Press "Enter" to skip to content

GraphQL – a Way of Communication Between a Service and a Client

Sphere

The demand for decentralization is breaking all records today. DeFi is especially active here. And the development of decentralization, which is based on blockchain technology, has led to the need to have a kind of link between application data and blockchain. As a result of this, there was a demand to create and implement a platform on the basis of which developers can form their requests quickly and efficiently, receive and store the necessary data securely. And such a platform appeared in the form of the Graph project. And the GraphQL syntax firmly connected the data catena “blockchain – application”. Now supporters of blockchain projects can take advantage of services with GraphQL, in particular, graphql blockchain and easily request and receive all the necessary data in a format convenient for them.

The emergence of GrafQl

Speaking about the architecture of the Graph platform, it is necessary to say about its new query language – GraphQL. Recently, this query language has become very popular among frontend developers. Its history goes back to 2012, when Facebook first introduced this new query language. Prior to this, the standard “request – response” chain was carried out by the REST API. And it was realizing in the following way. For each entity, there was a separate endpoint, and to answer the request, this endpoint turned to some kind of data store. The problem was that with serious projects there could be more than one such storages and there could also be very, very many entities. And when a large number of components of a process appear, the risk of all kinds of errors increases many times over. In addition to errors, a serious load fell on the company’s servers.

Being essentially a graph data system, Facebook developed GraphQL for its internal use, as a query language for communicating between the server and the client, and also as an environment for making these queries. And as a result, since 2015, GraphQL has ceased to be an internal tool of Facebook and has become widely used by various other companies.

Comparing GrafQl and REST API, it should be noted that these are, in fact, two tools that solve the same problem, but they use different approaches. The REST API is more static, like a set of requests, and doesn’t change as often. In fact, it is a set of endpoints for specific goals and for specific requests from clients. For example, requesting a list of users or requesting one user by his ID, updating a user, etc. – all these are endpoints and there can be many of them. GrafQl, on the other hand, allows you to design a single query for specific needs. The query is very flexible and allows you to include a large amount of data. And in cases where the REST API requires several requests, GrafQl can customize the data.

Features of GrafQl

So, Facebook proposed to create one endpoint, which will internally transfer one request for obtaining the necessary data to various sources of this data. And in order not to get confused in such a large amount of data, it was necessary to make this entity strongly typed. In other words, another “programming language” was emerging, which is declarative and, fortunately, quite simple. In addition, four basic components of GrafQl itself have been formed. This:

– schema as a description of the data type,

– request for data,

– mutation or request for data changes,

– subscription or request for regular data updates.

What is the main feature of this syntax? When using it, there is not just a description of the fact that the user has such types or the user has such entities. In fact, a hierarchy of entity relationships is built. In essence, we get a hierarchy that describes our business model and our data model.

GrafQl is declared as a  transport agnostic . Since there is one endpoint, the user, in principle, does not care how to access it, the user only needs a mechanism for sending a request and a mechanism for receiving a response.

It is important to note that GrafQl is available for many languages and its dedicated page shows you which languages are supported by this tool. It is important to note three main characteristics of GrafQl: the first – is that the client himself specifies what data he needs, the second – is that GrafQl facilitates data aggregation, and the third – is that GrafQl has a type system for describing data.

It must be remembered that GrafQl is not about the database itself and is not about how to work with databases. GrafQl is about API approach. Another feature of GrafQl is that it only returns the fields that have been requested. And all this happens in one http request, without the need to make any other multiple requests.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *