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
Property | Type | Description | |
---|---|---|---|
type | string | required | The type of mutation to perform, must be one of create , update , json-patch *, or delete . |
resource | string | required | The path to the resource being requested, i.e. indicators . |
id | string or () => string | Required for update and delete mutations, not allowed for create mutations. Indicates that a particular instance of a collection will be mutated | |
partial | boolean | If performing an update mutation, set partial: true to replace only the provided fields of the target object. | |
params | Object or () => Object | A dictionary of properties which are translated into querystring parameters when the data is fetched | |
data | Object or () => Object | The "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-typeapplication/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}',
}),
}