What are GraphQL mutations?
Mutations in GraphQL allow us to update the data in the API server, and with the help of it, we can create, update, or remove the data in the backend database. They are defined in the GraphQL schema, and the users can refer the schema to call the mutation with the required fields to update the data by calling the API in the server. Let’s look at a mutation example.
Example –
In the below example query, the createUser mutation is used to create a new user on the server when the query is hit. It accepts the input data, “name” and “email” and uses the data passed in the arguments to create a new entry for the user the server database.
mutation {
createUser(input: { name: "John Doe", email: "john@example.com") {
id
name
}
}
Handling Data Updates in GraphQL
GraphQL is an open source query language for the APIs that allows us to query and fetch only the data we require on the client side, and also shows us the detailed schema of all the fields supported in the API. It helps saving a lot network bandwidth with just sending and receiving the fields that we want, and with its strongly typed nature, we can easily identify all the queries and mutations supported by the server. In this article, we will learn about handling data updates in GraphQL.