Skip to content

Resolver

Medium — good to knowBackend

ELI5 — The Vibe Check

A resolver is a function that fetches the data for a single field in a GraphQL query. When you ask for user.posts, there's a resolver that knows how to get those posts. Each field in your schema maps to a resolver. They're the workers that actually get the data.

Real Talk

In GraphQL, a resolver is a function that returns the data for a specific field in a schema. Resolvers receive four arguments: parent (result of the parent resolver), args (field arguments), context (shared across resolvers, holds auth/DB), and info (query metadata). They can return values, promises, or throw errors.

Show Me The Code

const resolvers = {
  Query: {
    user: (_, { id }, { db }) => db.users.findById(id),
  },
  User: {
    posts: (parent, _, { db }) => db.posts.findByUserId(parent.id),
  }
};

When You'll Hear This

"Each GraphQL field has a resolver that knows how to fetch its data." / "The user.posts resolver is causing an N+1 query — use a DataLoader."

Made with passive-aggressive love by manoga.digital. Powered by Claude.