All about GraphQl:

Everything about GraphQL:

The Graph QL library is a library that can eliminate reset-controllers alongside various API, leaving only one reference AIP with the address: http://[server-url]:[port]/graphql in the server code side. Note that all requests are made by the Request Body and with POST methods are sent to the remaining address, and according to the Body which have been sent, different methods are called. As a result, there is no need to define different models of Response in the code which have been sent.

There are generally two types of data transmission in the Body:

1.Query: this information transmission includes requests that the user sends to the server to receive various information. (Similar to GET methods)

2- Mutation: it includes requests that the user sends to create, delete, and edit their information. (Similar to the POST, PUT, DELETE)

Note that for each domain, instead of a reset-controller, there are actually two different classes for managing Query, and Mutation. In fact, to better understand these cases, if we want to conform to the MVC model, the order of the layers is as follows: 

  1. Repository
  2. Service
  3. Query/Mutation

Since different methods are defined in Query and Mutation classes, we need to introduce these methods to the graph.  According to the following code, we start to define different types of Domain, different types of request models, different types of Query methods, and different types of Mutation methods. Different fields, their kind and the arguments which are required for each method, are fully listed in this file. We also have to say that the «!» symbol in front of every field shows that, so-called field is NutNull. After doing this the project can be used and different methods can be used based on presented fields.

In the following, we have an example of how to send the request:

  • This Query request is only for receiving the user by its ID and displaying its ID name and roles:

graphOL

  • Response:

graphql

  • To send a Mutation request is to create a user and determine their role, but only display the user’s name and ID after creation in response:

graphql

  • Response:

graphql

To check out the Graphql sample project, you can connect to my GitHub via the link.

 

More Articles

Leave A Comment

− 1 = 2

Please Send Email

Your message sent successfully
There has been an error