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
- Apollo Client Setup in Vue 3
- useQuery for Data Fetching
- useMutation for Data Changes
- Real-Time Subscriptions with useSubscription