Overstacked

Writing your first mutation 🔄

Learn how to write your first GraphQL mutation in the GraphQL Playground.

It's time to write our first mutation. Mutations are used to create, update, and delete data. Let's write a mutation to create a user.

mutation CreateUser($name: String!) {
  createUser(name: $name) {
    id
    name
  }
}

The anatomy of a mutation

Mutations are made up of a few key parts:

  • mutation: This is the keyword that tells the server that we are making a mutation.
  • createUser: This is the name of the field we are mutating.
  • name: $name: This is the data we are passing to the mutation.

We can also pass variables to queries and mutations. In this case, we are passing a variable called $name. Variables are prefixed with a $ and are used to pass data to the mutation.

On this page