Resolver Function Arguments

A resolver function commonly receives four conceptual arguments:

(parent, args, context, info)

The exact function signature can vary by GraphQL server implementation, but these four concepts are fundamental.

Parent

parent contains the value returned by the resolver of the parent field.

Args

args contains arguments supplied to the field.

For:

user(id: "42")

args might be:

{ id: "42" }

Context

context contains request-scoped information shared by resolvers. It is commonly used for authentication information, database clients, loaders, request IDs, or other request-level dependencies.

Info

info contains execution metadata, including information about the current field and GraphQL operation. Advanced tooling and optimization systems can use it.

Example:

const resolvers = {
  Query: {
    user: async (parent, args, context, info) => {
      return context.userService.findById(args.id);
    }
  }
};

Understanding these arguments is essential because they provide the bridge between the GraphQL execution engine and your application.

Resolver Arguments
parent: Value returned by the parent resolver
Useful for resolving nested fields.
args: Arguments supplied to the field
Contains field-specific client inputs.
context: Request-scoped application context
Commonly contains authentication and shared services.
info: GraphQL execution metadata
Contains details about the current execution and field.
Key Takeaways
  • Resolvers commonly receive parent, args, context, and info.
  • Args contain field arguments.
  • Context is useful for request-scoped dependencies.
  • Parent is especially important for nested object resolution.
Knowledge Check

Where would you normally find the value supplied to a field argument such as `user(id: "42")`?