Bird
0
0

Consider this GraphQL schema snippet:

medium📝 Debug Q14 of 15
GraphQL - Schema Definition Language (SDL)
Consider this GraphQL schema snippet:
type Product {
  id: ID!
  name: String!
  description: String
}

Which change fixes the error when a query returns null for name?
AAdd <code>!</code> to <code>description</code> field
BRemove <code>!</code> from <code>name</code> field
CChange <code>id</code> type to <code>ID</code> without <code>!</code>
DRename <code>name</code> field to <code>title</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand the error cause

    The error occurs because name is required (String!) but the query returns null, violating the non-null rule.
  2. Step 2: Fix by making name optional

    Removing ! from name allows it to be null, fixing the error.
  3. Final Answer:

    Remove ! from name field -> Option B
  4. Quick Check:

    Null returned for required field? Remove ! [OK]
Quick Trick: If null causes error, remove ! to allow optional [OK]
Common Mistakes:
  • Adding ! to optional fields instead of removing
  • Changing unrelated fields
  • Renaming fields without fixing null issue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes