Handling mutations with Apollo Client

Mutating data makes using GraphQL more interesting because when data is mutated, some side effects should be executed. For example, when a user adds a product to their cart, the data for the cart should be updated throughout the component as well. This is quite easy when you're using Apollo Client since the Provider handles this in the same way the context API.

Before writing your first mutation, the definitions of the executable queries for the cart should be moved to a constants file. That way, you can easily import them into other components to reuse and execute them as a side effect. Creating the new constants file and moving all the GraphQL queries and mutations to it requires that we make the following ...

Get React Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.