Basic mutations in GraphQL

From the GraphQL cheat sheet · Mutations · verified Jul 2026

Basic mutations

graphql
# Simple mutation
mutation {
  createUser(input: {
    name: "John Doe"
    email: "john@example.com"
    password: "secure123"
  }) {
    id
    name
    email
  }
}

# Mutation with variables
mutation CreatePost($title: String!, $content: String!) {
  createPost(title: $title, content: $content) {
    id
    title
    content
    published
    author {
      name
    }
  }
}

# Update mutation
mutation UpdateUser($id: ID!, $input: UpdateUserInput!) {
  updateUser(id: $id, input: $input) {
    id
    name
    email
    updatedAt
  }
}

# Delete mutation
mutation DeletePost($id: ID!) {
  deletePost(id: $id) {
    success
    message
  }
}
💡 Mutations modify server-side data
⚡ Return updated data after mutation
📌 Use input types for complex arguments
🟢 Can include queries in response

More GraphQL tasks

Back to the full GraphQL cheat sheet