JesusValera

A brief introduction to GraphQL

 Found a typo? Edit me

atomium-graphql

A RESTful API is a de-facto standard to allow communication between applications, although, recently GraphQL comes up.

From the user-client perspective, GraphQL is similar to RESTful, they work as an entry point between different applications, but GraphQL is slightly different, and because of this, this technology has a reason to be.

GraphQL vs RESTful API

GraphQL and RESTful have the same foundation. They use the HTTP methods, and they have the idea of resource, but, in REST, each endpoint is a single resource, while in GraphQL there is only a single resource.
GraphQL is not about resource state management, but about separating read operations (queries) from write operations (mutations). This is known as the Command Query Separation pattern.
In REST, the server determines the shape and size of a resource, in GraphQL depends on the user's needs.

How to manage a GraphQL schema?

A schema contains objects, every object has different parameters, and those parameters can be properties or even sub-objects.

Usually, if you want to filter an object(s) from a specific Type, you can apply a filter into brackets, the output is always a JSON response.

Queries

The queries are the GET requests. That means you can only fetch data.

graphql-query

Mutations

The mutations are the POST, PUT, PATCH, and DELETE HTTP methods. That means you can mutate the data model, and persist it in the database by creating, updating or removing elements.

graphql-mutation

In a mutation, the addOffer() is the instruction you will perform into the system, though the body of the mutation is the response you want to receive.

I hope you will be able to write from now on queries and mutations for your GraphQL API, in order to do that first you should understand the DB architecture and relations between elements, but that is the basic idea. In the end, it is very similar to how Restful works, but with another syntax.

graphql-logo

I recommend you to take a look at the GraphQL documentation for more information, not only from a black-box side perspective but also as a white box and learn more about other elements like enums, interfaces.
How to create and manage new entities, even building up new architectures.