Bird
0
0

Which GraphQL schema snippet correctly models a many-to-many relationship between Teacher and Classroom?

easy📝 Syntax Q3 of 15
GraphQL - Type Relationships
Which GraphQL schema snippet correctly models a many-to-many relationship between Teacher and Classroom?
Atype Teacher { classrooms: Classroom } type Classroom { teachers: Teacher }
Btype Teacher { classroom: Classroom } type Classroom { teacher: Teacher }
Ctype Teacher { classroom: [Classroom] } type Classroom { teacher: [Teacher] }
Dtype Teacher { classrooms: [Classroom!]! } type Classroom { teachers: [Teacher!]! }
Step-by-Step Solution
Solution:
  1. Step 1: Identify many-to-many relationship

    Many-to-many means each Teacher can have multiple Classrooms and each Classroom can have multiple Teachers.
  2. Step 2: Use list types on both sides

    GraphQL lists (e.g., [Classroom!]!) represent multiple related objects.
  3. Final Answer:

    type Teacher { classrooms: [Classroom!]! } type Classroom { teachers: [Teacher!]! } correctly uses lists on both sides.
  4. Quick Check:

    Both types have lists of the other type [OK]
Quick Trick: Use lists on both sides for many-to-many [OK]
Common Mistakes:
  • Using single object instead of list for many-to-many
  • Omitting non-null or list syntax
  • Confusing one-to-many with many-to-many

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes