BLEST

Comparing, Contrasting, and Combining BLEST and GraphQL

When first presented with BLEST, many developers' initial reaction is to ask, "Why not just use GraphQL?" This is an excellent question because BLEST and GraphQL share several important features. However, BLEST and GraphQL are also very different and were designed for different purposes. Specifically, GraphQL was designed as a querying language for graph-like services, while BLEST was designed to be an all-purpose API protocol to replace REST.

Similarities

The two most similar features between BLEST and GraphQL are selective returns and single endpoint. Limiting the data returned from the server can be helpful in conserving bandwidth, which is of particular value when serving clients over slower connections. Receiving requests on a single endpoint improves security by hiding sensitive data or traffic patterns and makes server discovery and exploration much simpler than a traditional REST architecture. Despite their differences, both GraphQL and BLEST offer these features to developers.

Differences

The differences are a bit more substantial. GraphQL uses its own text-based language called GraphQL whereas BLEST uses standard JSON (JavaScript Object Notation). GraphQL divides requests into queries and mutations while BLEST does not concern itself with these distinctions. GraphQL requires a detailed schema with input and output type definitions which can be cumbersome. BLEST leaves validation entirely up to the developer. Finally, while both allow batching, a batched GraphQL request fails if one of the batched queries or mutations throws an error, but BLEST returns the result or error for all batched requests even if every single one of them throws an error.

Combination

There may be instances where, as with a RESTful API, the developer wishes to serve GraphQL from a specific endpoint while serving other types of requests from others. This is also possible with BLEST using a similar JSON payload as that used by the Apollo library. The following code illustrates a BLEST batched request containing a GraphQL query and mutation from the GraphQL documentation. Each request contains a unique request ID, the "graphql" route, the GraphQL statement, and the variables. GraphQL handles the return selection, so the selector is omitted. Each response contains the ID and route of its request along with either the data or error returned from GraphQL.

Request

BLEST GraphQL Request

Response

BLEST GraphQL Response

Conclusion

GraphQL is an innovative solution for querying graph-like systems, but it is not an all-purpose solution nor is it a replacement for REST (and it was not designed to be). BLEST offers selective returns and a single endpoint like GraphQL, but it is simpler, less opinionated, and flexible enough to support a wide variety of use cases (including serving GraphQL).

Next Step: Try BLEST for yourself