Overview
TheMutationCache is responsible for storing and managing all Mutation instances. It handles mutation scoping, execution ordering, and provides methods to access and manipulate mutations.
Constructor
MutationCacheConfig
Configuration options for the MutationCache
Methods
build()
Builds a new mutation instance.QueryClient
required
The QueryClient instance
MutationOptions
required
Mutation options
MutationState
Initial state for the mutation
Mutation instance
add()
Adds a mutation to the cache.Mutation
required
The mutation instance to add
remove()
Removes a mutation from the cache.Mutation
required
The mutation instance to remove
clear()
Removes all mutations from the cache.getAll()
Returns all mutations in the cache.Mutation instances
Example:
find()
Finds a single mutation that matches the filters.MutationFilters
required
Filters to match mutations
Mutation or undefined
Example:
findAll()
Finds all mutations that match the filters.MutationFilters
Filters to match mutations
Mutation instances
Example:
canRun()
Determines if a mutation can run based on scoping rules.Mutation
required
The mutation to check
true if the mutation can run, false otherwise
Mutations with the same scope ID execute sequentially. A mutation can run if there are no other pending mutations in its scope, or if it is the first pending mutation in the scope.
runNext()
Runs the next paused mutation in the same scope.Mutation
required
The mutation that just completed
notify()
Notifies all subscribers of a cache event.MutationCacheNotifyEvent
required
The event to notify subscribers about
subscribe()
Subscribes to cache events.(event: MutationCacheNotifyEvent) => void
required
Callback function to handle cache events
resumePausedMutations()
Resumes all paused mutations.This is typically called automatically when the network comes back online.
Mutation Scoping
Mutations can be scoped using thescope option. Mutations with the same scope ID will execute sequentially rather than concurrently.
Example:
Events
The MutationCache emits the following events:added- When a mutation is added to the cacheremoved- When a mutation is removed from the cacheupdated- When a mutation’s state changesobserverAdded- When an observer subscribes to a mutationobserverRemoved- When an observer unsubscribes from a mutationobserverOptionsUpdated- When observer options are updated