Complete the code to define a GraphQL type for a single Author.
type Author {
id: ID!
name: String!
[1]: [Book!]!
}The field books represents the list of books an author has written, showing the one-to-many relationship.
Complete the code to define a GraphQL type for a Book with a reference to its Author.
type Book {
id: ID!
title: String!
[1]: Author!
}The field author links each book to its single author, showing the many-to-one side of the relationship.
Fix the error in the Book type where the author field is incorrectly typed as a list.
type Book {
id: ID!
title: String!
author: [1]
}The author field should be a single Author! type, not a list, because each book has exactly one author.
Fill both blanks to define a query that fetches all authors and their books.
type Query {
[1]: [Author!]!
[2]: [Book!]!
}The query fields authors and books return lists of authors and books respectively.
Fill all three blanks to define a mutation that adds a new book with an author ID.
type Mutation {
addBook(title: String!, authorId: ID!): [1]!
}
type Book {
id: ID!
title: String!
author: [2]!
}
input [3]Input {
title: String!
authorId: ID!
}The mutation returns a Book type. The book's author field is of type Author. The input type for adding a book is named AddBookInput.