Bird
0
0

Given this GraphQL schema snippet:

medium📝 query result Q13 of 15
GraphQL - Type Relationships
Given this GraphQL schema snippet:
type Author {
  id: ID!
  books: [Book!]!
}

type Book {
  id: ID!
  title: String!
  author: Author!
}

What will the query { author(id: "1") { books { title } } } return if author 1 has two books titled "A" and "B"?
A{"data":{"author":{"books":{"title":"A"}}}}
B{"data":{"author":{"books":[{"title":"A"},{"title":"B"}]}}}
C{"data":{"author":{"books":null}}}
D{"errors":[{"message":"Field 'books' not found"}]}
Step-by-Step Solution
Solution:
  1. Step 1: Understand schema and query

    Author has a list of books. Query asks for author with id "1" and their books' titles.
  2. Step 2: Predict query result

    Since author 1 has two books "A" and "B", the books field returns a list with both titles.
  3. Final Answer:

    {"data":{"author":{"books":[{"title":"A"},{"title":"B"}]}}} -> Option B
  4. Quick Check:

    List of books with titles A and B returned [OK]
Quick Trick: List fields return arrays of objects in GraphQL query results [OK]
Common Mistakes:
  • Expecting a single book object instead of a list
  • Assuming null if multiple books exist
  • Confusing error with missing field

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes