Query options
Every option a query takes.
api.query, Query.make and Query.family take the options on this
page. Query.make and Query.family also take key and run, as
Queries from any Effect shows. Stream
queries take a shorter list, given in
Queries from a stream, and
infinite queries add paging options, given in
Infinite queries.
Options
A query takes the following options:
| Option | Default | What it does |
|---|---|---|
staleTime | 0 | How long a value counts as fresh (a Duration.Input, such as "1 minute"). |
gcTime | 5 minutes | How long a query not in use keeps its value. |
retry | No retries | A Schedule to retry failed fetches with. Defects aren't retried. |
refetchOnMount | true | Refetch a stale query when a component starts using it. |
retryOnMount | true | Refetch a failed query when a component starts using it. |
refetchOnFocus | true | Refetch stale queries in use when the app comes back into focus. |
refetchOnReconnect | true | Refetch stale queries in use when the device comes back online. |
refetchInterval | No polling | Refetch on this interval while the query is in use. |
reactivityKeys | None | Also refetch when Effect code invalidates these Reactivity keys, as Effect's SQL clients do. |
entities | In sync, if the query has a schema | { sync: false } leaves the query out of the client's entity sync, which is off until the client lists entities to sync. See Keep copies in sync. |
placeholder | None | A value to show until the query has one. See Show a placeholder. |
live | None | Server pushes that keep the value up to date. See Push updates into a query. |
schema | None | Query.make and Query.family only: how the value crosses to the browser in server rendering, and how entities find records in it. An endpoint's output is its schema already. |
headers, plugins | None | api.query only: what Effetch's client.bind takes, for every call. |
The client's queries.defaults can change the defaults of staleTime,
retry, refetchOnMount, retryOnMount, refetchOnFocus,
refetchOnReconnect and refetchInterval. The rest are set per query.
See Defaults and app-wide hooks, and
Freshness and refetching for what "in use"
and the refetch options mean.
Option types
Each set of options has a named type. Use it when you define options apart from the query, such as a preset several queries share:
Query.Options<E>: the options every query takes, fromstaleTimetoentities. It extendsQueryClient.QueryDefaults, the optionsqueries.defaultscan set, and addsgcTime,reactivityKeysandentities, which only a query sets.Query.MakeOptions<A, E>:Query.make's, withkey,run,schema,placeholderandlive.placeholderis an Effect andliveaStream.Query.FamilyOptions<Args, A, E>:Query.family's, whererun,placeholderandliveare functions of the member's argument.Query.Schema<A, E>: asuccessschema for the value and, to send failures too, anerrorschema. Pass the schemas themselves: each must encode to JSON and need no services.EndpointQueryOptions:api.query's, from@monarcode/effetch-query/effetch. Itsplaceholderandliveare functions of the call'sparamsandquery.
What's next
- Freshness and refetching: when the refetch options apply.
- Defaults and app-wide hooks: set defaults for every query on the client.