What is GraphQL ?

Pragmatic Reviews
3 min readApr 1, 2020

--

GraphQL 101

GraphQL is an open-source query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.
It was developed by Facebook and released in 2015.
GraphQL allows you to ask for specific data, giving clients more control over what information is sent.

GraphQL vs REST APIs

In GraphQL you ask for what you need and you are going to get exactly that, while in REST there is an all-or-nothing approach.

In GraphQL the server declares what resources are available, and the client asks for what it needs, while in REST, the shape and the size of the resource is determined by the server.

In GraphQL we are able to get multiple resources in a single request using a query. With REST we need to make multiple requests to fetch data from multiple resources.

In GraphQL the actions are defined by a Mutation or a Query. In REST APIs the actions are defined by the URL and HTTP Method.

In GraphQL you only have one endpoint while in REST you have multiple endpoints.

And this last difference is important regarding caching. In REST you can leverage the http specification for caching using urls as the unique identifier of a resource (that is going to become the entry key for the cache).

GraphQL and REST APIs

GraphQL and REST APIs work with HTTP and have the idea of a resource to describe data structures.
Both can fetch data via an HTTP GET request with a URL.
Both can return JSON data in the response.

GraphQL Architecture

GraphQL Architecture

A GraphQL Client will be able to send HTTP requests including queries, mutations or subscriptions and the GraphQL Server is going to process those requests using a resolver. The resolver will get the data from a database or a REST API for example.
The GraphQL server is going to return a result back to the GraphQL client, typically using a JSON format.

GraphQL Schemas

A GraphQL service defines a set of types (or Schema) which completely describes the set of possible data you can query on that service.
The Schema includes Data Types, Queries, Mutations and Subscriptions for Push notifications and is written by using the GraphQL schema language.

GraphQL Queries

A Query is used to read or fetch values. GraphQL Queries run in parallel.

GraphQL Mutations

A Mutation can be used to insert, update, or delete data and returns a value.
Mutations run in series, this means that if we send two mutations in one request, the first is guaranteed to finish before the second begins.

--

--

Pragmatic Reviews

Online training on multiple technology topics such as Programming, Cloud Computing, Testing Automation, SEO and more.