Browse documentation

MutationHandle

Exposes the public state and operations of a mutation.

Table of contents

Category

Value

Import

js
import { MutationHandle } from "valyrian.js/query";

Public signature

ts
client.mutation<TPayload, TResult>(config: MutationConfig<TPayload, TResult>): MutationHandle<TPayload, TResult>

API form

MutationHandle is a class instance returned by QueryClient.mutation(...). Application code obtains it from the client instead of calling its infrastructure constructor.

Configuration

ts
type MutationConfig<TPayload, TResult> = {
  execute: (payload: TPayload) => Promise<TResult> | TResult;
  onSuccess?: (result: TResult) => void;
  onError?: (error: unknown) => void;
};

Properties and methods

ts
type QueryState<TResult> = {
  status: "idle" | "loading" | "success" | "error";
  loading: boolean;
  success: boolean;
  error: unknown;
  data: TResult | null;
  updatedAt: number;
};

readonly state: QueryState<TResult>
execute(payload: TPayload): Promise<TResult>
reset(): void

Execution outcomes

execute() updates mutation state and invokes the matching success or error callback. A rejected operation leaves its error in state and rejects execute(). reset() restores idle state and clears result and error.