Life of Apps

Is GraphQL the SQL of the Web?


I was told by a friend that GraphQL was the next big thing, I wondered why and decided to take a look at it. GraphQL developed by Facebook, provides a SQL-like access to REST resources. Consider the following snippet:

{

    customer(id: "1140") {

    name

    type

   }

}

This will provide the name and type of the customer with id 1140. In a traditional REST based setup, one would have to make two calls, to get the name and the type of the customer. Or would get a full customer object and then parse it to extract the fields. In GraphQL, we can specify the fields needed in the query and get it in one call. This would reduce the number of requests and consequently the load on the server.

GraphQL features Fragments where two queries are executed to get details, such as for comparison, has its own schema with data types, Unions, abstract types and more.

Sounds good. How do we get started? 

There are a few libraries available that help handle the server side conversation. Relay from Facebook and React Apollo are some of the popular ones. For more, check out the GraphQL site.

While it may seem like too much of work changing the server side to start using GraphQL, it would definitely make sense to do so where the number of calls are high and of a relational nature. The GraphQL spec is currently a working draft but a few early adopters have already started using it in production. Enterprise adoption might take a while to do so. But once they do, it will most likely become the SQL of the web.

Danesh

Visit Pleb.in for apps developed by Danesh

No comments :

Post a Comment

Leave a Comment...