https://embed.notionlytics.com/wt/ZXlKd1lXZGxTV1FpT2lJelkyRm1aR0l5Wm1GbE56TTBNbVl3WW1ReFpEa3pNRGhoWVdZNU9UTmtaaUlzSW5kdmNtdHpjR0ZqWlZSeVlXTnJaWEpKWkNJNklrbGpiM1pzV2pOcU1VUnBRM1ZUUm1WNFRtdHlJbjA9

Our task is to provide the data with the requested shape. To do it, we need to create a thing that will help us with collecting and organizing information within certain rules.

This thing is called a resolver.

How to retrieve data in GraphQL?

GraphQL provides two types of constructs for accessing data:

  1. Queries - ****used for extracting, processing, and presenting information in the requested form
  2. Mutations - ****used for adding, deleting, updating data

A developer must create and assign a resolver for each of these mechanisms.

What is a GraphQL resolver?

In Magento 2, the GraphQL query resolver is realized as a class that implements one of the special GraphQL interfaces and returns the result in the form of a callable function. In the most common case, GraphQL resolver is the PHP-class that implements ResolverInterface.

How the ResolverInterface works?

The ResolverInterface obliges us to implement the resolve() method. Its arguments are:

<aside> ➡️ The GraphQl engine maps data to the response type. All fields that did not match the requested schema will be omitted in the response but available in child resolvers. This allows, for example, to share the loaded product model from product resolver down to product field resolvers.

</aside>