logo

Mutations for Writing Data

Queries read data. Mutations change it. The syntax is similar, but mutations have side effects.

mutation {
  createUser(name: "Alice", email: "alice@example.com") {
    id
    name
  }
}

This creates a user and returns the new user's data. You can request fields from the result just like in queries.

Updating:

mutation {
  updateUser(id: 1, name: "Alicia") {
    id
    name
  }
}

Deleting:

mutation {
  deleteUser(id: 1) {
    success
  }
}

The mutation name (createUser, updateUser) is defined by the server. Check the schema to see what mutations are available.

Mutations run sequentially by default, ensuring predictable order of operations.

I cover mutations in my GraphQL with Python course.