Course contentsShow
← Software Engineering
Lesson 811 of 1,93325. RPC and GraphQL API DesignFree lesson

Resolvers: The Execution Layer

Understanding how resolvers fetch data for each field and connect the schema to backend data sources.

Resolvers: The Execution Layer

What You'll Learn

You'll learn how resolvers act as the bridge between your GraphQL schema and your actual data sources, executing the logic that fetches the data for each field in a query.

The Core Idea

When a GraphQL query arrives, the schema defines what can be requested, but resolvers define how to actually get that data. Think of resolvers as the workforce behind the scenes: when someone orders from a restaurant menu (the schema), the kitchen staff (resolvers) actually prepare each dish.

Every field in your GraphQL schema can have a resolver function. When GraphQL executes a query, it calls the appropriate resolver for each field that was requested. These resolvers fetch data from databases, call other APIs, read files, or perform calculations—whatever is needed to fulfill that field's value.

How Resolvers Work

Each resolver function typically receives several arguments:

  • Parent/root: the result from the parent field
  • Arguments: any arguments passed to this specific field
  • Context: shared information (like database connections or authentication)
  • Info: metadata about the query itself

For example, if your query requests a user's name and email, the User resolver fetches the user object, then the name and email field resolvers extract those specific properties (or the default resolver does this automatically for simple fields).

Resolvers connect your elegant GraphQL schema to messy real-world data sources. One field might query PostgreSQL, another might call a REST API, and a third might read from Redis—all orchestrated seamlessly by their respective resolvers.

Resolver Execution Flow

GraphQL executes resolvers in a specific order: parent fields resolve first, then their children can access those results. This creates a cascading execution that matches your query's shape.

Key Takeaway: Resolvers are the execution layer that connects your GraphQL schema's abstract type definitions to concrete data sources, with each field's resolver responsible for fetching or computing that field's actual value.