mutationUtils
A set of helpers for writing Relay mutation updaters without
having to manipulate RecordProxy/ConnectionHandler by hand in every
common case. Covers:
- inserting/removing items in
linked recordslists; - inserting/removing edges in paginated connections (
@connection); - optimistic updaters for connections;
- copying scalar fields from a JS object to a
RecordProxy.
It also exports ClientMutationID, an id generated once per
module load to fill the clientMutationId field
expected by the Relay Modern pattern.
When to use
| ✅ Use when… | 🚫 Avoid when… |
|---|---|
|
|
Example
import { commitMutation } from '@apollion-dsi/relay';
import { connectionDeleteEdgeUpdater } from '@apollion-dsi/relay/mutationUtils';
await commitMutation<DeleteTodoMutation>(Environment, {
mutation: graphql`...`,
variables: { id: todoId },
updater: (store) => {
connectionDeleteEdgeUpdater({
parentId: userId,
connectionName: 'TodoList_todos',
nodeId: todoId,
store,
});
},
});Granular imports
import { connectionDeleteEdgeUpdater } from '@apollion-dsi/relay/mutationUtils';
// or via the root barrel
import { connectionDeleteEdgeUpdater } from '@apollion-dsi/relay';See also
- Full API:
mutationUtils.ts. - Promise wrapper for mutations:
commitMutation. - Relay Store updates: https://relay.dev/docs/guided-tour/updating-data/local-data-updates/ (opens in a new tab)