0Pricing
Vue Academy · Lesson

useMutation for Data Changes

useMutation(MUTATION), mutate(), cache update strategies, optimistic responses.

Changing Data With Mutations

Queries read data; mutations change it — create, update, delete. The useMutation composable runs a GraphQL mutation and gives you a mutate function to call when ready.

Basic useMutation

Pass a mutation document. Unlike useQuery, it does not run immediately — it returns a mutate function you invoke on an event.

import { useMutation } from '@vue/apollo-composable'
import { gql } from '@apollo/client/core'

const { mutate } = useMutation(gql(
  'mutation { addPost { id } }'
))

All lessons in this course

  1. Apollo Client Setup in Vue 3
  2. useQuery for Data Fetching
  3. useMutation for Data Changes
  4. Real-Time Subscriptions with useSubscription
← Back to Vue Academy