mutationUtils
Helpers for Relay mutation updaters, so the common store edits need no hand-written
RecordProxy or
ConnectionHandler code. They cover the usual cases, not every store manipulation.Relay
When to use
Use when
- an
updateroroptimisticUpdaterinserts into or removes from a linked-record list or a@connection; - an optimistic response must populate the store before the server answers;
- each mutation needs its own
clientMutationId.
Avoid when
- the update is specific — nested records or many-to-many links; edit the store directly;
- you need to store a nested object with
setValue— these helpers skip nested objects.
Usage
import { commitMutation } from '@apollion-dsi/relay/commitMutation';
import { connectionDeleteEdgeUpdater } from '@apollion-dsi/relay/mutationUtils';
await commitMutation<DeleteTodoMutation>(Environment, {
mutation: DeleteTodo,
variables: { id: todoId },
updater: (store) => {
connectionDeleteEdgeUpdater({ parentId: userId, connectionName: 'TodoList_todos', nodeId: todoId, store });
},
});API
Export | Use |
|---|---|
listRecordAddUpdater | append a record; nested objects are not passed to setValue |
listRecordRemoveUpdater | drop the record whose getDataID() matches; return when the list is null |
connectionUpdater | insert an edge into a @connection |
optimisticConnectionUpdater | optimistic edge, id client:newEdge:<dataID> |
connectionDeleteEdgeUpdater | remove an edge from a @connection |
copyObjScalarsToProxy | copy scalar fields onto a RecordProxy; nested objects are not passed to setValue |
createClientMutationID | a new id on every call |
ClientMutationID | the id created once when this module loads; kept for existing call sites |
isObject | true for a non-null object |
Scrolls sideways inside the table. The page does not.
createClientMutationID() returns a new nanoid per call. ClientMutationID remains that once-per-load
constant so existing call sites keep compiling.