Resolver

Resolver is the component in charge of mapping a source to an object. In other words, it allows you to map the data from the source to object fields.

You can access to the resolver of a source or an object by clicking on the Linked elements tab. Then you’ll see a resolvers list that uses this object/source.

resolver


Matchers and matches

This component transforms the data from a source to an object. You can define which source field corresponds to which object field by filling in the Source node/field and Object node/field fields.

When you map data, you can transform its structure. In the example above, we map the field address.city to object fields address and address.city and we’ve renamed the source field zipcode to the object field’s zip_code.

resolver_matchers_exemple

for a json response, such as the one found above:

{
  “address”: {
    “city”: “Montreal”
    “geo”: {
      “lat”: ...
      “lng”: ...
    }
  }
}
  • address

    • city
  • geolocation

    • latitude
    • longitude

you would have to use the following syntax to create the mapping:

from: to:
address address
address.city address.city
address.geo geolocation
address.geo.lat geolocation.latitude
address.geo.lng geolocation.longitude

Note that we separate nodes with a . to express the object hierarchy.

Before mapping a node to another node, in our case address to address and their subfields, you must map address from source’s address to object’s address first then their subfields.


Arguments

When you use a resolver, sometimes you will need to pass in arguments, such as the user’s id that you want to request or the bearer token required to obtain the data. You can accomplish that thanks to resolver arguments.

resolver_user

An argument is a parameter that will be mapped to a source’s variable. You can create an argument that you want by clicking on “add” in the resolver view.

Each argument is defined by a name, a kind, and a source’s variable name. As you can see in the image above, there is an argument call id of type integer that is matched to a variable call id.

arg_name

If the argument kind is followed by an exclamation mark like in integer! , it means that the argument cannot be null. So when we use the resolver, the user id parameter must be specified, like in the request below :

graphiql

If we don’t provide a valid argument, we’ll have the following error:

graphiql_error