Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Const

field resolver

A field resolver is the server function that supplies a value for a GraphQL field. GraphQL calls resolvers from the root operation fields through nested selections until the requested leaf values are produced.

How it works

A field resolver is the server-side function associated with a schema field. GraphQL calls it during execution, starting from root operation fields and continuing through nested selections; the returned value is then completed according to the field's type. Resolvers can use the parent object, field arguments, shared context, and execution metadata.

Syntax

resolver(obj, args, context, info)

Parameters

NameTypeDescription
objunknownThe previous object; commonly unused for a field on the root Query type.
argsobjectArguments supplied to the field in the GraphQL operation.
contextunknownShared value available to every resolver, such as the authenticated user or a database handle.
infoGraphQLResolveInfoField-specific information about the current operation and schema; generally for advanced use cases.

Returns

A value for the field's declared type; object values are recursively completed through their selected subfields, while scalar values complete at the leaf.

Key points

  • A schema field is backed by server code that determines the data returned for that field.
  • GraphQL begins field execution at the root operation type selected by the operation.
  • GraphQL invokes the matching resolver to produce the field's next value.
  • Object results are expanded by resolving the nested fields requested by the client.
  • A resolver may return its result asynchronously, supporting data sources that require waiting.
  • The response map uses the requested field name, or its alias when one is present.

Common mistakes

  • A resolver can fail during execution, producing a field error and potentially only partial data in the response.

Example: Resolvers for two fields

const resolvers = {
  Query: {
    me: (_parent, _args, context, _info) => context.request.auth.user,
  },
  User: {
    name: (user, _args, context, _info) =>
      context.db.getUserFullName(user.id),
  },
};

Each resolver receives the parent value and can obtain data from request context or another data source.

When to use it

Resolve root fields

Fetch a root resource such as the current user from request authentication context.

Resolve nested fields

Use the parent object's identifier to retrieve a related property from a database or repository.

Use request context

Access authentication details, database handles, or other request-scoped services shared through context.

Resolve asynchronously

Return data from a remote or database-backed source that requires awaiting asynchronous work.

Interview questions

QWhat is a GraphQL field resolver?

A resolver is the function that supplies a field's value. GraphQL invokes it when executing that field, and nested object results lead to execution of their selected subfields.

Follow-up: What are the resolver arguments? The reference implementation passes the previous object, field arguments, shared context, and field-specific execution information.

QWhat does the parent argument contain?

The first argument is the previous object, often called the parent value. For a root Query field it is commonly unused; for a nested field it represents the object returned by the parent resolver.

Follow-up: How can a nested resolver fetch related data? It can use an identifier from the parent object and access a repository or database through context.

QCan resolvers be asynchronous?

Resolvers may execute asynchronously, so they can obtain data from remote services or databases before returning a value. GraphQL continues completing the result once the resolver's value is available.

Follow-up: What happens when the value is an object? GraphQL applies the requested selection set recursively until leaf scalar values are reached.

  • Execution
  • Query
  • Mutation
  • Subscription
  • context
  • GraphQLResolveInfo
  • field errors

Source: Execution. Checked 2026-10-15.