Mutation
Every member of the Mutation namespace: defining and running mutations.
Mutation defines mutations, and runs them from Effect. Import it from the core entry point:
import { } from "@monarcode/effetch-query";Its exports follow, grouped by the guide that covers them, each with its docs. Your editor shows the same docs, with an example, when you hover the name.
Define a mutation
Guide: Define a mutation.
Mutation.make
Defines a mutation. Nothing runs until it's used, with run or useMutation. Its types come from run: annotate run's parameter to type the variables. Explicit type arguments must give all three, since the value and error types left out are never.
Mutation.isMutation
Checks whether a value is a Mutation. A mutation's variables can't be known from the value, so it narrows to Mutation<never, unknown, unknown>, which every mutation is.
Mutation.TypeId
The property that marks a Mutation.
Mutation.Mutation
A mutation's definition: what a run does with its Variables, succeeding with A or failing with E. Create one with make, and run it with run or useMutation.
A definition holds no state. Each use (each component's useMutation) keeps its own, so components never share a waiting or failed state.
Prop
Type
Mutation options
Guide: Mutation options.
Mutation.MakeOptions
Options for make. A run calls them in this order:
optimistic, whose cache writes are recorded;- the client's
mutations.onMutate; run, retried onretry;- on success:
onSuccess,invalidates, then the client'smutations.onSuccess; - on failure: the optimistic writes are rolled back, then
onFailure, then the client'smutations.onFailure; onSettled, then the client'smutations.onSettled.
The run completes after all of them. If one of the callbacks here dies, the run dies with its defect and the steps after it don't happen, except that a run whose optimistic dies still has its writes rolled back.
An interrupted run (with concurrent: false, replaced by a newer one; or its client disposed, which also interrupts runs concurrent: "queue" holds back) calls nothing after the interruption. If run hadn't succeeded yet, its optimistic writes are rolled back, unless the client is being disposed: then there's no cache left to put back.
Prop
Type
Run a mutation
Guide: Run a mutation.
Mutation.run
Runs a mutation from Effect code, with the steps MakeOptions lists, and succeeds or fails as its run did. A mutation whose run takes no variables runs without them. Each call is a run of its own: concurrent applies to one use's runs, such as a component's useMutation, so calls never interrupt each other. It dies with a Query.KeyHoldsTargetError before it starts if a key in invalidates holds a query, a family or a group.