Bird
0
0

Given this schema snippet:

medium📝 query result Q13 of 15
GraphQL - Schema Definition Language (SDL)
Given this schema snippet:
type Query { user(id: Int): User }

What will happen if a client queries for { user(id: 1) { id name } } but the schema does not define the name field on User?
AThe query will return an error about the unknown field 'name'
BThe query will return the user with an empty 'name' field
CThe query will ignore the 'name' field and return only 'id'
DThe query will return null for the entire user
Step-by-Step Solution
Solution:
  1. Step 1: Understand schema validation

    GraphQL validates queries against the schema. If a field is not defined, it causes an error.
  2. Step 2: Apply to the given query

    The 'name' field is missing in the User type, so the query asking for it will fail with an error.
  3. Final Answer:

    The query will return an error about the unknown field 'name' -> Option A
  4. Quick Check:

    Query fields must exist in schema [OK]
Quick Trick: Query fields must match schema exactly [OK]
Common Mistakes:
  • Assuming missing fields return empty or null silently
  • Thinking GraphQL ignores unknown fields
  • Believing partial data is returned without error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes