React
Boost Your React Apps with Apollo: Fetching & Updating Data

Create Data with Mutations

PRO

So far, we've only learned how to get data with GraphQL, which is kinda boring. How do we do something with that data? How do we change it, add to it, or delete it? For that, we'll use mutations.

We're going to use the createHabit mutation. This mutation takes an input of type NewHabitInput, which is an object that contains a description.

To use variables with this mutation, we can prefix an argument to the mutation with a $ and then pass that into createHabit.

Here's our finished mutation:

mutation createHabit($input: NewHabitInput) {
    createHabit(input: $input) {
      id
      description
      points
      entries {
        id
        notes
        date
        completed
      }
    }
  }

In this next video, we'll add this to the code.

 

I finished! On to the next chapter