Example of Update Mutations
In this example, we will see a sample GraphQL mutation that updates a user information. The mutation takes an id, and the input object as its arguments, and then update the existing user object in the database with the passed information.
mutation {
updateUser(id: "user_id", input: { name: "GFG" }) {
id
name
}
}
In the above example, the updateUser mutation takes in “id”, and “input” object, and pass in “name” in the object to specify the new value of “name” field. We then request id, and name from the mutation’s response to verify whether the fields have been updated
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.
Contact Us