# Resolvers
# Resolver function signature
Resolvers are always called with the same 4 arguments:
use Nuwave\Lighthouse\Execution\ResolveInfo;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
function (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
mixed $root
: The result that was returned from the parent field. When resolving a field that sits on one of the root types (Query
,Mutation
) this isnull
.array $args
: The arguments that were passed into the field. For example, for a field call likeuser(name: "Bob")
it would be['name' => 'Bob']
GraphQLContext $context
: Arbitrary data that is shared between all fields of a single query. Lighthouse passes in an instance ofNuwave\Lighthouse\Schema\Context
by default.ResolveInfo $resolveInfo
: Information about the query itself, such as the execution state, the field name, path to the field from the root, and more.
The return value of this must fit the return type defined for the corresponding field from the schema.
# Complexity function signature
The complexity function is used to calculate a query complexity score for a field. You can define your own complexity function with the @complexity directive.
function (int $childrenComplexity, array $args): int
$childrenComplexity
: The complexity of the children of the field. In case you expect to return multiple children, it can be useful to do some maths on this.array $args
: The arguments that were passed into the field. For example, for a field call likeuser(name: "Bob")
it would be['name' => 'Bob']
Read more about query complexity in the webonyx/graphql-php docs (opens new window)
← Directives Scalars →