Bird
0
0

What is wrong with this resolver that causes a runtime error?

medium📝 Debug Q7 of 15
GraphQL - Resolvers
What is wrong with this resolver that causes a runtime error?
const resolvers = {
  Query: {
    userId: (parent, args) => {
      return parent.id;
    }
  }
};
Assuming the root query has no parent object.
Aargs parameter is missing
BResolver should not use arrow functions
CResolver must return a promise
Dparent is undefined, so accessing parent.id causes error
Step-by-Step Solution
Solution:
  1. Step 1: Understand parent in root query

    At root query level, parent is usually undefined or null.
  2. Step 2: Identify error cause

    Accessing parent.id when parent is undefined causes runtime error.
  3. Final Answer:

    parent is undefined, so accessing parent.id causes error -> Option D
  4. Quick Check:

    Undefined parent causes error = B [OK]
Quick Trick: Root query parent is undefined; avoid accessing its properties [OK]
Common Mistakes:
  • Assuming parent always has data
  • Expecting args to fix error
  • Thinking arrow functions cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes