Chapter 7. Relay Mutations

In this chapter, we will define a Relay-compliant GraphQL mutation and see how to invoke it in Relay. The mutation will allow users to like a quote. Once liked, the likes count in the UI will increase.

The topics we'll cover in this chapter are:

  • Defining a Relay-compliant mutation
  • Invoking mutations with Relay
  • Relay's optimistic updates

Relay-compliant GraphQL mutations

In the previous chapter, we implemented the likes count feature and used mock random data to test it out. Let's now allow the users to click on the thumbs-up icon to like a quote and replace the mock random data we used before with actual data in the database.

First, we need to define a GraphQL mutation to record the like action. This mutation will take one ...

Get Learning GraphQL and Relay now with O’Reilly online learning.

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