Bird
0
0

Which of the following is the correct GraphQL schema snippet to represent a one-to-many relationship between Author and Book?

easy📝 Syntax Q12 of 15
GraphQL - Type Relationships
Which of the following is the correct GraphQL schema snippet to represent a one-to-many relationship between Author and Book?
Atype Author { id: ID! name: String! books: [Book!]! } type Book { id: ID! title: String! authorId: ID! }
Btype Author { id: ID! name: String! book: Book } type Book { id: ID! title: String! author: Author }
Ctype Author { id: ID! name: String! books: Book } type Book { id: ID! title: String! authorId: ID! }
Dtype Author { id: ID! name: String! books: Book! } type Book { id: ID! title: String! authorId: ID! }
Step-by-Step Solution
Solution:
  1. Step 1: Identify list type for many children

    In GraphQL, a one-to-many uses a list type like [Book!]! for multiple books.
  2. Step 2: Check each option's books field

    type Author { id: ID! name: String! books: [Book!]! } type Book { id: ID! title: String! authorId: ID! } uses books: [Book!]! correctly; others use single Book or wrong types.
  3. Final Answer:

    type Author { id: ID! name: String! books: [Book!]! } type Book { id: ID! title: String! authorId: ID! } -> Option A
  4. Quick Check:

    List type for many children = [Type!]! [OK]
Quick Trick: Use square brackets [] for lists in GraphQL schema [OK]
Common Mistakes:
  • Using single type instead of list for many children
  • Missing non-null ! on list or items
  • Confusing field names or types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes