QueryDefaults class Client

Query options that apply to many queries at once: client-wide through DefaultOptions.queries, or per key prefix through QueryClient.setQueryDefaults.

Every field is optional. When a query's options are resolved, each field the query's own options leave null is taken from the matching key defaults, then from the client-wide defaults, then from the built-in default named on each field below.

Defaults serve every data type under them, and Dart cannot express "options for any data type", so they carry the options that do not mention the data type, plus two that are worth erasing the type for: queryFn (a shared fetcher per key prefix is the single most useful default there is) and structuralSharing. The rest (initialData, select, placeholderData) belongs to a single query and is passed at the call site.

final client = QueryClient(
  defaultOptions: const DefaultOptions(
    queries: QueryDefaults(
      staleTime: StaleTime.duration(Duration(seconds: 30)),
      refetchOnWindowFocus: RefetchOn.never,
    ),
  ),
);
client.setQueryDefaults(
  QueryKey(['reports']),
  const QueryDefaults(gcTime: GcTime.never),
);
Annotations
  • @immutable

Constructors

QueryDefaults({QueryFn<Object?>? queryFn, Object? structuralSharing(Object? previous, Object? next)?, Enabled? enabled, StaleTime? staleTime, GcTime? gcTime, RetryPolicy? retry, RetryDelay? retryDelay, bool? retryOnMount, NetworkMode? networkMode, RefetchOn? refetchOnMount, RefetchOn? refetchOnWindowFocus, RefetchOn? refetchOnReconnect, RefetchInterval? refetchInterval, bool? refetchIntervalInBackground, Object? meta})
Creates a set of defaults; every field is optional, and an unset one defers to the next layer down (the client-wide defaults, then the built-in values).
const

Properties

enabled → Enabled?
Default for enabled: whether queries under this default fetch on their own. Built-in: Enabled.yes.
final
gcTime → GcTime?
Default for gcTime: how long an unobserved query stays in the cache. Built-in: GcTime.defaultValue, five minutes.
final
hashCode → int
The hash code for this object.
no setteroverride
meta → Object?
Default for meta: opaque data handed to the query function's context and readable off the query. No built-in default.
final
networkMode → NetworkMode?
Default for networkMode: when a fetch may run relative to the online state. Built-in: NetworkMode.online.
final
queryFn → QueryFn<Object?>?
A fetcher for every query this default covers, used when a query's own options set no queryFn. No built-in default.
final
refetchInterval → RefetchInterval?
Default for refetchInterval: how often to poll, if at all. Built-in: RefetchInterval.off.
final
refetchIntervalInBackground → bool?
Default for refetchIntervalInBackground: whether polling continues while the app is not in the foreground. Built-in: false.
final
refetchOnMount → RefetchOn?
Default for refetchOnMount: whether a subscribing observer refetches data it already has. Built-in: RefetchOn.ifStale.
final
refetchOnReconnect → RefetchOn?
Default for refetchOnReconnect: whether the device coming back online refetches. Built-in: RefetchOn.ifStale, or RefetchOn.never for a query under NetworkMode.always.
final
refetchOnWindowFocus → RefetchOn?
Default for refetchOnWindowFocus: whether the app returning to the foreground refetches. Built-in: RefetchOn.ifStale.
final
retry → RetryPolicy?
Default for retry: whether and how often a failed fetch is retried. Built-in: RetryPolicy.times(3) — except for QueryClient.query, which does not retry unless a retry is configured somewhere.
final
retryDelay → RetryDelay?
Default for retryDelay: the backoff between retries. Built-in: RetryDelay.defaultValue, 1 s doubling up to 30 s.
final
retryOnMount → bool?
Default for retryOnMount: whether a query in error state is retried when a new observer subscribes. true when unset here too.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
staleTime → StaleTime?
Default for staleTime: how long fetched data counts as fresh. Built-in: StaleTime.zero.
final
structuralSharing → Object? Function(Object? previous, Object? next)?
Default for structuralSharing: how new data is reconciled with the data already cached. Unset, replaceEqualDeep is used.
final

Methods

mergedWith(QueryDefaults? other) → QueryDefaults
These defaults with other's laid over them, field by field: a field other sets wins, one it leaves null falls through to this. null other returns this unchanged.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
override