Skip to main content

Mutation

The Mutation type is used to define declarative data mutations. It is required input for the useDataMutation hook, DataMutation component, and DataEngine.mutate method.

A mutation defines a destructive operation performed on a collection or instance of a particular resource.

Properties

PropertyTypeDescription
typestringrequiredThe type of mutation to perform, must be one of create, update, json-patch*, or delete.
resourcestringrequiredThe path to the resource being requested, i.e. indicators.
idstring or () => stringRequired for update and delete mutations, not allowed for create mutations. Indicates that a particular instance of a collection will be mutated
partialbooleanIf performing an update mutation, set partial: true to replace only the provided fields of the target object.
paramsObject or () => ObjectA dictionary of properties which are translated into querystring parameters when the data is fetched
dataObject or () => ObjectThe "body" of the mutation, the content of the newly created or updated resource. Disallowed for delete mutations

See the Mutation type definition for more information

* When choosing the json-patch type, a PATCH request with content-type application/json-patch+json will be sent and the server will expect the "body" of the mutation to be a "patch document" (i.e. an array of operations). See jsonpatch.com for a brief overview, or JSON Patch specifications in RFC 6902 for full details.

Examples

Delete an existing indicator

const deleteMutation = {
type: 'delete',
resource: 'indicators',
id: 'xyz123',
}

Update an existing indicator, only overwriting the name property

const updateMutation = {
type: 'update',
partial: true,
resource: 'indicators',
id: 'xyz123',
data: {
name: 'MyNewName',
},
}

Create a new indicator, accepting the name as a variable, allowing it to be specified at the time the mutation is executed

const dynamicCreateMutation = {
type: 'create',
resource: 'indicators',
data: ({ name }) => ({
name,
shortName: name,
indicatorType: {
id: 'bWuNrMHEoZ0',
},
numerator: '#{fbfJHSPpUQD}',
denominator: '#{h0xKKjijTdI}',
}),
}