Emre Sokullu

Blog

12 July 2017

GraphQL, the future of APIs


Facebook may not be the favorite company of the open web community, for some good reasons. But when it comes to open source, most developers take advantage of their tools, libraries, and frameworks in one way or another. In particular, Javascript (Node.js) and PHP have advanced by leaps and bounds largely thanks to Facebook’s contributions. Although, one such technology that’s often overlooked is GraphQL, which, for many, has real potential to replace the infrastructure of the connected web, the REST APIs.

Drawbacks of REST APIs

REST is good, that is until it becomes a hairball.

For simple, single-purpose APIs like Flickr’s, it does the job, but as the Facebook’s Graph API documentation shows, its flat structure becomes unmanageable with multi-function, multivariate systems.

[caption id=”attachment_497" align=”aligncenter” width=”703"]

Even this formatted view of REST APIs is overwhelmingly complex.[/caption]

Nevertheless, REST’s design with primitive pagination and no support for slicing make it a no-go for complex queries. For example, this GraphQL example below:

where we query movie heroes with their name and the names of the first of two of their friends would take multiple REST API calls to accomplish. More queries only add up to the unreadability of REST’s already ugly syntax.

JSON to the rescue

When JSON first came out, in Steve Jobs’ saying, it was a glass of ice water to all the developers out there in the inter-connected web services hell with SOAP and co.

GraphQL is heavily inspired by JSON’s success, as it uses a similar simple format to define the APIs. Moreover, for the very first time, it encompasses:

in a single format, which makes it uniquely singular to define and use web services.

GraphQL is still work-in-progress for the most part, but it is a good start. The website claims it has already been explored or used by Yelp, Intuit, Pinterest and Coursera. However, its success will only depend on the indie developers who can up the ante with new tools, implementations, and specs around current drafts.

tags: