01 / 02

What are resolvers?

Difficulty: 6/10
resolver functions, data fetching, error handling

In GraphQL, resolvers are functions that handle the logic for retrieving or manipulating data based on the queries, mutations, or subscriptions defined in your GraphQL schema. Resolvers act as the connection between your GraphQL API and the underlying data sources, such as databases, REST APIs, or other services.

What do they do:
  1. 1

    They retrieve data requested in queries.

  2. 2

    They implement mutations to create, update, or delete data.

  3. 3

    They control how data is processed or formatted before being sent to the client.

Example of a resolver:
Types of resolvers:
  1. 1

    Query Resolvers: Handle fetching data (e.g.,getUser , listPosts ).

  2. 2

    Mutation Resolvers: Handle modifying data (e.g., createUser, updatePost).

  3. 3

    Field Resolvers: Resolve specific fields, particularly if they require custom logic (e.g., nested fields like post.author)

Scenario Questions

0-2 years experience

  1. 1We have a simple GraphQL schema with a `User` type that has `id` and `name`. How would you write a resolver to fetch a user by ID from an in‑memory array?
  2. 2If you omit a resolver for a scalar field like `name`, what does GraphQL do when that field is requested?
  3. 3When a query asks for `user { id name }` and your resolver for `user` returns `null`, what will the response look like?

2-5 years experience

  1. 1Our product team added a new field `profilePicture` to the `User` type, but the field always returns `null` in the response. Walk me through how you'd debug the resolver chain.
  2. 2We need to batch database calls for a list of posts and their authors. How would you modify resolvers to avoid N+1 queries, and what trade‑offs does that introduce?
  3. 3Suppose a resolver throws an error after partially populating the response. How does GraphQL handle error propagation, and how would you customize the error format for the client?

5-8 years experience

  1. 1Our service is scaling to millions of requests per second, and each resolver performs a remote HTTP call. What architectural changes would you consider to keep latency low and avoid cascading failures?
  2. 2We have a monolithic GraphQL server with many resolvers tightly coupled to business logic. How would you refactor the resolver layer to improve testability and allow independent deployment of downstream services?
  3. 3Explain how you would implement caching at the resolver level for frequently accessed fields while ensuring cache invalidation when underlying data changes.

8+ years experience

  1. 1Our organization is migrating from a legacy REST API to GraphQL. How would you design a resolver strategy that allows incremental migration, minimizes duplication, and supports multiple teams owning different parts of the schema?
  2. 2We need to enforce consistent authorization across all resolvers without sprinkling checks in each function. What pattern would you adopt at the architecture level, and how would you ensure it scales across microservices?
  3. 3Discuss the long‑term maintenance implications of using schema‑stitching versus a federated gateway for resolver composition in a large, multi‑team environment.

Follow-up Questions

  • Can you give an example of when you'd rely on the default resolver?
  • How would you expose the same resolver logic to both GraphQL and a REST endpoint?
  • What monitoring would you add around resolver execution?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.