Queries and Mutations
Explore how to define and implement basic GraphQL queries and mutations in a Deno application. Learn to handle data retrieval and additions for books, authors, and reviews while testing operations using a GraphiQL interface. Understand schema definitions, resolver setup, and running a Deno server to serve your GraphQL endpoint.
We'll cover the following...
Overview
Now that we have defined the schema, types, queries, and mutations, let’s dive deeper into these concepts. To keep everything simple, we’ll define the following queries:
getAllBooks()getAllAuthors()getBook(id: String)getAuthor(id: String)
We’ll also define the following mutations:
addBook(input: BookInput!)addAuthor(input: AuthorInput!)addReview(input: ReviewInput!)
Note: We’ll only add the entities for now and we won’t link them (that is, we won’t add an author and reviews to a book).
Queries
Now that we’ve listed our queries, let’s start defining them. First of all, we need some data, so let’s add the following example data:
Now let’s define our queries below:
We can use the code widget below to test our queries. Try using one of the queries we defined in a new ...