⬡ GraphQL Beginner

What is the root value in GraphQL?

Answer

The root value (sometimes called rootValue) is an optional object passed to the GraphQL executor that serves as the parent object for top-level resolver functions. In the reference GraphQL.js implementation, it's the value passed as the second argument to graphql(schema, query, rootValue). For Query resolvers, parent (first resolver argument) is the root value. In practice, most modern GraphQL frameworks (Apollo Server, Yoga) do not rely on root value — instead, they use the context for shared data and define resolvers on the Query/Mutation types directly. The root value pattern is more common in simple setups or the reference implementation. For production apps, the context pattern is preferred as it's more flexible and explicit.