Bird
0
0

Given the resolver:

medium📝 Debug Q6 of 15
GraphQL - Resolvers
Given the resolver:
function getPost(root, args) { return posts.find(p => p.id == args.postId); }

and the query:
{ getPost(postId: 3) { title } }

Which of the following is a likely cause if the resolver returns undefined?
AThe posts array is empty
BThe argument name in the query does not match the resolver's expected argument
CThe resolver function is missing the root parameter
DThe query syntax is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check argument name matching

    The query uses postId which matches the resolver's args.postId.
  2. Step 2: Consider data availability

    If posts array is empty, find returns undefined because no post exists.
  3. Final Answer:

    The posts array is empty -> Option A
  4. Quick Check:

    No data means find returns undefined [OK]
Quick Trick: Empty data arrays cause find() to return undefined [OK]
Common Mistakes:
  • Assuming argument name mismatch
  • Thinking missing root causes undefined
  • Assuming query syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes