You want to model a many-to-many relationship between Student and Club with extra data like joinDate. How should you design the GraphQL schema?
hard📝 Application Q8 of 15
GraphQL - Type Relationships
You want to model a many-to-many relationship between Student and Club with extra data like joinDate. How should you design the GraphQL schema?
AUse scalar fields in <code>Student</code> to store club IDs and join dates
BCreate a linking type <code>Membership</code> with fields <code>student</code>, <code>club</code>, and <code>joinDate</code>, then reference it in both types
CAdd <code>joinDate</code> field directly to <code>Student</code> and <code>Club</code>
DAdd a list of <code>joinDate</code> strings in both <code>Student</code> and <code>Club</code>
Step-by-Step Solution
Solution:
Step 1: Understand extra data in many-to-many
Extra data on the relationship requires a linking type to hold that data.
Step 2: Design schema accordingly
Create a linking type Membership with fields student, club, and joinDate, then reference it in both types correctly creates a Membership type with references and extra fields, linked from Student and Club.
Final Answer:
Create a linking type Membership with fields student, club, and joinDate, then reference it in both types -> Option B
Quick Check:
Extra data needs linking type = C [OK]
Quick Trick:Use linking type to store extra many-to-many data [OK]
Common Mistakes:
Adding extra fields directly to main types
Using scalar lists for complex data
Ignoring relationship data needs
Master "Type Relationships" in GraphQL
9 interactive learning modes - each teaches the same concept differently