Search⌘ K
AI Features

Root Fields and Resolvers

Explore how GraphQL queries are executed starting from root fields using resolver functions. Learn how resolvers handle arguments and context to return scalar or object data, and how query resolution continues recursively until scalar values are produced.

In this lesson, we’ll learn how a GraphQL query is executed by a GraphQL server that returns a response that reflects the structure of the invoked GraphQL query.

The sample query below is the same as the type system used throughout the lesson.

Javascript (babel-node)
type Pizza {
id: Int!
pizza: String!
stock: Int!
toppings: [Topping!]!
}
type Topping {
id: Int!
topping: String!
}
type Query {
pizzas: [Pizza]
}

Let’s use one of our previous queries as an example.

Javascript (babel-node)
query{
pizzas {
__typename
... on Pizza {
id
toppings {
id
topping
}
pizza
}
}
}

We can conceptualize each field in a GraphQL query as a function. Each field is mapped to a resolver ...