Bird
0
0

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:
  1. Step 1: Understand extra data in many-to-many

    Extra data on the relationship requires a linking type to hold that data.
  2. 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.
  3. Final Answer:

    Create a linking type Membership with fields student, club, and joinDate, then reference it in both types -> Option B
  4. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes