Mutation creators
Build mutations from creator functions. Mutations are plain values; pass them around, transform them, compose them across documents.
Mutation creators, an in-memory apply engine, and an optimistic local store.
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.