Bird
0
0

In this schema:

medium📝 Debug Q7 of 15
GraphQL - Type Relationships
In this schema:
type Order { id: ID customer: Customer } type Customer { id: ID name: String }

Which query will cause a runtime error if the resolver for 'customer' returns null?
A{ order(id: "5") { id customer { name } } }
B{ order(id: "5") { id customer } }
C{ order(id: "5") { id } }
D{ order(id: "5") { customer } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand nullability in GraphQL

    In GraphQL, if a nullable object field like 'customer' resolves to null, but the query requests subfields on that field, it results in a runtime error because null cannot have fields.
  2. Step 2: Check which queries request subfields of 'customer'

    The query { order(id: "5") { id customer { name } } } requests subfields on customer, causing the error if null. Others either don't query customer or query it without subfields.
  3. Final Answer:

    { order(id: "5") { id customer { name } } } -> Option A
  4. Quick Check:

    Requesting subfields on null object causes errors = A [OK]
Quick Trick: Requesting subfields on null causes errors unless nullable [OK]
Common Mistakes:
  • Assuming null object fields never cause errors
  • Ignoring nullability in schema definitions
  • Thinking all queries handle null automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes