Skip to content

API reference > @kontsedal/olas-core > defineMutation

defineMutation() function ​

Define a mutation at module scope. The definition is registered by id, so a plugin can run it with no controller present. The mutation queue replays a run persisted before a reload this way.

ts
// module scope
export const createOrder = defineMutation({
  id: 'order/create',
  mutate: (vars: OrderInput, { signal, deps }) => deps.api.createOrder(vars, { signal }),
  meta: { persist: true },
})

// a controller
const place = createMutation(ctx, createOrder, {
  onSuccess: () => toast('Order placed'),
})

mutate must not close over controller state, because on a replay there is no controller. Reach services through deps instead.

Signature:

typescript
declare function defineMutation<V, R>(definition: MutationDefinition<V, R>): MutationDef<V, R>;

Parameters ​

Parameter

Type

Description

definition

MutationDefinition<V, R>

Returns:

MutationDef<V, R>

Released under the MIT License.