Overview
Mutations are non-idempotent requests — POST, PUT, PATCH, DELETE. Unlike queries, mutations:- Do not cache their results
- Do not deduplicate concurrent calls
- Support lifecycle hooks (
onMutate,onSuccess,onError,onSettled) - Can automatically invalidate related queries after success
Basic mutation
MutationOptions
Execution order
onMutate runs before the request. Its return value becomes context, which is passed to all subsequent hooks. This is the standard pattern for optimistic updates with rollback.
onSettled always fires regardless of success or error — use it for cleanup.
Optimistic updates
Automatic invalidation
Useinvalidates to specify endpoints that should be invalidated after a successful mutation. Kweri calls invalidateQuery(ep, {}) for each — suitable when the endpoint doesn’t require params.
In React hooks
TheuseMutation hook wraps kweri.mutate with reactive status tracking:
ReactMutationResult
In Vue composables
VueMutationResult
Optimistic updates with path-based hooks
When usingusePost, usePut, usePatch, useDelete, lifecycle hooks are handled inline in your action functions since the path hooks don’t accept callback options: