Skip to content

@sanity/mutateToolkit for Sanity mutations

Mutation creators, an in-memory apply engine, and an optimistic local store.

@sanity/mutate

Example

ts
import {
  
at
,
create
,
createIfNotExists
,
patch
,
SanityEncoder
,
set
,
setIfMissing
,
} from '@sanity/mutate' const
patches
= [
at
('published',
set
(true)),
at
('address',
setIfMissing
({
_type
: 'address'})),
at
('address.city',
set
('Oslo')),
] const
mutations
= [
create
({
_type
: 'dog',
name
: 'Fido'}),
createIfNotExists
({
_id
: 'document-1',
_type
: 'someType'}),
patch
('other-document',
patches
),
] const
payload
=
SanityEncoder
.
encodeAll
(
mutations
)

NOTE

@sanity/mutate is experimental. Expect API changes between minor versions.