What is the Context object in GraphQL resolvers?

Updated Apr 28, 2026

Short answer

The Context is an object shared across all resolvers for a specific execution of a GraphQL operation.

Deep explanation

It is constructed once per request (typically in the server middleware) and passed to every resolver. It is the perfect place to store per-request state, such as the authenticated user, database connections, and DataLoaders.

Real-world example

A resolver checking context.user.role to determine if the user has permission to view a sensitive salary field.

Common mistakes

  • Storing global, cross-request state inside the Context, or putting heavy computation directly in the context initialization instead of lazily evaluating it.

Follow-up questions

  • Why use Context for database connections?

More GraphQL interview questions

View all →