Polski
Français
Deutsch
日本
Español
Nederlands
Dansk
GraphQL is a way of communicating with APIs created as an alternative to REST.
GraphQL is a query language for APIs that was developed by Facebook and their dev community. It premiered in June 2018, and is now a mature technology that has gained widespread market recognition. As a result, it is well recognized and many companies are choosing to implement it. In order to tell you how it is different, we have to look at what is still most widely used: REST and what it is based on. GraphQL is often called the successor to REST because it solves its key problems. As you probably know, it is based on a kind of old system design. According to it, each data model is available at a separate address. Having an online shop with clothes, for example we can have addresses for cart, warehouse, products and many more.
In fact, the number of such addresses will never be small, on the contrary, it will grow with the system. Keep in mind that for almost every address you need to create a set of calls to handle get, post, put or delete requests. This will result in a large number of addresses to maintain and an even larger amount of calls needed to get the data. GraphQL works in a completely different way. We have only one address, a single source of truth, from which we can request data. What we get depends solely on us and how we construct the query.
The key feature of GraphQL is the ability to perform flexible queries within which we define exactly what data from the API we want to get. In addition, the language provides the possibility of creating nested queries, which makes it gain even more of an advantage over REST APIs in these areas.
One point of similarity between REST and GraphQL is platform or programming language independence. Another common feature is the idempotency of the same operations. For both REST architecture and GraphQL, operations such as retrieve, modify or delete can be used repeatedly without changing the result.
The basic elements of GraphQL are: mutation:
GraphQL uses its own syntax: SDL or Schema Definition Language. It is used to specify the schema of an API and its types and fields. Types are declared using the type keyword and fields are added in brackets for each object type.
While GraphQL is still not as popular as REST, its community is rapidly growing. It has already had a number of major adopters such as GitHub, Netflix, PayPal or Shopify. It’s only a matter of time before more will follow.