Types of GraphQL Mutations

There are different types of mutations available in GraphQL –

  • Create Mutations: It is used to create a new resource onto the server
  • Delete Mutations: It is used to delete a resource from the database
  • Update Mutations: It is used to update or modify a resource on the server
  • Custom Mutations: We can also define some custom mutations to perform some custom operation

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.

Similar Reads

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....

What are GraphQL subscriptions?

With the help of subscriptions, the users can get real-time updates on the data changes in the server. This is useful in case of features that require real-time data handling like trading sites, or live chats, push notifications, etc. They are akin to a pub-sub model where the users subscribe to a particular event in the server model, and receive updates when there is a change in the specified model....

Types of GraphQL Mutations

There are different types of mutations available in GraphQL –...

Update Mutations

We can use Update Mutations in GraphQL update or modify a resource on the server. The mutation accepts an input object in its argument, and the object is then used to update the existing data on the server. Let’s look at an example to understand it in more detail...

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....

Conclusion

In this article, we learnt about the GraphQL mutations and subscriptions, and how we can use these two operations to handle data updates in the GraphQL. GraphQL mutations are used when we want to update (add, remove, patch) the data in the server, and subscriptions are used when we want to listen to the real-time data updates in a specific data model in the GraphQL server....

Contact Us