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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.