GraphQL: Resolver

Resolver function in a GraphQL schema accepts four positional arguments:

fieldName:(root, args, context, info) => { result }
ArgumentsDescription
rootThe object that contains the result returned from the resolver on the parent field.
argsAn object with the arguments passed into the field in the query.
contextThis is an object shared by all resolvers in a particular query.
infoIt contains information about the execution state of the query, including the field name, the path to the field from the root.

Resolvers in GraphQL can return different types of values:

ArgumentsDescription
null or undefinedIndicates the object could not be found
arrayOnly valid if the schema indicates that the result of a field should be a list
promiseResolvers often do asynchronous actions like fetching from a database or backend API, so they can return promises
scalar or objectA resolver can also return other values

Leave a Reply

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