⬡ GraphQL
Intermediate
How do field resolvers work with the parent object in GraphQL?
Answer
In GraphQL, each field has a resolver. The parent (also called root or source) argument is the resolved value of the parent type. For example, if a User type has a posts field, the posts resolver receives the resolved User object as its parent: posts: (user, args, ctx) => ctx.db.posts.findByUserId(user.id). For top-level Query fields, the parent is the root value (usually null or an empty object). If no custom resolver is provided, GraphQL's default resolver reads the same-named property from the parent object — so name: (user) => user.name is equivalent to having no resolver at all, enabling concise schema implementations.
More GraphQL Questions
View all →- Intermediate What is the N+1 problem in GraphQL and how does DataLoader solve it?
- Intermediate What are persisted queries in GraphQL?
- Intermediate What is the difference between schema-first and code-first GraphQL approaches?
- Intermediate What are the pagination strategies in GraphQL?
- Intermediate How is authentication handled in GraphQL?