Understanding queries, mutations, and subscriptions
When creating a GraphQL API, we want to do more than just get data: we may also want to write to a datastore or be notified when some data changes. In this section, we'll see how to do both actions in GraphQL.
Let's take a look at how to write data using mutations first:
- We will create a mutation called
addTodo
, but in order to make the mutation more realistic, we will need a temporary datastore. So, we will create an in-memory datastore for testing purposes. Create thedb.ts
file and add this code to it:import { v4 } from "uuid"; export const todos = [ { id: v4(), title: "First todo", description: "First todo description", }, { id: v4(), title: "Second todo", description: "Second todo description...