Bird
0
0

In GraphQL, how do you represent a many-to-many relationship between two types, for example, Author and Book?

easy📝 Conceptual Q11 of 15
GraphQL - Type Relationships
In GraphQL, how do you represent a many-to-many relationship between two types, for example, Author and Book?
ABy having a list of <code>Book</code> in <code>Author</code> and a list of <code>Author</code> in <code>Book</code>
BBy having a single field of <code>Book</code> in <code>Author</code> only
CBy using scalar fields only, no lists
DBy embedding <code>Author</code> inside <code>Book</code> as a string
Step-by-Step Solution
Solution:
  1. Step 1: Understand many-to-many relationship in GraphQL

    Many-to-many means each Author can have many Books and each Book can have many Authors.
  2. Step 2: Represent with lists on both types

    To model this, both Author and Book types should have a list field referencing the other type.
  3. Final Answer:

    By having a list of Book in Author and a list of Author in Book -> Option A
  4. Quick Check:

    Many-to-many = lists on both sides [OK]
Quick Trick: Use lists on both types to link many items [OK]
Common Mistakes:
  • Using a single object instead of a list
  • Not linking both types with lists
  • Using scalar fields instead of object references

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes