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.
GraphQL
Beginner
10 min read
GraphQL Mutations
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
}
}
Related Resources
GraphQL Reference
Complete tag & property list
GraphQL How-To Guides
Step-by-step practical guides
GraphQL Exercises
Practice what you've learned
More in GraphQL