Bird
0
0

If a User has no Profile linked, what will this query return?

medium📝 query result Q5 of 15
GraphQL - Type Relationships
If a User has no Profile linked, what will this query return?
{ user(id: "2") { name profile { bio } } }
AError: Cannot query profile of null
B{ "data": { "user": { "name": "Bob", "profile": { "bio": "" } } } }
C{ "data": { "user": { "name": "Bob", "profile": null } } }
D{ "data": { "user": null } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand nullable fields in schema

    Profile field can be null if no linked profile exists.
  2. Step 2: Predict query output when profile missing

    Query returns user data with profile as null, no error.
  3. Final Answer:

    { "data": { "user": { "name": "Bob", "profile": null } } } -> Option C
  4. Quick Check:

    Missing one-to-one linked data returns null field [OK]
Quick Trick: Missing linked object returns null, not error [OK]
Common Mistakes:
  • Expecting empty object instead of null
  • Assuming error on null nested field
  • Confusing null user with null profile

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes