0
0
GraphQLquery~10 mins

One-to-many relationships in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a GraphQL type for a single Author.

GraphQL
type Author {
  id: ID!
  name: String!
  [1]: [Book!]!
}
Drag options to blanks, or click blank then click option'
Abooks
Bbook
Cauthor
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular form like 'book' which implies only one book.
Using unrelated field names like 'author' or 'title' here.
2fill in blank
medium

Complete the code to define a GraphQL type for a Book with a reference to its Author.

GraphQL
type Book {
  id: ID!
  title: String!
  [1]: Author!
}
Drag options to blanks, or click blank then click option'
Abooks
Bauthor
Cwriters
Dpublisher
Attempts:
3 left
💡 Hint
Common Mistakes
Using plural forms like 'books' or 'writers' which don't fit here.
Using unrelated fields like 'publisher' which is not part of this relationship.
3fill in blank
hard

Fix the error in the Book type where the author field is incorrectly typed as a list.

GraphQL
type Book {
  id: ID!
  title: String!
  author: [1]
}
Drag options to blanks, or click blank then click option'
A[Author!]
BString!
CAuthor!
DID!
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list type which implies multiple authors per book.
Using scalar types like String or ID instead of the Author type.
4fill in blank
hard

Fill both blanks to define a query that fetches all authors and their books.

GraphQL
type Query {
  [1]: [Author!]!
  [2]: [Book!]!
}
Drag options to blanks, or click blank then click option'
Aauthors
Bauthor
Cbooks
Dbook
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular names which imply single items instead of lists.
Mixing up authors and books field names.
5fill in blank
hard

Fill all three blanks to define a mutation that adds a new book with an author ID.

GraphQL
type Mutation {
  addBook(title: String!, authorId: ID!): [1]!
}

type Book {
  id: ID!
  title: String!
  author: [2]!
}

input [3]Input {
  title: String!
  authorId: ID!
}
Drag options to blanks, or click blank then click option'
ABook
BAuthor
CAddBook
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return types for mutation.
Confusing author type with book type.
Naming input type incorrectly.