Bird
0
0

How should you use the parent argument in the author resolver inside Book to get the correct author name?

hard📝 Application Q15 of 15
GraphQL - Resolvers
You want to fetch a list of books with their authors' names using nested resolvers. The Book type has an authorId field, and the Author type has id and name. How should you use the parent argument in the author resolver inside Book to get the correct author name?
AUse <code>parent.authorId</code> to find the author by matching <code>id</code>.
BUse <code>args.authorId</code> to find the author by matching <code>id</code>.
CUse <code>context.authorId</code> to find the author by matching <code>id</code>.
DUse <code>info.authorId</code> to find the author by matching <code>id</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested resolver data flow

    The author resolver inside Book receives the book object as parent.
  2. Step 2: Access authorId from parent to find author

    Use parent.authorId to look up the author by matching id in authors data.
  3. Final Answer:

    Use parent.authorId to find the author by matching id. -> Option A
  4. Quick Check:

    Parent holds book data, use parent.authorId [OK]
Quick Trick: Parent holds book; use parent.authorId for author lookup [OK]
Common Mistakes:
  • Using args instead of parent for authorId
  • Trying to get authorId from context or info
  • Ignoring parent argument in nested resolver

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes