Bird
0
0

How can you represent a one-to-many relationship in GraphQL when the 'many' side can be empty (no related items)?

hard📝 Application Q9 of 15
GraphQL - Type Relationships
How can you represent a one-to-many relationship in GraphQL when the 'many' side can be empty (no related items)?
AUse a non-null single item type: Item!
BUse a non-null list with nullable items: [Item]!
CUse a nullable single item type: Item
DUse a list type with non-null items but nullable list: [Item!]
Step-by-Step Solution
Solution:
  1. Step 1: Understand nullable list vs nullable items

    To allow empty lists, the list itself must be nullable or allow empty, but items inside can be non-null.
  2. Step 2: Match correct syntax

    Use a list type with non-null items but nullable list: [Item!] uses [Item!] which means list can be null or empty, but items are non-null, allowing empty many side.
  3. Final Answer:

    Use a list type with non-null items but nullable list: [Item!] -> Option D
  4. Quick Check:

    Nullable list allows empty many side [OK]
Quick Trick: Nullable list type allows empty many side [OK]
Common Mistakes:
  • Making list non-null which disallows empty lists
  • Using single item type for many side
  • Confusing nullable items with nullable list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes