Skip to main content

Mutations

Mutations in GraphQL are used to modify data (e.g. create, update, delete data). Mutations return an instance of the object you just modified, so you can query the data you changed.

Below are a couple of examples how to create, update, delete and restore a user. Mostly the same main 4 mutations apply to other objects as well.

Create a new user

mutation CreateUser($input: CreateUserInput!) {
createUser(input: $input) {
id
firstName
lastName
email
createdAt
}
}
Query variables
{
"input": {
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com"
}
}

Update an existing user

mutation UpdateUser($input: UpdateUserInput!) {
updateUser(input: $input) {
id
firstName
lastName
email
}
}
Query variables
{
"input": {
"id": 1,
"firstName": "Peter"
}
}

Delete a user

mutation DeleteUser($id: ID!) {
deleteUser(id: $id) {
id
deletedAt
}
}
Query variables
{
"id": 1
}

Restore a deleted user

mutation RestoreUser($id: ID!) {
restoreUser(id: $id) {
id
deletedAt
}
}
Query variables
{
"id": 1
}