SyntaxStudy
Sign Up
GraphQL Beginner 10 min read

GraphQL Mutations

While queries fetch data, mutations are used to modify data — creating, updating, or deleting records. Mutations can also return data, so you can update your client after a mutation in a single round trip.

Example
# Create a new user
mutation CreateUser($input: CreateUserInput!) {
  createUser(input: $input) {
    id
    name
    email
    createdAt
  }
}

# Variables
{
  "input": {
    "name": "Alice",
    "email": "alice@example.com",
    "password": "securepassword"
  }
}

# Update a user
mutation UpdateUser($id: ID!, $name: String!) {
  updateUser(id: $id, name: $name) {
    id
    name
    updatedAt
  }
}

# Delete a record
mutation DeletePost($id: ID!) {
  deletePost(id: $id) {
    success
    message
  }
}