Bird
0
0

Given the GraphQL query:

medium📝 query result Q13 of 15
GraphQL - Resolvers
Given the GraphQL query:
{ user(id: 3) { name age } }

What will be the result if the user with id=3 has name "Alice" and age 30?
A{ "data": { "user": { "id": 3, "name": "Alice" } } }
B{ "data": { "user": { "name": "Alice", "age": 30 } } }
C{ "data": { "user": { "name": "Alice" } } }
D{ "error": "User not found" }
Step-by-Step Solution
Solution:
  1. Step 1: Understand the query fields

    The query requests the user with id 3 and asks for the fields name and age.
  2. Step 2: Match the expected output

    The response should include both name and age for user 3. { "data": { "user": { "name": "Alice", "age": 30 } } } matches this exactly. { "data": { "user": { "id": 3, "name": "Alice" } } } includes id which was not requested. { "data": { "user": { "name": "Alice" } } } misses age. { "error": "User not found" } is an error which is incorrect since user exists.
  3. Final Answer:

    { "data": { "user": { "name": "Alice", "age": 30 } } } -> Option B
  4. Quick Check:

    Requested fields = name, age; output matches [OK]
Quick Trick: Output matches requested fields exactly [OK]
Common Mistakes:
  • Expecting unrequested fields in output
  • Ignoring requested fields in output
  • Assuming error when user exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes