Skip to Content
Effetch Query
Queries

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:

OptionDefaultWhat it does
staleTime0How long a value counts as fresh (a Duration.Input, such as "1 minute").
gcTime5 minutesHow long a query not in use keeps its value.
retryNo retriesA Schedule to retry failed fetches with. Defects aren't retried.
refetchOnMounttrueRefetch a stale query when a component starts using it.
retryOnMounttrueRefetch a failed query when a component starts using it.
refetchOnFocustrueRefetch stale queries in use when the app comes back into focus.
refetchOnReconnecttrueRefetch stale queries in use when the device comes back online.
refetchIntervalNo pollingRefetch on this interval while the query is in use.
reactivityKeysNoneAlso refetch when Effect code invalidates these Reactivity keys, as Effect's SQL clients do.
entitiesIn 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.
placeholderNoneA value to show until the query has one. See Show a placeholder.
liveNoneServer pushes that keep the value up to date. See Push updates into a query.
schemaNoneQuery.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, pluginsNoneapi.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, from staleTime to entities. It extends QueryClient.QueryDefaults, the options queries.defaults can set, and adds gcTime, reactivityKeys and entities, which only a query sets.
  • Query.MakeOptions<A, E>: Query.make's, with key, run, schema, placeholder and live. placeholder is an Effect and live a Stream.
  • Query.FamilyOptions<Args, A, E>: Query.family's, where run, placeholder and live are functions of the member's argument.
  • Query.Schema<A, E>: a success schema for the value and, to send failures too, an error schema. Pass the schemas themselves: each must encode to JSON and need no services.
  • EndpointQueryOptions: api.query's, from @monarcode/effetch-query/effetch. Its placeholder and live are functions of the call's params and query.

What's next

On this page