Bird
0
0

A developer writes this resolver:

medium📝 Debug Q7 of 15
GraphQL - Resolvers
A developer writes this resolver:
function getItem(root, args) { return items.filter(i => i.category === args.category); }

But the query:
{ getItem(category: "books") { name } }

returns an error. What is the most likely cause?
AThe resolver returns an array but the schema expects a single object
BThe argument name is misspelled in the query
CThe filter function is used incorrectly
DThe query is missing required arguments
Step-by-Step Solution
Solution:
  1. Step 1: Understand resolver return type

    The resolver returns an array from filter.
  2. Step 2: Check schema expectation

    If the schema expects a single object but resolver returns array, GraphQL throws an error.
  3. Final Answer:

    The resolver returns an array but the schema expects a single object -> Option A
  4. Quick Check:

    Return type must match schema type [OK]
Quick Trick: Return type must match schema: array vs object [OK]
Common Mistakes:
  • Assuming argument name typo
  • Thinking filter is wrong usage
  • Assuming missing arguments cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes