Bird
0
0

Which of the following is the correct GraphQL schema snippet to define a many-to-many relationship between Student and Course?

easy📝 Syntax Q12 of 15
GraphQL - Type Relationships
Which of the following is the correct GraphQL schema snippet to define a many-to-many relationship between Student and Course?
Atype Student { course: Course } type Course { student: Student }
Btype Student { courses: Course } type Course { students: Student }
Ctype Student { courses: String } type Course { students: String }
Dtype Student { courses: [Course!]! } type Course { students: [Student!]! }
Step-by-Step Solution
Solution:
  1. Step 1: Check list syntax for many-to-many

    Many-to-many requires lists, so fields must be lists like [Course!]! and [Student!]!.
  2. Step 2: Validate non-null and list usage

    type Student { courses: [Course!]! } type Course { students: [Student!]! } correctly uses non-null lists of non-null items, which is best practice.
  3. Final Answer:

    type Student { courses: [Course!]! } type Course { students: [Student!]! } -> Option D
  4. Quick Check:

    Lists with non-null = correct schema [OK]
Quick Trick: Use square brackets for lists in GraphQL schema [OK]
Common Mistakes:
  • Missing square brackets for lists
  • Using singular fields instead of lists
  • Using scalar types instead of object types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes