Bird
0
0

Which of the following is the correct syntax to define a one-to-many relationship in a GraphQL type?

easy📝 Syntax Q3 of 15
GraphQL - Type Relationships
Which of the following is the correct syntax to define a one-to-many relationship in a GraphQL type?
Atype Author { books: Book[] }
Btype Author { books: Book }
Ctype Author { books: [Book] }
Dtype Author { books: Book! }
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to represent multiple related items in GraphQL

    Square brackets [] indicate a list of items in GraphQL types.
  2. Step 2: Match this to the options

    Only type Author { books: [Book] } uses [Book] to show many books related to an author.
  3. Final Answer:

    type Author { books: [Book] } -> Option C
  4. Quick Check:

    List syntax uses brackets = D [OK]
Quick Trick: Use square brackets [] for lists in GraphQL types [OK]
Common Mistakes:
  • Using Book without brackets for multiple items
  • Using Book! which means non-null single item
  • Using Book[] which is invalid syntax in GraphQL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes