Mutation
TheMutation class represents a single mutation instance. It manages the lifecycle of a mutation execution, including state, retries, and callbacks.
Import
Constructor
Type Parameters
type
default:"unknown"
The type of data returned by the mutation function
type
default:"DefaultError"
The type of error that can be thrown
type
default:"unknown"
The type of variables passed to the mutation function
type
default:"unknown"
The type of context returned by onMutate
Properties
state
options
mutationId
Methods
execute
pause
continue
cancel
setState
Examples
Accessing Mutation State
Filtering Mutations
Accessing Mutation Options
Checking Mutation Status
Subscribing to Mutations
Manually Creating Mutations
Pausing and Resuming
Canceling Mutations
Mutation State
The mutation state object contains:'idle' | 'pending' | 'success' | 'error'
The current status of the mutation
TData | undefined
The data returned by the mutation function (only set on success)
TError | null
The error thrown by the mutation function (only set on error)
TVariables | undefined
The variables passed to the mutation function
TContext | undefined
The context returned by the onMutate callback
number
The number of times the mutation has failed
TError | null
The reason for the last failure
boolean
Whether the mutation is currently paused
number
Timestamp when the mutation was submitted
Notes
Mutationis a low-level class typically created and managed byMutationCache- Each call to
mutate()creates a newMutationinstance - Mutations are kept in the cache even after completion for state tracking
- The
mutationIdis unique and auto-incremented - Mutations support pause/resume for handling network state changes
- Failed mutations can be retried based on the retry configuration
- State changes trigger notifications to observers and cache subscribers
- Mutations are automatically removed from cache based on
gcTimesetting