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.
Value returned by the parent resolverArguments supplied to the fieldRequest-scoped application contextGraphQL execution metadata- 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.
Where would you normally find the value supplied to a field argument such as `user(id: "42")`?