Q6: What is a GraphQL Resolver?

Difficulty:EasyTopic:Execution

A resolver is a function that populates the data for a specific field in a GraphQL schema. Every field on every type in GraphQL is backed by a resolver function on the server.

Basic JavaScript Resolver
const resolvers = {
  Query: {
    user: (parent, args, context, info) => {
      return context.db.findUserById(args.id);
    }
  }
};

Resolvers receive four positional arguments: parent, args, context, and info.

Key Takeaways
  • Resolvers bridge schema fields to actual data sources (DBs, REST APIs, microservices).

Knowledge Check

What role does a resolver fulfill in a GraphQL server?