# @monarcode/effetch-query/effetch (https://effetch-query.monarcode.dev/docs/reference/effetch)

`@monarcode/effetch-query/effetch` turns Effetch endpoints into queries and mutations. Import what you use:

```ts
import {
  EndpointQueryError,
  fromClient,
} from "@monarcode/effetch-query/effetch";
```

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.

## Queries from endpoints

Guide: [Queries from endpoints](https://effetch-query.monarcode.dev/docs/queries).

### fromClient

Turns `Fetch.endpoint` definitions into queries and mutations that call them through your Effetch client: give it the client's service, a `Fetch.Service` class or a `Context.Service` key. Use it at module level, next to the definitions: the client is only reached when a query fetches or a mutation runs, from your services (so the service must be in `Register["services"]`). Returns an [`Endpoints`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpoints-type), whose `query`, `infiniteQuery` and `mutation` make them.

The adapter adds no behavior of its own: a query is a [`Query.family`](https://effetch-query.monarcode.dev/docs/reference/query#family) member keyed by its route, and a mutation is a [`Mutation.make`](https://effetch-query.monarcode.dev/docs/reference/mutation#make) whose `run` calls the endpoint, and that invalidates its route with `EndpointsOptions.invalidates`. From a `Fetch.Service` class it reads the `defaultError` and `statusErrors` the client is made with, to send errors to the browser; from a `Context.Service` key, give them in the options ([`EndpointsOptions`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointsoptions)). The definitions of a `Fetch.Endpoints` class (`TodoApi.definitions`) work as any other. It needs `@monarcode/effetch` 0.1, from `0.1.0-rc.4`.

### endpoints

**Deprecated.** Use [`fromClient`](https://effetch-query.monarcode.dev/docs/reference/effetch#fromclient): rename the import and the call.

The former name of [`fromClient`](https://effetch-query.monarcode.dev/docs/reference/effetch#fromclient), which works the same: it takes the same client and options, and returns the same [`Endpoints`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpoints-type). It stays for the 0.1 releases and goes in 0.2.0.

### EndpointQuery

A family of queries, one per call of an Effetch endpoint, made by `Endpoints.query`. Call it with the endpoint's `params` and `query` to get the query for that call. Its key is the route's path with the params filled in, then the query object: `GET /todos/:id` called with `{ params: { id: 1 } }` is `["todos", 1]`.

Calls that send the same request share a query: what isn't sent doesn't count (`params` the path doesn't name, `null` and `undefined` query values and array items, and arrays left empty). Without a `query` schema, values are otherwise compared as given, so `{ page: 1 }` and `{ page: "1" }` are two queries.

The key has no method, scheme or host, so give a backend of its own a prefix (`EndpointsOptions.key`), and make one `EndpointQuery` per endpoint: two would share keys but not their cache.

As a target of [`Query.invalidate`](https://effetch-query.monarcode.dev/docs/reference/query#invalidate), [`Query.refetch`](https://effetch-query.monarcode.dev/docs/reference/query#refetch) or a mutation's `invalidates`, it matches exactly its own queries, not other routes under the same path.

With a `query` schema on the endpoint (`QS`), `query` is typed by the schema, and the key holds the query as the schema encodes it, as it's sent: each value a string (a `Date` as its ISO string, `2` as `"2"`) and each field by its sent name. Equal requests share a query, and keys stay JSON for server rendering. The query a member was first called with is the one it sends, and the `args` [`Query.update`](https://effetch-query.monarcode.dev/docs/reference/query#update) gives. A call throws an [`EndpointQueryError`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointqueryerror) when its query doesn't match the schema, a field encodes to an object, or a field is `Redacted`: a key would hold the secret and send it to the browser, so send it in a header.

| Prop       | Type     | Description                                                                                                                                                                                                                               |
| ---------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `key`      | `Key`    | The start every one of its keys has: the prefix and the path up to its first param.                                                                                                                                                       |
| `endpoint` | `object` | The endpoint definition it calls.                                                                                                                                                                                                         |
| `error`    | `union`  | The schema error bodies are decoded with: the endpoint's, else the client's `defaultError` as fromClient knows it (from its options, or a `Fetch.Service` class's config), else `undefined` (the client's applies, but isn't known here). |

### EndpointQueryArgs

What a query from route `R` takes: the path's params, and a query object. They make its key, so `headers` and `plugins` are given once, in [`EndpointQueryOptions`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointqueryoptions), instead.

- `Q`: the type of `query`, checked with `Fetch.QueryOf`, so a value typed with an `interface` is accepted too. Default: `Fetch.QueryInput`.
- `QS`: the endpoint's `query` schema, if it has one: `query` is then the schema's type, required when the schema has required fields.

### EndpointQueryCallError

The error of a query `Endpoints.query` makes from an endpoint: the `Fetch.CallError` of its call, from its `output` schema `O`, its error body schema `EB` ([`ErrorSchema`](https://effetch-query.monarcode.dev/docs/reference/effetch#errorschema)), the client's plugins `Ps`, its status errors `SE` and its stream format `St`. A stream endpoint's elements are decoded as they come, so its `DecodeError` isn't for the whole `output`.

### EndpointQueryOptions

Options for `Endpoints.query`: a query's options ([`Query.Options`](https://effetch-query.monarcode.dev/docs/reference/query#options)), a `placeholder`, `live` updates, and the headers and plugin overrides `client.bind` takes (`Fetch.BindOptions`). `A` is the query's value and `Args` the call's `params` and `query` ([`EndpointQueryArgs`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointqueryargs)), which type `placeholder` and `live`; `api.query` sets both from the endpoint.

| Prop                  | Type            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| --------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `placeholder?`        | `function`      | A value to show for a query until it has one, from the call's `params` and `query`, as Query.MakeOptions.placeholder: an Effect that returns `Option.some(value)`, or `Option.none()` for nothing. It gets the route's `params` and the `query` of the call that made the query: calls that send the same request share one, so a later call's extra fields, or a query it gives in another form that encodes the same, aren't seen. Default: none. |
| `live?`               | `function`      | The server pushes that keep a query's value up to date, from the call's `params` and `query`, as Query.MakeOptions.live: a `Stream` of functions, each applied to the value. Default: none.                                                                                                                                                                                                                                                         |
| `headers?`            | `union`         | Headers for every call, over the definition's. A call's own header wins.                                                                                                                                                                                                                                                                                                                                                                            |
| `plugins?`            | `Overrides<Ps>` | Plugin overrides for every call. A call's own override wins.                                                                                                                                                                                                                                                                                                                                                                                        |
| `staleTime?`          | `union`         | How long a success counts as fresh. Default: 0, stale at once.                                                                                                                                                                                                                                                                                                                                                                                      |
| `retry?`              | `object`        | Retries a failed fetch on this schedule, which gets each failure. Defects aren't retried. Default: no retries.                                                                                                                                                                                                                                                                                                                                      |
| `refetchOnMount?`     | `union`         | If true, refetches a stale query when a component starts using it. Default: `true`.                                                                                                                                                                                                                                                                                                                                                                 |
| `retryOnMount?`       | `union`         | If true, refetches a failed query when a component starts using it, however recent the failure. A suspense reader (React's `useSuspenseQuery`) of a failure with no earlier value throws it to an error boundary instead, so it never starts using the query to retry it (see `useResetQueryFailure`). Default: `true`.                                                                                                                             |
| `refetchOnFocus?`     | `union`         | If true, refetches a stale query in use when the app regains focus (CommonOptions.signals). Default: `true`.                                                                                                                                                                                                                                                                                                                                        |
| `refetchOnReconnect?` | `union`         | If true, refetches a stale query in use when the device reconnects (CommonOptions.signals). Default: `true`.                                                                                                                                                                                                                                                                                                                                        |
| `refetchInterval?`    | `union`         | The interval at which a query in use refetches. A tick that finds a fetch in progress doesn't start another. Polling pauses while nothing uses the query and resumes when something starts using it. Default: no polling.                                                                                                                                                                                                                           |
| `gcTime?`             | `union`         | How long a query nothing uses stays cached. Default: 5 minutes. Like `reactivityKeys` and `entities`, it has no client-wide default.                                                                                                                                                                                                                                                                                                                |
| `reactivityKeys?`     | `union`         | The `Reactivity` keys that refetch this query when invalidated, for Effect code that publishes them (Effect's SQL clients do). Run `Reactivity.invalidate` through the client, as QueryClient.QueryClient.runPromise does, to reach it. Default: none.                                                                                                                                                                                              |
| `entities?`           | `object`        | How this query takes part in the client's entity sync (QueryClient.EntitiesOptions.sync). Default: it does, if it has a `schema`.                                                                                                                                                                                                                                                                                                                   |

### EndpointQueryOptionsFor

The options `Endpoints.query` takes for an endpoint: those of a stream query ([`EndpointStreamOptions`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointstreamoptions)) for a stream endpoint, whose stream format `St` is `"sse"` or `"ndjson"`, else those of a fetched one ([`EndpointQueryOptions`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointqueryoptions)). `E` is the query's error ([`EndpointQueryCallError`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointquerycallerror)), `A` its value ([`EndpointQueryValue`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointqueryvalue)), `R` the endpoint's route and `QS` its `query` schema, which type `placeholder` and `live`.

### EndpointQueryValue

The value of a query `Endpoints.query` makes from an endpoint, from its `output` schema `O` and its stream format `St`: the decoded `output` (the raw `HttpClientResponse` without one), or for a stream endpoint (`stream: "sse"` or `"ndjson"`) its latest element, a `Fetch.SseEvent` of the `output` for SSE.

### Endpoints

Queries and mutations for one Effetch client, made by [`fromClient`](https://effetch-query.monarcode.dev/docs/reference/effetch#fromclient).

| Prop            | Type       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| --------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `query`         | `function` | Defines a family of queries that call an endpoint defined with `Fetch.endpoint`, one query per `params` and `query` (EndpointQuery). The value is the endpoint's `output` (the raw `HttpClientResponse` without one), and the error every error the call can fail with: `NetworkError`, `HttpError` with the decoded error body, `DecodeError` when it has an `output`, the client's plugins' errors, and the errors the endpoint's and the client's `statusErrors` decode, matched by their `_tag` with `Effect.catchTag` or `AsyncResult.builder`'s `onErrorTag`. Only `GET`, `HEAD`, `OPTIONS` and `TRACE` endpoints: a call with a body is a Endpoints.mutation, or a Query.family of your own. An endpoint with a `query` schema is keyed by the query as it's sent (EndpointQuery); its schema can't need services (KeyQuerySchema). Not endpoints with `responseMode`: their calls don't give a value to cache. A stream endpoint (`stream: "sse"` or `"ndjson"`) makes stream queries (Query.stream): the value is the latest element as Effetch gives it, a `Fetch.SseEvent` of the `output` for SSE (read its `data` with `useQuery`'s `select`) or the `output` for NDJSON, and the request runs while the query is read. Its options are EndpointStreamOptions. With an `output`, its queries cross from server to browser with no `schema` to write (`QueryClient.dehydrate`); without one, they aren't sent. The value goes with `output`, and, with `failures: "include"`, Effetch's errors go too: an `HttpError` without its headers, though with its request URL and response text, so keep secrets out of the URLs your server calls; a `NetworkError` without its `cause`; a `DecodeError` without its `issue`. Errors from `statusErrors` go as their schemas encode them, the client's only when fromClient has them: read from a `Fetch.Service` class, or given for a `Context.Service` key (EndpointsOptions.statusErrors). A query that failed with a plugin's error isn't sent. |
| `infiniteQuery` | `function` | Defines a family of infinite queries that call an endpoint page by page, one query per `params` and `query` (EndpointInfiniteQuery), as Endpoints.query makes queries. Each page's param is sent in the query field `pageParam` names; the value is an InfiniteQuery.InfiniteData of the endpoint's `output`, and the error is Endpoints.query's. With a `query` schema, `pageParam` names one of its optional fields (EndpointPageField). Only endpoints without a body. Its queries cross from server to browser as Endpoints.query's do, the page params as JSON.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `mutation`      | `function` | Defines a mutation that calls an endpoint defined with `Fetch.endpoint`, whatever its method. Its variables are the call's options (`params`, `query`, `body`, …: EndpointVariables), with `query` typed by the endpoint's `query` schema if it has one, and it takes a mutation's options (EndpointMutationOptions), such as `invalidates` and `optimistic`. It invalidates what its `invalidates` says, or with EndpointsOptions.invalidates set to `"route"` and no `invalidates` of its own, its route's queries. Its value and errors are those of Endpoints.query. An endpoint whose `input` is a `Fetch.multipart` schema sends `body` as `multipart/form-data`, typed by the schema: an upload, with `Fetch.UploadFile` for each file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

### EndpointsOptions

Options for [`fromClient`](https://effetch-query.monarcode.dev/docs/reference/effetch#fromclient).

| Prop            | Type      | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| --------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `key?`          | `Key`     | A prefix put before every key these endpoints make, when another backend has the same paths: with `["wallet"]`, `GET /accounts/:id` is `["wallet", "accounts", 1]`. Default: no prefix.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `defaultError?` | `EB`      | The client's `defaultError`, for queries whose endpoint has no `error` schema of its own: their `HttpError` bodies go to the browser encoded with it (`QueryClient.dehydrate` with `failures: "include"`), and it's shown as EndpointQuery.error. It's typed as the client's. Default: for a `Fetch.Service` class, the one it was declared with (`Api.config`); this option overrides it, as it must for a class whose `layer` builds its client from another config. A client behind a `Context.Service` key can't be read until its layer is built, so give it here. Without one, the client still decodes and types those bodies, but they go as JSON, so a query whose body isn't JSON isn't sent.                                                                                                                                                                                                                                                                                |
| `statusErrors?` | `SE`      | The client's `statusErrors`, so its queries can send those errors to the browser (`QueryClient.dehydrate` with `failures: "include"`). It's typed as the client's. Default: for a `Fetch.Service` class, the ones it was declared with (`Api.config`); this option overrides them. A client behind a `Context.Service` key can't be read until its layer is built, so give them here. Without them, the client's errors are still decoded and typed, but a query that fails with one isn't sent: the browser fetches it again.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `invalidates?`  | `"route"` | If `"route"`, a mutation that succeeds invalidates its route's queries, as Query.invalidate does: every query whose key starts with the route's EndpointQuery.key, the `key` prefix and the path's literals before its first param. `PATCH /todos/:id` invalidates `["todos"]`, so `GET /todos` and `GET /todos/:id` refetch, along with any other query under that key. A route with no param invalidates its whole path: `POST /todos/reorder` invalidates `["todos", "reorder"]`, which no list is keyed under, so give it an `invalidates` of its own. A route that starts with a param invalidates every query under `key`, or every query on the client without one. It invalidates more than a write changes, on purpose: a query refetched for nothing costs a request, and one left stale shows old data. A mutation's own `invalidates` replaces it, and `invalidates: []` turns it off for that mutation. Default: a mutation invalidates only what its `invalidates` says. |

### RegisteredSchema

A schema whose decoding and encoding need nothing outside your registered services (`Register["services"]`) and the client. The adapter accepts only these, so an endpoint whose schema needs another service is a compile error where its query or mutation is defined (`Endpoints.query`, `Endpoints.mutation`).

## Query keys

Guide: [Query keys](https://effetch-query.monarcode.dev/docs/queries/keys).

### EndpointQueryError

Thrown when a call's `query` can't be part of its key: it doesn't match the endpoint's `query` schema, a field encodes to an object, or a field is `Redacted`, whose secret the key would hold and send to the browser. Send a secret in a header instead. It's thrown when the query is made, such as `todos({ query })` in a component, before anything is fetched.

### KeyQuerySchema

A `query` schema an endpoint query can be keyed by: one whose encoding needs no services, since a key is encoded when the family is called, outside any Effect. `Endpoints.mutation` takes any query schema whose services are registered.

## Query errors

Guide: [Query errors](https://effetch-query.monarcode.dev/docs/queries/errors).

### ErrorSchema

The error schema a bound endpoint decodes error bodies with: its own, or the client's `defaultError` (see `EndpointsOptions.defaultError`).

## Errors by status

Guide: [Query errors](https://effetch-query.monarcode.dev/docs/queries/errors).

### RegisteredStatusErrors

A `statusErrors` map (`Fetch.StatusErrorMap`) whose schemas need nothing outside your registered services, as [`RegisteredSchema`](https://effetch-query.monarcode.dev/docs/reference/effetch#registeredschema). The adapter accepts only these, on the client and on each endpoint: its queries and mutations decode the errors, and its queries send them to the browser (the client's only when [`fromClient`](https://effetch-query.monarcode.dev/docs/reference/effetch#fromclient) has them, see `EndpointsOptions.statusErrors`).

## Queries from a stream

Guide: [Queries from a stream](https://effetch-query.monarcode.dev/docs/queries/streams).

### EndpointStreamOptions

Options for `Endpoints.query` with a stream endpoint (`stream: "sse"` or `"ndjson"`): a stream query's options ([`Query.StreamOptions`](https://effetch-query.monarcode.dev/docs/reference/query#streamoptions)), a `placeholder`, and the headers and plugin overrides `client.bind` takes (`Fetch.BindOptions`). `A` is the value, one element of the stream, and `Args` the call's arguments.

| Prop              | Type            | Description                                                                                                                                                                                                                 |
| ----------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `placeholder?`    | `function`      | A value to show for a query until its first element, from the call's `params` and `query`, as EndpointQueryOptions.placeholder. Default: none.                                                                              |
| `headers?`        | `union`         | Headers for every call, over the definition's. A call's own header wins.                                                                                                                                                    |
| `plugins?`        | `Overrides<Ps>` | Plugin overrides for every call. A call's own override wins.                                                                                                                                                                |
| `gcTime?`         | `union`         | The time a query nothing uses stays cached, as Options.gcTime. Default: 5 minutes.                                                                                                                                          |
| `retry?`          | `object`        | The schedule to resubscribe on after the stream fails, as `Stream.retry` takes it: the schedule starts over once an element comes through. Defects aren't retried. Default: the client's `queries.defaults.retry`, or none. |
| `retryOnMount?`   | `union`         | If true, a query whose stream failed subscribes again when something starts using it. Default: the client's `queries.defaults.retryOnMount`, or `true`.                                                                     |
| `reactivityKeys?` | `union`         | The `Reactivity` keys that resubscribe this query when invalidated, as Options.reactivityKeys. Default: none.                                                                                                               |

## Infinite queries

Guide: [Infinite queries](https://effetch-query.monarcode.dev/docs/queries/infinite).

### EndpointInfiniteQuery

A family of infinite queries, one per call of an Effetch endpoint, made by `Endpoints.infiniteQuery`. Call it with the endpoint's `params` and `query` to get the [`InfiniteQuery.InfiniteQuery`](https://effetch-query.monarcode.dev/docs/reference/infinite-query#infinitequery) for that call; a page field given there is ignored. Keys and matching are as for [`EndpointQuery`](https://effetch-query.monarcode.dev/docs/reference/effetch#endpointquery).

| Prop       | Type     | Description                                                                         |
| ---------- | -------- | ----------------------------------------------------------------------------------- |
| `key`      | `Key`    | The start every one of its keys has: the prefix and the path up to its first param. |
| `endpoint` | `object` | The endpoint definition it calls.                                                   |
| `error`    | `union`  | The schema error bodies are decoded with, as EndpointQuery.error.                   |

### EndpointInfiniteQueryOptions

Options for `Endpoints.infiniteQuery`: an infinite query's page options ([`InfiniteQuery.PageOptions`](https://effetch-query.monarcode.dev/docs/reference/infinite-query#pageoptions)) and query options ([`Query.Options`](https://effetch-query.monarcode.dev/docs/reference/query#options)), the query field each page's param is sent in, and the headers and plugin overrides `client.bind` takes (`Fetch.BindOptions`).

| Prop                  | Type                               | Description                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `reactivityKeys?`     | `union`                            | The `Reactivity` keys that refetch this query when invalidated, for Effect code that publishes them (Effect's SQL clients do). Run `Reactivity.invalidate` through the client, as QueryClient.QueryClient.runPromise does, to reach it. Default: none.                                                                                                                                            |
| `entities?`           | `object`                           | How this query takes part in the client's entity sync (QueryClient.EntitiesOptions.sync). Default: it does, if it has a `schema`.                                                                                                                                                                                                                                                                 |
| `pageParam`           | `EndpointPageField<QS, P>`         | The query field each page's param is sent in, such as `"cursor"` or `"skip"`. It's set on every page's request, over the call's own value, and left out of the key. The param must be a value a query field takes (`Fetch.QueryValue`), such as a string or a number. With a `query` schema on the endpoint, it's an optional field of the schema whose type takes the param (EndpointPageField). |
| `headers?`            | `union`                            | Headers for every call, over the definition's. A call's own header wins.                                                                                                                                                                                                                                                                                                                          |
| `plugins?`            | `Overrides<Ps>`                    | Plugin overrides for every call. A call's own override wins.                                                                                                                                                                                                                                                                                                                                      |
| `staleTime?`          | `union`                            | How long a success counts as fresh. Default: 0, stale at once.                                                                                                                                                                                                                                                                                                                                    |
| `retry?`              | `object`                           | Retries a failed fetch on this schedule, which gets each failure. Defects aren't retried. Default: no retries.                                                                                                                                                                                                                                                                                    |
| `refetchOnMount?`     | `union`                            | If true, refetches a stale query when a component starts using it. Default: `true`.                                                                                                                                                                                                                                                                                                               |
| `retryOnMount?`       | `union`                            | If true, refetches a failed query when a component starts using it, however recent the failure. A suspense reader (React's `useSuspenseQuery`) of a failure with no earlier value throws it to an error boundary instead, so it never starts using the query to retry it (see `useResetQueryFailure`). Default: `true`.                                                                           |
| `refetchOnFocus?`     | `union`                            | If true, refetches a stale query in use when the app regains focus (CommonOptions.signals). Default: `true`.                                                                                                                                                                                                                                                                                      |
| `refetchOnReconnect?` | `union`                            | If true, refetches a stale query in use when the device reconnects (CommonOptions.signals). Default: `true`.                                                                                                                                                                                                                                                                                      |
| `refetchInterval?`    | `union`                            | The interval at which a query in use refetches. A tick that finds a fetch in progress doesn't start another. Polling pauses while nothing uses the query and resumes when something starts using it. Default: no polling.                                                                                                                                                                         |
| `gcTime?`             | `union`                            | How long a query nothing uses stays cached. Default: 5 minutes. Like `reactivityKeys` and `entities`, it has no client-wide default.                                                                                                                                                                                                                                                              |
| `initialPageParam`    | `P`                                | The first page's param.                                                                                                                                                                                                                                                                                                                                                                           |
| `nextPageParam`       | `PageParamFunction<A, NoInfer<P>>` | The param of the page after the last one, or `undefined` / `null` for none.                                                                                                                                                                                                                                                                                                                       |
| `previousPageParam?`  | `PageParamFunction<A, NoInfer<P>>` | The param of the page before the first one, or `undefined` / `null` for none. Without it, there's no previous page.                                                                                                                                                                                                                                                                               |
| `maxPages?`           | `number`                           | The most pages to keep. Past it, a page is dropped from the far end: the first when a next page loads, the last when a previous page does. Give `previousPageParam` too, so the dropped pages can load again. Default: no limit.                                                                                                                                                                  |

### EndpointPageField

The query fields an infinite query's `EndpointInfiniteQueryOptions.pageParam` can name. The param `P` must be a `Fetch.QueryValue`, such as a string or a number, so pages cross to the browser as JSON. Without a `query` schema (`QS` is `undefined`), any field. With one, the schema's optional fields whose type takes `P` (`undefined` aside, for a first page with no cursor): optional, so a call can leave it out.

## Define a mutation

Guide: [Define a mutation](https://effetch-query.monarcode.dev/docs/mutations).

### EndpointMutationOptions

Options for `Endpoints.mutation`: a mutation's options ([`Mutation.MakeOptions`](https://effetch-query.monarcode.dev/docs/reference/mutation#makeoptions)) without `run`, which is the endpoint, and the headers and plugin overrides `client.bind` takes (`Fetch.BindOptions`).

| Prop           | Type            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `headers?`     | `union`         | Headers for every call, over the definition's. A call's own header wins.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `plugins?`     | `Overrides<Ps>` | Plugin overrides for every call. A call's own override wins.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `optimistic?`  | `function`      | Updates the cache before `run`, so the change shows at once. Its cache writes (Query.set, Query.update, and `Entity.update`, `set` and `remove`) are recorded, and if the run fails, the queries they wrote are put back, newest write first. A query written again in the meantime, even by a fetch, is put back all the same. Only writes made while it runs count: not those of a fiber it forks that write after it's done, nor those of a mutation it runs. A fetch of the same query already in progress still settles over the optimistic value, as it does over any Query.set, and there's no way to cancel it: the query then shows what that fetch returned.                                                                                                                                                                                           |
| `onSuccess?`   | `function`      | Runs after a successful `run`, before `invalidates`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `onFailure?`   | `function`      | Runs after a failed `run`, once the optimistic writes are rolled back.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `onSettled?`   | `function`      | Runs after `run` succeeds or fails, after `onSuccess` or `onFailure`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `invalidates?` | `union`         | Queries to invalidate after `onSuccess`, as Query.invalidate does: a list of targets, or a function of the run's value and variables that returns one. Default: none. A failed run invalidates nothing. A key that holds a query, a family or a group matches nothing: in a list, the run dies with a Query.KeyHoldsTargetError before it starts; from the function, the change is already saved, so the target is logged and skipped. Combine targets with Query.group.                                                                                                                                                                                                                                                                                                                                                                                         |
| `retry?`       | `object`        | Retries a failed run on this schedule, which gets each failure. Defects aren't retried. Default: no retries.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `concurrent?`  | `union`         | The policy for how one use's runs (one component's `useMutation`, say) overlap. Separate uses, and `Mutation.run` calls, never affect each other. Default: `true`. - `true`: runs overlap. - `false`: a new run interrupts the one in progress, whose optimistic writes are rolled back first. - `"queue"`: a new run waits until the ones before it have settled, so runs go one at a time, in order. A queued run counts as in progress (`useIsMutating`, `useMutationState`), but its `optimistic` runs when it starts, so a run that fails rolls back only its own writes. - `"drop"`: a new run is ignored while the one the use shows is in progress, such as a second click on a submit button. It never starts or calls anything, and its `run` resolves at once with an interrupted `Exit`. After `reset`, which stops showing a run, a new run starts. |

### EndpointVariables

What a mutation from route `R` takes when run: the endpoint's call options (`params`, `query`, `body`, `headers`, `plugins`), or nothing when none are required. The variables of `Endpoints.mutation`.

Without a `query` schema (`QS`), its `query` is a `Fetch.QueryInput`, which has an index signature: type a query object you pass with a `type` alias rather than an `interface`. With one, it's the schema's type.