Skip to content

raf-query is early. The API can still change between minor releases, so use it at your own risk.

raf-query

Guides

Plugins

Give a client its behaviors as plugins, set their per-query options in factories, give every queryFn a typed context, and bind the builders to the client that has them.

A client's behavior beyond caching comes from its plugins: retries, polling, refetching on focus, and whatever your app adds. A plugin declares the per-query options it reads and the context it gives every queryFn. A query takes those options, and its queryFn gets that context, on the clients that have the plugin.

The per-query behavior that recommended() turns on is set this way, in the query's factory:

import { 
const queryOptions: QueryOptionsBuilder<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchOnWindowFocus: boolean | undefined;
        readonly refetchOnReconnect: boolean | undefined;
        readonly refetchInterval: number | ... 1 more ... | undefined;
    };
}, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchOnWindowFocus: boolean | undefined;
        readonly refetchOnReconnect: boolean | undefined;
        readonly refetchInterval: number | ... 1 more ... | undefined;
    };
}>
queryOptions
} from "~/raf.ts";
export function
function postsQuery(input: {
    page: number;
    sort: "newest" | "oldest";
}): QueryOptions<readonly ["posts", "list", {
    page: number;
    sort: "newest" | "oldest";
}], readonly Post[], readonly Post[], {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        ...;
    };
}>
postsQuery
(
input: {
    page: number;
    sort: "newest" | "oldest";
}
input
: { page: numberpage: number; sort: "newest" | "oldest"sort: "newest" | "oldest" }) {
return
queryOptions<readonly ["posts", "list", {
    page: number;
    sort: "newest" | "oldest";
}], readonly Post[], readonly Post[]>(options: BaseOptions<readonly ["posts", "list", {
    page: number;
    sort: "newest" | "oldest";
}]> & Partial<{
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["posts", "list", {
        page: number;
        sort: "newest" | "oldest";
    }], {
        readonly "~options": {
            readonly retry: (value: number | false | undefined) => number | ... 1 more ... | undefined;
            readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
            readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
            readonly refetchInterval: (value: number | ... 1 more ... | undefined) => number | ... 1 more ... | undefined;
        };
        readonly context: {};
        readonly options: {
            ...;
        };
    }>) => Awaitable<...>;
    readonly select?: ((data: readonly Post[]) => readonly Post[]) | undefined;
}): QueryOptions<...> (+1 overload)
queryOptions
({
BaseOptions<readonly ["posts", "list", { page: number; sort: "newest" | "oldest"; }]>.queryKey: readonly ["posts", "list", {
    page: number;
    sort: "newest" | "oldest";
}]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
:
const posts: Group
<readonly ["list", {
    page: number;
    sort: "newest" | "oldest";
}]>(rest_0: "list", rest_1: {
    page: number;
    sort: "newest" | "oldest";
}) => readonly ["posts", "list", {
    page: number;
    sort: "newest" | "oldest";
}]
posts
("list",
input: {
    page: number;
    sort: "newest" | "oldest";
}
input
),
queryFn: (context: QueryFunctionContext<readonly ["posts", "list", {
    page: number;
    sort: "newest" | "oldest";
}], {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchOnWindowFocus: boolean | undefined;
        readonly refetchOnReconnect: boolean | undefined;
        readonly refetchInterval: number | ... 1 more ... | undefined;
    };
}>) => Awaitable<...>
queryFn
: () =>
function listPosts(input: {
    page: number;
    sort: "newest" | "oldest";
}): Promise<readonly Post[]>
listPosts
(
input: {
    page: number;
    sort: "newest" | "oldest";
}
input
),
// Options of `retry()` and `focusRefetch()`, which `recommended()` includes. retry?: number | false | undefinedretry: 1, refetchOnWindowFocus?: boolean | undefinedrefetchOnWindowFocus: false, }); }

This queryOptions comes from the app's raf.ts, which binds it to the client, so it takes the options of that client's plugins.

OptionDeclared byUse
retryretry()Attempts for this query, or false. See Retries
refetchIntervalpolling()Refetch every n ms while read. See Polling
refetchOnWindowFocusfocusRefetch()false opts out. See Window focus refetching
refetchOnReconnectreconnectRefetch()false opts out

Writing a plugin

plugin() makes a plugin. A plugin contributes any of four things, and each takes effect in its own place:

What a plugin has, and where each piece takes effect A plugin hasWhere it takes effect options declares the per-query options it reads queryOptions({ retry: 1, … }) a bound builder takes the option, typed context values for every queryFn queryFn: ({ api, signal }) => … the queryFn gets them, for the client or per request link wraps every request load → link → link → queryFn outermost first, in the order of the plugins array setup a cache-wide behavior <QueryClientProvider client={…}> started when a provider mounts the client; never on a server
What a plugin has, and where each piece takes effect.
PieceWhat it isWhere it takes effect
linkA function that wraps a requestAround every request the client makes, the queryFn innermost
setupA function that makes the plugin a featureAcross the cache, from when a provider mounts the client until it unmounts
contextAn object, or values its link adds per requestIn every queryFn of the client, beside client, queryKey and signal
declarationAn interface with options and contextIn the types: what factories and defaults can set, and what a queryFn gets

A plugin with no link, setup or context only declares options.

The declaration is plugin()'s type argument: an interface with the options the plugin reads and the context it gives. Both are optional. It types the link's op.options, and a plugin that declares a context has to give it.

A link gets the request as op and calls next(op) to run the rest of the chain, like a tRPC link. The last link is the query's own queryFn. op.options has the query's options, over the client's defaults, with the fields the plugin declares typed. retry() and timeout(ms) are plugins with a link.

import { function plugin<TDecl extends OptionsDecl = NoDecl>(definition?: PlainDefinition<NoInfer<TDecl>>): Plugin<NoInfer<TDecl>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
} from "@raf-query/react";
interface ErrorToasts { readonly
ErrorToasts.options: {
    readonly errorMessage?: string;
}
options
: { readonly errorMessage?: string | undefinederrorMessage?: string };
} // One toast per failed request, with the query's own message. const const errorToasts: Plugin<NoInfer<ErrorToasts>>errorToasts = plugin<ErrorToasts>(definition?: PlainDefinition<NoInfer<ErrorToasts>> | undefined): Plugin<NoInfer<ErrorToasts>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
<ErrorToasts>({
PlainDefinition<NoInfer<ErrorToasts>>.link?: LinkOf<NoInfer<ErrorToasts>, Operation<NoInfer<ErrorToasts>>> | undefined

Wraps every request, like a tRPC link. Call next(op) to run the rest of the chain; the last link is the query's own queryFn.

link
: async (op: Operation<NoInfer<ErrorToasts>>op, next: (op: Operation<NoInfer<ErrorToasts>>) => Promise<unknown>next) => {
try { return await next: (op: Operation<NoInfer<ErrorToasts>>) => Promise<unknown>next(op: Operation<NoInfer<ErrorToasts>>op); } catch (function (local var) error: unknownerror) {
const toast: {
    error(message: string): void;
}
toast
.function error(message: string): voiderror(op: Operation<NoInfer<ErrorToasts>>op.
Operation<NoInfer<ErrorToasts>>.options: Partial<{
    readonly errorMessage?: string;
}> & QueryOptions<QueryKey, unknown, unknown, RootTypes>

The query's options, over the client's defaults.

options
.errorMessage?: string | undefinederrorMessage ?? "Something went wrong");
throw function (local var) error: unknownerror; } }, });

A feature

setup(client, signal) runs when a provider mounts the client, and signal aborts when the last provider of that client unmounts. So a feature runs once however many providers share the client, and never during a server render. focusRefetch(), reconnectRefetch() and polling() are features. This one listens to the server with an EventSource:

import { function invalidateAll(client: QueryClient): Promise<void>

Mark every query stale; read ones refetch. For sign-out, or after any write.

invalidateAll
} from "@raf-query/react";
// Refetches what's on screen when the server says something changed. const const liveUpdates: Plugin<NoInfer<NoDecl>>liveUpdates = plugin<NoDecl>(definition?: PlainDefinition<NoInfer<NoDecl>> | undefined): Plugin<NoInfer<NoDecl>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
({
PluginSetup<NoInfer<NoDecl>>.setup?: ((client: QueryClient<{
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>, signal: AbortSignal) => void) | undefined

A cache-wide behavior, started when a provider mounts the client and stopped by signal. The client is typed with this plugin, so it runs the factories of a builder bound to it.

setup
: (
client: QueryClient<{
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>
client
, signal: AbortSignalsignal) => {
const const events: EventSourceevents = new var EventSource: new (url: string | URL, eventSourceInitDict?: EventSourceInit) => EventSource

The EventSource interface is web content's interface to server-sent events.

EventSource
("/api/events");
const events: EventSourceevents.EventSource.addEventListener<"message">(type: "message", listener: (this: EventSource, ev: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void (+2 overloads)

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

addEventListener
("message", () => void function invalidateAll(client: QueryClient): Promise<void>

Mark every query stale; read ones refetch. For sign-out, or after any write.

invalidateAll
(
client: QueryClient<{
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>
client
));
signal: AbortSignalsignal.AbortSignal.addEventListener<"abort">(type: "abort", listener: (this: AbortSignal, ev: Event) => any, options?: boolean | AddEventListenerOptions): void (+1 overload)

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

addEventListener
("abort", () => const events: EventSourceevents.EventSource.close(): void

The close() method of the EventSource interface closes the connection, if one is made, and sets the EventSource.readyState attribute to 2 (closed).

close
());
}, });

Context for every queryFn

A plugin's context is merged into the context of every queryFn the client runs, beside client, queryKey and signal. The declaration names its fields:

interface Api {
	readonly 
Api.context: {
    readonly api: ApiClient;
}
context
: { readonly api: ApiClientapi: ApiClient };
} // A function, so each client is given its own API client. const const api: (apiClient: ApiClient) => Plugin<NoInfer<Api>>api = (apiClient: ApiClientapiClient: ApiClient) => plugin<Api>(definition: ClientContextDefinition<NoInfer<Api>>): Plugin<NoInfer<Api>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
<Api>({
ClientContextDefinition<NoInfer<Api>>.context: {
    readonly api: ApiClient;
}

Merged into the context of every queryFn the client runs.

context
: { api: ApiClientapi: apiClient: ApiClientapiClient } });

A server makes one client per request, so a client's context belongs to that request: an API client that sends the request's cookies, a database reader for the signed-in user.

In a factory built with the queryOptions bound to that client, the queryFn gets api, typed:

export function 
function postQuery(input: {
    slug: string;
}): QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
postQuery
(
input: {
    slug: string;
}
input
: { slug: stringslug: string }) {
return
const queryOptions: QueryOptionsBuilder
<readonly ["posts", "bySlug", string], Post, Post>(options: BaseOptions<readonly ["posts", "bySlug", string]> & Partial<{
    readonly errorMessage: string | undefined;
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
    readonly owner: "editorial" | "community" | undefined;
}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["posts", "bySlug", string], {
        readonly "~options": {
            readonly errorMessage: (value: string | undefined) => string | undefined;
            ... 4 more ...;
            readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
        };
        readonly context: {
            ...;
        };
        readonly options: {
            ...;
        };
    }>) => Awaitable<...>;
    readonly select?: ((data: Post) => Post) | undefined;
}) => QueryOptions<...> (+1 overload)
queryOptions
({
BaseOptions<readonly ["posts", "bySlug", string]>.queryKey: readonly ["posts", "bySlug", string]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
: posts<readonly ["bySlug", string]>(rest_0: "bySlug", rest_1: string): readonly ["posts", "bySlug", string]posts("bySlug",
input: {
    slug: string;
}
input
.slug: stringslug),
queryFn: (context: QueryFunctionContext<readonly ["posts", "bySlug", string], {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>) => Awaitable<...>
queryFn
: ({ api: ApiClientapi, signal: AbortSignal

Aborted when the request is restarted or its entry is removed.

signal
}) => api: ApiClientapi.
ApiClient.getPost(slug: string, init: {
    signal: AbortSignal;
}): Promise<Post>
getPost
(
input: {
    slug: string;
}
input
.slug: stringslug, { signal: AbortSignalsignal }),
}); }

Context per request

A plugin can also give its context from its link, for values that belong to one request: a token that may need refreshing, a trace id. The link passes next an operation with the context it adds for the queryFn and the links after it. It goes over what the plugins before it gave (op.context), so a link can add a field or replace one, and the fields it leaves out stay:

import { function plugin<TDecl extends OptionsDecl = NoDecl>(definition?: PlainDefinition<NoInfer<TDecl>>): Plugin<NoInfer<TDecl>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
} from "@raf-query/react";
interface Session { readonly
Session.context: {
    readonly token: string;
}
context
: { readonly token: stringtoken: string };
} // No `context` here: the link gives it, to every request. const const session: Plugin<NoInfer<Session>>session = plugin<Session>(definition: RequestContextDefinition<NoInfer<Session>>): Plugin<NoInfer<Session>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
<Session>({
RequestContextDefinition<NoInfer<Session>>.link: LinkOf<NoInfer<Session>, Operation<NoInfer<Session>> & {
    readonly context: {
        readonly token: string;
    };
}>

Wraps every request, and gives each the context the plugin declares: next takes an operation whose context has it.

link
: async (op: Operation<NoInfer<Session>>op,
next: (op: Operation<NoInfer<Session>> & {
    readonly context: {
        readonly token: string;
    };
}) => Promise<unknown>
next
) =>
next: (op: Operation<NoInfer<Session>> & {
    readonly context: {
        readonly token: string;
    };
}) => Promise<unknown>
next
({ ...op: Operation<NoInfer<Session>>op,
context: Partial<{
    readonly token: string;
}> & {
    readonly token: string;
}

What the queryFn gets beside the client, key and signal: the plugins' context, as the links before this one left it. Pass next an operation with a context to add to it, or to replace a field of it, for this request: the fields it leaves out stay.

context
: { ...op: Operation<NoInfer<Session>>op.
Operation<NoInfer<Session>>.context: Partial<{
    readonly token: string;
}>

What the queryFn gets beside the client, key and signal: the plugins' context, as the links before this one left it. Pass next an operation with a context to add to it, or to replace a field of it, for this request: the fields it leaves out stay.

context
, token: stringtoken: await function freshToken(): Promise<string>freshToken() } }),
});

The declaration is the same, so a factory reads token the same way:

import { function bindQueryOptions<T = NoDecl>(): QueryOptionsBuilder<RootOf<T>, SetsOf<T>>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
,
function createQueryClient<const TPlugins extends ReadonlyArray<AnyPlugin> = []>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<RootOfPlugins<TPlugins>["options"]>>;
    readonly plugins?: TPlugins;
}): QueryClient<RootOfPlugins<TPlugins>>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
} from "@raf-query/react";
const
const makeQueryClient: () => QueryClient<{
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>
makeQueryClient
= () =>
createQueryClient<readonly [Plugin<NoInfer<Session>>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{}>> | undefined;
    readonly plugins?: readonly [Plugin<NoInfer<Session>>] | undefined;
}): QueryClient<{
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({ plugins?: readonly [Plugin<NoInfer<Session>>] | undefinedplugins: [const session: Plugin<NoInfer<Session>>session] });
const
const queryOptions: QueryOptionsBuilder<{
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}, {
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>
queryOptions
=
bindQueryOptions<() => QueryClient<{
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>>(): QueryOptionsBuilder<{
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}, {
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
<typeof
const makeQueryClient: () => QueryClient<{
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>
makeQueryClient
>();
export function
function draftsQuery(): QueryOptions<readonly ["posts", "drafts"], readonly string[], readonly string[], {
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>
draftsQuery
() {
return
const queryOptions: QueryOptionsBuilder
<readonly ["posts", "drafts"], readonly string[], readonly string[]>(options: BaseOptions<readonly ["posts", "drafts"]> & Partial<{}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["posts", "drafts"], {
        readonly "~options": {};
        readonly context: {
            readonly token: string;
        };
        readonly options: {};
    }>) => Awaitable<readonly string[]>;
    readonly select?: ((data: readonly string[]) => readonly string[]) | undefined;
}) => QueryOptions<readonly ["posts", "drafts"], readonly string[], readonly string[], {
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}> (+1 overload)
queryOptions
({
BaseOptions<readonly ["posts", "drafts"]>.queryKey: readonly ["posts", "drafts"]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
: posts<readonly ["drafts"]>(rest_0: "drafts"): readonly ["posts", "drafts"]posts("drafts"),
queryFn: (context: QueryFunctionContext<readonly ["posts", "drafts"], {
    readonly "~options": {};
    readonly context: {
        readonly token: string;
    };
    readonly options: {};
}>) => Awaitable<readonly string[]>
queryFn
: ({ token: stringtoken, signal: AbortSignal

Aborted when the request is restarted or its entry is removed.

signal
}) =>
function getDrafts(token: string, init: {
    signal: AbortSignal;
}): Promise<ReadonlyArray<string>>
getDrafts
(token: stringtoken, { signal: AbortSignalsignal }),
}); }

A plugin that declares a context gives it one of the two ways. With no context, its link's next only takes an operation that has the declared fields, so this is a type error:

plugin<Session>(definition: RequestContextDefinition<NoInfer<Session>>): Plugin<NoInfer<Session>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
<Session>({
RequestContextDefinition<NoInfer<Session>>.link: LinkOf<NoInfer<Session>, Operation<NoInfer<Session>> & {
    readonly context: {
        readonly token: string;
    };
}>

Wraps every request, and gives each the context the plugin declares: next takes an operation whose context has it.

link
: (op: Operation<NoInfer<Session>>op,
next: (op: Operation<NoInfer<Session>> & {
    readonly context: {
        readonly token: string;
    };
}) => Promise<unknown>
next
) =>
next: (op: Operation<NoInfer<Session>> & {
    readonly context: {
        readonly token: string;
    };
}) => Promise<unknown>
next
(op) });
Argument of type 'Operation<NoInfer<Session>>' is not assignable to parameter of type 'Operation<NoInfer<Session>> & { readonly context: { readonly token: string; }; }'. Type 'Operation<NoInfer<Session>>' is not assignable to type '{ readonly context: { readonly token: string; }; }'. The types of 'context.token' are incompatible between these types. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.

A link can replace a field another plugin gave the client, too, for the one request. A paged query's pages are one request: they share its context.

Options only

A plugin without a link, a setup or a context does nothing at runtime. It declares options: your app's own facts about a query, for targets to match on. Tags are built this way.

export interface Ownership {
	readonly 
Ownership.options: {
    readonly owner?: "editorial" | "community";
}
options
: { readonly owner?: "editorial" | "community" | undefinedowner?: "editorial" | "community" };
} // No link, setup or context: it only declares `owner`. const const ownership: Plugin<NoInfer<Ownership>>ownership = plugin<Ownership>(definition?: PlainDefinition<NoInfer<Ownership>> | undefined): Plugin<NoInfer<Ownership>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
<Ownership>();

The client's plugins

createQueryClient takes the plugins as one array. recommended() returns an array of plugins, so spread it among your own:

import { 
function createQueryClient<const TPlugins extends ReadonlyArray<AnyPlugin> = []>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<RootOfPlugins<TPlugins>["options"]>>;
    readonly plugins?: TPlugins;
}): QueryClient<RootOfPlugins<TPlugins>>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
, function recommended(): Recommended

The behaviors most apps want: retries, refetching on focus and reconnect, and polling. Pass it as the client's plugins, or spread it among your own:

recommended
} from "@raf-query/react";
export function
function makeQueryClient(apiClient: ApiClient): QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
makeQueryClient
(apiClient: ApiClientapiClient: ApiClient) {
return
createQueryClient<readonly [Plugin<NoInfer<ErrorToasts>>, Plugin<Retry>, Plugin<FocusRefetch>, Plugin<ReconnectRefetch>, Plugin<Polling>, Plugin<NoInfer<NoDecl>>, Plugin<NoInfer<Api>>, Plugin<NoInfer<Ownership>>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
        ...;
    }>> | undefined;
    readonly plugins?: readonly [...] | undefined;
}): QueryClient<...>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({
plugins?: readonly [Plugin<NoInfer<ErrorToasts>>, Plugin<Retry>, Plugin<FocusRefetch>, Plugin<ReconnectRefetch>, Plugin<Polling>, Plugin<NoInfer<NoDecl>>, Plugin<NoInfer<Api>>, Plugin<NoInfer<Ownership>>] | undefinedplugins: [ const errorToasts: Plugin<NoInfer<ErrorToasts>>errorToasts, ...function recommended(): Recommended

The behaviors most apps want: retries, refetching on focus and reconnect, and polling. Pass it as the client's plugins, or spread it among your own:

recommended
(),
const liveUpdates: Plugin<NoInfer<NoDecl>>liveUpdates, const api: (apiClient: ApiClient) => Plugin<NoInfer<Api>>api(apiClient: ApiClientapiClient), const ownership: Plugin<NoInfer<Ownership>>ownership, ], }); }

Links wrap each request in array order, outermost first: errorToasts comes before retry(), so it sees a request's error only after its retries ran out. Order matters for links only, unless two plugins give the same context field: then the later plugin's wins.

A package that ships a plugin needs only these exports: plugin, the types Plugin and Operation (the request a link gets) to name what it returns and takes, and Target and QueryInfo for a target that matches on the options it declares.

Typing options by the client

A client's plugins decide what its queries can set and what their queryFns get, so a builder always belongs to a client. @raf-query/react exports no queryOptions of its own: it exports binders, and an app binds its builders to its client once, in a file of their own. Every factory imports them from there:

src/raf.ts
import {
	function bindInfiniteQueryOptions<T = NoDecl>(): InfiniteQueryOptionsBuilder<RootOf<T>, SetsOf<T>>

Makes infiniteQueryOptions, the builder of a paged query factory's options, bound like bindQueryOptions. Bind it next to queryOptions, in apps that page:

bindInfiniteQueryOptions
,
function bindQueryOptions<T = NoDecl>(): QueryOptionsBuilder<RootOf<T>, SetsOf<T>>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
,
function bindUseQueryClient<T>(): () => QueryClient<RootOf<T>>

useQueryClient typed with a root, so verbs called with the client it returns check factories and targets against that root. T is the client's type, or the type of a function that makes it. Bind once per app:

bindUseQueryClient
,
} from "@raf-query/react"; // `makeQueryClient` is the function above, imported with `import type`. type
type Client = (apiClient: ApiClient) => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
Client
= typeof
function makeQueryClient(apiClient: ApiClient): QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
makeQueryClient
;
export const
const queryOptions: QueryOptionsBuilder<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
queryOptions
=
bindQueryOptions<(apiClient: ApiClient) => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>>(): QueryOptionsBuilder<...>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
<
type Client = (apiClient: ApiClient) => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
Client
>();
export const
const useQueryClient: () => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
useQueryClient
=
bindUseQueryClient<(apiClient: ApiClient) => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>>(): () => QueryClient<...>

useQueryClient typed with a root, so verbs called with the client it returns check factories and targets against that root. T is the client's type, or the type of a function that makes it. Bind once per app:

bindUseQueryClient
<
type Client = (apiClient: ApiClient) => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
Client
>();
// Only in an app that pages: export const
const infiniteQueryOptions: InfiniteQueryOptionsBuilder<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
infiniteQueryOptions
=
bindInfiniteQueryOptions<(apiClient: ApiClient) => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>>(): InfiniteQueryOptionsBuilder<...>

Makes infiniteQueryOptions, the builder of a paged query factory's options, bound like bindQueryOptions. Bind it next to queryOptions, in apps that page:

bindInfiniteQueryOptions
<
type Client = (apiClient: ApiClient) => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
Client
>();
How a builder is bound, in an app and in a library, and which clients run its factories In an app makeQueryClient() plugins: [retry(), api(), ownership] bindQueryOptions<typeof makeQueryClient>() in raf.ts, once per client postQuery may set retry and owner; its queryFn gets api runs on a client with all three not on a client made without api() In a library interface Convex { context: … } the declaration of the library's plugin bindQueryOptions<Convex & Optional<Retry>>() names the plugins its factories need convexQuery(ref) its queryFn gets convex; sets retry where there is one runs on any client with convex() with or without retry()
A builder is bound to a client in an app, or to plugin declarations in a library. Its factories run on the clients that have those plugins.

The types flow one way. The client factory lists the plugins, the binders read that list from the factory's type, the builders they return type every factory, and a factory then runs on the clients that have those plugins.

Each binder takes the type of the function that makes the client, or of the client. Only the type is read, so import type is enough and the factories don't import the client. A binder returns the plain builder, typed for the client: binding costs a few bytes, and an app that doesn't page leaves out bindInfiniteQueryOptions and ships none of the paging code.

Factories built with the bound builders never name the client:

export function 
function commentsQuery(input: {
    slug: string;
}): InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "community" | ... 1 more ... | undefined) => "community" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
commentsQuery
(
input: {
    slug: string;
}
input
: { slug: stringslug: string }) {
return
const infiniteQueryOptions: InfiniteQueryOptionsBuilder
<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>>(options: InfiniteOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>> & Partial<{
    readonly errorMessage: string | undefined;
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
    readonly owner: "community" | ... 1 more ... | undefined;
}> & {
    ...;
}) => InfiniteQueryOptions<...>
infiniteQueryOptions
({
BaseOptions<readonly ["posts", "comments", string]>.queryKey: readonly ["posts", "comments", string]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
: comments<readonly [string]>(rest_0: string): readonly ["posts", "comments", string]comments(
input: {
    slug: string;
}
input
.slug: stringslug),
// `api` is the context the `api()` plugin gives
queryFn: (context: InfiniteQueryFunctionContext<readonly ["posts", "comments", string], number, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "community" | "editorial" | undefined) => "community" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>) => CommentPage | PromiseLike<...>
queryFn
: ({ api: ApiClientapi, pageParam: numberpageParam, signal: AbortSignal

Aborted when the request is restarted or its entry is removed.

signal
}) =>
api: ApiClientapi.
ApiClient.listComments(input: {
    cursor: number;
    slug: string;
}, init: {
    signal: AbortSignal;
}): Promise<CommentPage>
listComments
({ cursor: numbercursor: pageParam: numberpageParam, slug: stringslug:
input: {
    slug: string;
}
input
.slug: stringslug }, { signal: AbortSignalsignal }),
InfiniteOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>>.initialPageParam: numberinitialPageParam: 0, InfiniteOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>>.getNextPageParam: PageParamFn<CommentPage, number>getNextPageParam: (lastPage: CommentPagelastPage) => lastPage: CommentPagelastPage.CommentPage.nextCursor: number | nullnextCursor, // Options the client's plugins declare errorMessage?: string | undefinederrorMessage: "Couldn't load the comments", owner?: "community" | "editorial" | undefinedowner: "community", retry?: number | false | undefinedretry: 1, }); }
  • They take the options the client's plugins declare, with their types. Anything else is a type error:
queryOptions({ BaseOptions<readonly ["account", "me"]>.queryKey: readonly ["account", "me"]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
: account<readonly ["me"]>(rest_0: "me"): readonly ["account", "me"]account("me"),
queryFn: (context: QueryFunctionContext<readonly ["account", "me"], {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>) => AsyncIterable<...>
queryFn
: function getMe(): Promise<User | null>

null when signed out.

getMe
, cacheFor: numbercacheFor: 60_000 });
No overload matches this call. Overload 1 of 2, '(options: BaseOptions<readonly ["account", "me"]> & Partial<{ readonly errorMessage: string | undefined; readonly retry: number | false | undefined; readonly refetchOnWindowFocus: boolean | undefined; readonly refetchOnReconnect: boolean | undefined; readonly refetchInterval: number | ... 1 more ... | undefined; readonly owner: "community" | ... 1 more ... | undefined; }> & { ...; }): QueryOptions<...>', gave the following error. Type '() => Promise<User | null>' is not assignable to type '(context: QueryFunctionContext<readonly ["account", "me"], { readonly "~options": { readonly errorMessage: (value: string | undefined) => string | undefined; readonly retry: (value: number | false | undefined) => number | false | undefined; readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | und...'. Property '[Symbol.asyncIterator]' is missing in type 'Promise<User | null>' but required in type 'AsyncIterable<unknown>'. Overload 2 of 2, '(options: BaseOptions<readonly ["account", "me"]> & Partial<{ readonly errorMessage: string | undefined; readonly retry: number | false | undefined; readonly refetchOnWindowFocus: boolean | undefined; readonly refetchOnReconnect: boolean | undefined; readonly refetchInterval: number | ... 1 more ... | undefined; readonly owner: "community" | ... 1 more ... | undefined; }> & { ...; }): QueryOptions<...>', gave the following error. Object literal may only specify known properties, and 'cacheFor' does not exist in type 'BaseOptions<readonly ["account", "me"]> & Partial<{ readonly errorMessage: string | undefined; readonly retry: number | false | undefined; readonly refetchOnWindowFocus: boolean | undefined; readonly refetchOnReconnect: boolean | undefined; readonly refetchInterval: number | ... 1 more ... | undefined; readonly owne...'.
  • Their queryFn gets the context the client's plugins give.
  • Verbs such as invalidateMany and setData, and load for each of its entries, take them only with a client that has those plugins. The bound useQueryClient returns the app's client, so verbs called in components take the app's factories:
import { function invalidateMany<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, partial?: PartialInput<TFactory>): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
} from "@raf-query/react";
export function
function RefreshComments(props: {
    slug: string;
}): React.JSX.Element
RefreshComments
(
props: {
    slug: string;
}
props
: { slug: stringslug: string }) {
const
const client: QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
client
=
const useQueryClient: () => QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
useQueryClient
();
return ( <React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button React.DOMAttributes<HTMLButtonElement>.onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonClick={() =>
invalidateMany<(input: {
    slug: string;
}) => InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>>(client: ClientFor<...>, factory: (input: {
    slug: string;
}) => InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>, partial?: {
    ...;
} | undefined): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(
const client: QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
client
,
function commentsQuery(input: {
    slug: string;
}): InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
commentsQuery
,
props: {
    slug: string;
}
props
)}
React.ButtonHTMLAttributes<HTMLButtonElement>.type?: "button" | "submit" | "reset" | undefinedtype="button" > Refresh </React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button> ); }

The bare QueryClient type stands for any client, whatever its plugins. Verbs and load given one take the factories and targets that need no plugin, and reject the rest. The useQueryClient that @raf-query/react exports returns that type, which is why components get the client from the bound one. Wherever your app names its client's type, write ReturnType<typeof makeQueryClient>: TanStack Router's router context, a React Router context, a helper's parameter. ClientFor<typeof factory> is any client that runs that factory:

import type { type ClientFor<TFactory extends QueryFactory> = QueryClient<RootOfFactory<TFactory>>

The clients a factory runs on: those with the plugins its builder is bound to, or any client for a factory from an unbound builder.

ClientFor
} from "@raf-query/react";
// The app's client type
type AppQueryClient = QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
AppQueryClient
= type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any

Obtain the return type of a function type

ReturnType
<typeof
function makeQueryClient(apiClient: ApiClient): QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
makeQueryClient
>;
// Any client that can run `commentsQuery` type
type CommentsClient = QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
CommentsClient
= type ClientFor<TFactory extends QueryFactory> = QueryClient<RootOfFactory<TFactory>>

The clients a factory runs on: those with the plugins its builder is bound to, or any client for a factory from an unbound builder.

ClientFor
<typeof
function commentsQuery(input: {
    slug: string;
}): InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
commentsQuery
>;
export function function refreshComments(client: CommentsClient, slug: string): Promise<void>refreshComments(client: CommentsClientclient:
type CommentsClient = QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
CommentsClient
, slug: stringslug: string) {
return
invalidateMany<(input: {
    slug: string;
}) => InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>>(client: ClientFor<...>, factory: (input: {
    slug: string;
}) => InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>, partial?: {
    ...;
} | undefined): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(client: CommentsClientclient,
function commentsQuery(input: {
    slug: string;
}): InfiniteQueryOptions<readonly ["posts", "comments", string], CommentPage, number, InfiniteData<CommentPage, number>, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
commentsQuery
, { slug?: string | undefinedslug });
}

A binder takes the type of a function, not of a client at module level, because a server makes one client per request. It's the same idea as a tRPC v12 client typing its call options from its links.

Several clients

Nothing is registered globally, so a program can have several clients with different plugins. A client runs a factory when it has at least the plugins the factory's builder is bound to. Bind a builder to one client for the factories only it runs, and to the plugins several clients share, named by their declarations, for the factories they all run. Retry, Polling, FocusRefetch and ReconnectRefetch are the declarations of the built-in plugins; intersect them to name more than one (Retry & Polling).

import {
	function bindQueryOptions<T = NoDecl>(): QueryOptionsBuilder<RootOf<T>, SetsOf<T>>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
,
function createQueryClient<const TPlugins extends ReadonlyArray<AnyPlugin> = []>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<RootOfPlugins<TPlugins>["options"]>>;
    readonly plugins?: TPlugins;
}): QueryClient<RootOfPlugins<TPlugins>>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
,
function polling(): Plugin<Polling>

Refetch read queries every refetchInterval ms.

polling
,
type Retry, function retry(options?: RetryOptions): Plugin<Retry>

Retry failed requests. Thrown Responses (router redirects and not-founds) and cancelled requests aren't retried, server clients never retry, and a browser that is offline waits until it's back online before retrying. A query sets its own attempts with retry.

retry
,
} from "@raf-query/react"; // The site retries and polls; the embeddable widget only retries. export const
const makeSiteClient: () => QueryClient<{
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>
makeSiteClient
= () =>
createQueryClient<readonly [Plugin<Retry>, Plugin<Polling>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    }>> | undefined;
    readonly plugins?: readonly [Plugin<Retry>, Plugin<Polling>] | undefined;
}): QueryClient<{
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly retry: (value: number | ... 1 more ... | undefined) => number | ... 1 more ... | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({ plugins?: readonly [Plugin<Retry>, Plugin<Polling>] | undefinedplugins: [function retry(options?: RetryOptions): Plugin<Retry>

Retry failed requests. Thrown Responses (router redirects and not-founds) and cancelled requests aren't retried, server clients never retry, and a browser that is offline waits until it's back online before retrying. A query sets its own attempts with retry.

retry
(), function polling(): Plugin<Polling>

Refetch read queries every refetchInterval ms.

polling
()] });
export const
const makeWidgetClient: () => QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
makeWidgetClient
= () =>
createQueryClient<readonly [Plugin<Retry>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
        readonly retry: number | false | undefined;
    }>> | undefined;
    readonly plugins?: readonly [Plugin<Retry>] | undefined;
}): QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({ plugins?: readonly [Plugin<Retry>] | undefinedplugins: [function retry(options?: RetryOptions): Plugin<Retry>

Retry failed requests. Thrown Responses (router redirects and not-founds) and cancelled requests aren't retried, server clients never retry, and a browser that is offline waits until it's back online before retrying. A query sets its own attempts with retry.

retry
()] });
// Bound to the site's client: its factories need `retry()` and `polling()`. const
const siteQueryOptions: QueryOptionsBuilder<{
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}, {
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>
siteQueryOptions
=
bindQueryOptions<() => QueryClient<{
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>>(): QueryOptionsBuilder<{
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}, {
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
<typeof
const makeSiteClient: () => QueryClient<{
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>
makeSiteClient
>();
// Bound to the plugin both clients have: its factories run on either. const
const sharedQueryOptions: QueryOptionsBuilder<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
sharedQueryOptions
=
bindQueryOptions<Retry>(): QueryOptionsBuilder<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
<Retry>();
export function
function postViewsQuery(input: {
    slug: string;
}): QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>
postViewsQuery
(
input: {
    slug: string;
}
input
: { slug: stringslug: string }) {
return
const siteQueryOptions: QueryOptionsBuilder
<readonly ["posts", "views", string], number, number>(options: BaseOptions<readonly ["posts", "views", string]> & Partial<{
    readonly refetchInterval: number | false | undefined;
    readonly retry: number | false | undefined;
}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["posts", "views", string], {
        readonly "~options": {
            readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
            readonly retry: (value: number | false | undefined) => number | false | undefined;
        };
        readonly context: {};
        readonly options: {
            readonly refetchInterval: number | false | undefined;
            readonly retry: number | ... 1 more ... | undefined;
        };
    }>) => Awaitable<...>;
    readonly select?: ((data: number) => number) | undefined;
}) => QueryOptions<...> (+1 overload)
siteQueryOptions
({
BaseOptions<readonly ["posts", "views", string]>.queryKey: readonly ["posts", "views", string]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
: posts<readonly ["views", string]>(rest_0: "views", rest_1: string): readonly ["posts", "views", string]posts("views",
input: {
    slug: string;
}
input
.slug: stringslug),
queryFn: (context: QueryFunctionContext<readonly ["posts", "views", string], {
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
        readonly retry: number | false | undefined;
    };
}>) => Awaitable<number>
queryFn
: () => function getPostViews(slug: string): Promise<number>getPostViews(
input: {
    slug: string;
}
input
.slug: stringslug),
refetchInterval?: number | false | undefinedrefetchInterval: 2000, }); } export function
function postQuery(input: {
    slug: string;
}): QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
postQuery
(
input: {
    slug: string;
}
input
: { slug: stringslug: string }) {
return
const sharedQueryOptions: QueryOptionsBuilder
<readonly ["posts", "bySlug", string], Post, Post>(options: BaseOptions<readonly ["posts", "bySlug", string]> & Partial<{
    readonly retry: number | false | undefined;
}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["posts", "bySlug", string], {
        readonly "~options": {
            readonly retry: (value: number | false | undefined) => number | false | undefined;
        };
        readonly context: {};
        readonly options: {
            readonly retry: number | false | undefined;
        };
    }>) => Awaitable<Post>;
    readonly select?: ((data: Post) => Post) | undefined;
}) => QueryOptions<...> (+1 overload)
sharedQueryOptions
({
BaseOptions<readonly ["posts", "bySlug", string]>.queryKey: readonly ["posts", "bySlug", string]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
: posts<readonly ["bySlug", string]>(rest_0: "bySlug", rest_1: string): readonly ["posts", "bySlug", string]posts("bySlug",
input: {
    slug: string;
}
input
.slug: stringslug),
queryFn: (context: QueryFunctionContext<readonly ["posts", "bySlug", string], {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>) => Awaitable<Post>
queryFn
: () => function getPost(slug: string): Promise<Post>getPost(
input: {
    slug: string;
}
input
.slug: stringslug),
retry?: number | false | undefinedretry: 1, }); }

Each client runs the shared factory, and only the site's client runs the one that polls. The last call is a type error:

import { function invalidateMany<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, partial?: PartialInput<TFactory>): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
} from "@raf-query/react";
const
const site: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>
site
=
const makeSiteClient: () => QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>
makeSiteClient
();
const
const widget: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
widget
=
const makeWidgetClient: () => QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
makeWidgetClient
();
await
invalidateMany<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>>(client: ClientFor<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>>, factory: (input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>, partial?: {
    ...;
} | undefined): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(
const site: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>
site
,
function postQuery(input: {
    slug: string;
}): QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
postQuery
);
await
invalidateMany<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>>(client: ClientFor<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>>, factory: (input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>, partial?: {
    ...;
} | undefined): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(
const widget: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
widget
,
function postQuery(input: {
    slug: string;
}): QueryOptions<readonly ["posts", "bySlug", string], Post, Post, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
postQuery
);
await
invalidateMany<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>>(client: ClientFor<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>>, factory: (input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>, partial?: {
    ...;
} | undefined): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(
const site: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>
site
,
function postViewsQuery(input: {
    slug: string;
}): QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>
postViewsQuery
);
await
invalidateMany<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>>(client: ClientFor<(input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>>, factory: (input: {
    slug: string;
}) => QueryOptions<readonly ["posts", "views", string], number, number, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>, partial?: {
    ...;
} | undefined): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(
const widget: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
widget
, postViewsQuery);
No overload matches this call. The last overload gave the following error. Argument of type '(input: { slug: string; }) => QueryOptions<readonly ["posts", "views", string], number, number, { readonly "~options": { readonly retry: (value: number | false | undefined) => number | false | undefined; readonly refetchInterval: (value: number | ... 1 more ... | undefined) => number | ... 1 more ... | undefined; };...' is not assignable to parameter of type 'readonly AnyItem[]'.

Options several factories share

OptionsOf<typeof makeQueryClient> is what the client's builders let a query set beside its key and queryFn: the core's options and those of the client's plugins. Use it to type a fragment that several factories spread:

import type { type OptionsOf<T> = CoreOptions & Partial<SetsOf<T>["options"]>

The options a builder bound to T lets a query set, beside its key and queryFn: the core's, and those T's plugins declare. For a fragment several factories share:

OptionsOf
} from "@raf-query/react";
// For data that doesn't change: never stale, and not worth a retry const
const pinned: {
    retry: false;
    staleTime: number;
}
pinned
= {
retry?: number | false | undefinedretry: false, CoreOptions.staleTime?: number | undefined

How long data stays fresh, in ms. Default 0.

staleTime
: var Infinity: numberInfinity,
} satisfies type OptionsOf<T> = CoreOptions & Partial<SetsOf<T>["options"]>

The options a builder bound to T lets a query set, beside its key and queryFn: the core's, and those T's plugins declare. For a fragment several factories share:

OptionsOf
<typeof
function makeQueryClient(apiClient: ApiClient): QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
makeQueryClient
>;
export function
function authorQuery(input: {
    id: string;
}): QueryOptions<readonly ["authors", string], Author, Author, {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | ... 1 more ... | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
authorQuery
(
input: {
    id: string;
}
input
: { id: stringid: string }) {
return
const queryOptions: QueryOptionsBuilder
<readonly ["authors", string], Author, Author>(options: BaseOptions<readonly ["authors", string]> & Partial<{
    readonly errorMessage: string | undefined;
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
    readonly owner: "editorial" | "community" | undefined;
}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["authors", string], {
        readonly "~options": {
            readonly errorMessage: (value: string | undefined) => string | undefined;
            ... 4 more ...;
            readonly owner: (value: "editorial" | ... 1 more ... | undefined) => "editorial" | ... 1 more ... | undefined;
        };
        readonly context: {
            ...;
        };
        readonly options: {
            ...;
        };
    }>) => Awaitable<...>;
    readonly select?: ((data: Author) => Author) | undefined;
}) => QueryOptions<...> (+1 overload)
queryOptions
({
...
const pinned: {
    retry: false;
    staleTime: number;
}
pinned
,
BaseOptions<readonly ["authors", string]>.queryKey: readonly ["authors", string]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
: authors<readonly [string]>(rest_0: string): readonly ["authors", string]authors(
input: {
    id: string;
}
input
.id: stringid),
queryFn: (context: QueryFunctionContext<readonly ["authors", string], {
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>) => Awaitable<...>
queryFn
: () => function getAuthor(id: string): Promise<Author>getAuthor(
input: {
    id: string;
}
input
.id: stringid),
}); }

Client-wide defaults

defaults sets an option for every query of the client: the core's staleTime, gcTime and structuralSharing, and any option the client's plugins declare. A query's own option wins.

import { function recommended(): Recommended

The behaviors most apps want: retries, refetching on focus and reconnect, and polling. Pass it as the client's plugins, or spread it among your own:

recommended
} from "@raf-query/react";
export function
function makeQueryClient(): QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchOnWindowFocus: boolean | undefined;
        readonly refetchOnReconnect: boolean | undefined;
        readonly refetchInterval: number | ... 1 more ... | undefined;
    };
}>
makeQueryClient
() {
return
createQueryClient<Recommended>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
        readonly retry: number | false | undefined;
        readonly refetchOnWindowFocus: boolean | undefined;
        readonly refetchOnReconnect: boolean | undefined;
        readonly refetchInterval: number | false | undefined;
    }>> | undefined;
    readonly plugins?: Recommended | undefined;
}): QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | ... 1 more ... | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | ... 1 more ... | undefined) => number | ... 1 more ... | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
        readonly refetchOnWindowFocus: boolean | undefined;
        readonly refetchOnReconnect: boolean | undefined;
        readonly refetchInterval: number | false | undefined;
    };
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({
plugins?: Recommended | undefinedplugins: function recommended(): Recommended

The behaviors most apps want: retries, refetching on focus and reconnect, and polling. Pass it as the client's plugins, or spread it among your own:

recommended
(),
defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
}>> | undefined
defaults
: {
// The core's options staleTime?: number | undefined

How long data stays fresh, in ms. Default 0.

staleTime
: 30_000,
gcTime?: number | undefined

How long an entry with no reader stays cached. Default 5 minutes; never on the server.

gcTime
: 10 * 60_000,
// Options of `retry()` and `focusRefetch()` retry?: number | false | undefinedretry: 1, refetchOnWindowFocus?: boolean | undefinedrefetchOnWindowFocus: false, }, }); }

defaults is typed by the plugins of the same call, so a default for an option no plugin declares is an error:

createQueryClient<readonly [Plugin<Polling>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
        readonly refetchInterval: number | false | undefined;
    }>> | undefined;
    readonly plugins?: readonly [Plugin<Polling>] | undefined;
}): QueryClient<{
    readonly "~options": {
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly refetchInterval: number | false | undefined;
    };
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({
plugins?: readonly [Plugin<Polling>] | undefinedplugins: [function polling(): Plugin<Polling>

Refetch read queries every refetchInterval ms.

polling
()],
defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
    readonly refetchInterval: number | false | undefined;
}>> | undefined
defaults
: { retry: 1 },
Object literal may only specify known properties, and 'retry' does not exist in type 'Omit<CoreOptions, "ssr"> & Partial<{ readonly refetchInterval: number | false | undefined; }>'.
});

Selecting queries by options

A where target picks queries by what their options say. Written inline, query.options has the options of the client the verb is called with:

import { function invalidateMany<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, partial?: PartialInput<TFactory>): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
} from "@raf-query/react";
const
const qc: QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
qc
=
function makeQueryClient(apiClient: ApiClient): QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
makeQueryClient
(const apiClient: ApiClientapiClient);
await
invalidateMany<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}, never>(client: QueryClient<...>, target: TargetFor<...>): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(
const qc: QueryClient<{
    readonly "~options": {
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
qc
, {
Target<NoInfer<{ readonly errorMessage: string | undefined; readonly retry: number | false | undefined; readonly refetchOnWindowFocus: boolean | undefined; readonly refetchOnReconnect: boolean | undefined; readonly refetchInterval: number | ... 1 more ... | undefined; readonly owner: "editorial" | ... 1 more ... | undefined; }>, never>.where: (query: QueryInfo<NoInfer<{
    readonly errorMessage: string | undefined;
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
    readonly owner: "editorial" | "community" | undefined;
}>>, param: never) => boolean
where
: (
query: QueryInfo<NoInfer<{
    readonly errorMessage: string | undefined;
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
    readonly owner: "editorial" | "community" | undefined;
}>>
query
) =>
query: QueryInfo<NoInfer<{
    readonly errorMessage: string | undefined;
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
    readonly owner: "editorial" | "community" | undefined;
}>>
query
.
QueryInfo<NoInfer<{ readonly errorMessage: string | undefined; readonly retry: number | false | undefined; readonly refetchOnWindowFocus: boolean | undefined; readonly refetchOnReconnect: boolean | undefined; readonly refetchInterval: number | ... 1 more ... | undefined; readonly owner: "editorial" | ... 1 more ... | undefined; }>>.options: {
    readonly errorMessage: string | undefined;
    readonly retry: number | false | undefined;
    readonly refetchOnWindowFocus: boolean | undefined;
    readonly refetchOnReconnect: boolean | undefined;
    readonly refetchInterval: number | false | undefined;
    readonly owner: "editorial" | "community" | undefined;
}

The options its factory gave it. An entry only hydrated has {} until it's read.

options
.owner === "community",
owner: "editorial" | "community" | undefined
});

A target kept in a variable is typed Target<TOptions, TParam>, by the options it reads and the parameter it takes:

import type { type RootOf<T> = [RootOfClient<T>] extends [never] ? Root<WithoutOptional<T>> : RootOfClient<T>

The root a builder is bound to: a client's, the root of a function that makes one, or the root of the plugins a library names by their declarations. QueryClient<RootOf<Convex>> is a client that has the plugin that declares Convex.

RootOf
, interface Target<TOptions = object, TParam = never>

Picks out queries by what they are: where gets each query and the parameter the verb was called with.

Target
} from "@raf-query/react";
type type Team = "editorial" | "community"Team = type NonNullable<T> = T & {}

Exclude null and undefined from T

NonNullable
<Ownership["options"]["owner"]>;
// `owner` the way a client with `ownership` has it: present, possibly `undefined` type
type Owned = {
    readonly owner: "editorial" | "community" | undefined;
}
Owned
= type RootOf<T> = [RootOfClient<T>] extends [never] ? Root<WithoutOptional<T>> : RootOfClient<T>

The root a builder is bound to: a client's, the root of a function that makes one, or the root of the plugins a library names by their declarations. QueryClient<RootOf<Convex>> is a client that has the plugin that declares Convex.

RootOf
<Ownership>["options"];
const
const ownedBy: Target<{
    readonly owner: "editorial" | "community" | undefined;
}, Team>
ownedBy
: interface Target<TOptions = object, TParam = never>

Picks out queries by what they are: where gets each query and the parameter the verb was called with.

Target
<
type Owned = {
    readonly owner: "editorial" | "community" | undefined;
}
Owned
, type Team = "editorial" | "community"Team> = {
Target<{ readonly owner: "editorial" | "community" | undefined; }, Team>.where: (query: QueryInfo<{
    readonly owner: "editorial" | "community" | undefined;
}>, param: Team) => boolean
where
: (
query: QueryInfo<{
    readonly owner: "editorial" | "community" | undefined;
}>
query
, team: Teamteam) =>
query: QueryInfo<{
    readonly owner: "editorial" | "community" | undefined;
}>
query
.
QueryInfo<{ readonly owner: "editorial" | "community" | undefined; }>.options: {
    readonly owner: "editorial" | "community" | undefined;
}

The options its factory gave it. An entry only hydrated has {} until it's read.

options
.owner: "editorial" | "community" | undefinedowner === team: Teamteam,
}; await
invalidateMany<{
    readonly "~options": {
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}, Team>(client: QueryClient<...>, target: TargetFor<...>, param: Team): Promise<void> (+3 overloads)

Mark queries stale: a factory's (optionally only those whose input matches partial), a group's (keys that start with its path, whether the group built them or not), or those a target's where picks. Read queries refetch now; the rest when next read. Resolves when the refetches settle.

invalidateMany
(
const qc: QueryClient<{
    readonly "~options": {
        readonly owner: (value: "editorial" | "community" | undefined) => "editorial" | "community" | undefined;
        readonly errorMessage: (value: string | undefined) => string | undefined;
        readonly retry: (value: number | false | undefined) => number | false | undefined;
        readonly refetchOnWindowFocus: (value: boolean | undefined) => boolean | undefined;
        readonly refetchOnReconnect: (value: boolean | undefined) => boolean | undefined;
        readonly refetchInterval: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {
        ...;
    };
    readonly options: {
        ...;
    };
}>
qc
,
const ownedBy: Target<{
    readonly owner: "editorial" | "community" | undefined;
}, Team>
ownedBy
, "editorial");

RootOf<Ownership>["options"] is owner the way a client with the plugin has it: present, and possibly undefined. Typed that way, ownedBy fits only clients made with ownership. Typed Target<Ownership["options"], Team>, where owner is optional, it would also fit a client without the plugin, and match nothing there.

See Query invalidation for targets, and for tags, which are targets over an option.

Binding a library to plugins

A package that ships factories can't name the app's client. It binds its builders to the declarations of the plugins its factories need. Optional<…> names a plugin they don't need: its options can be set, and they take effect on the clients that have the plugin.

import {
	function bindQueryOptions<T = NoDecl>(): QueryOptionsBuilder<RootOf<T>, SetsOf<T>>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
,
function group<const TName extends string>(name: TName): Group<readonly [TName]> (+1 overload)

A group, or a subgroup inside parent. Call it for a query's key: a flat, plain array that starts with the group's path. Invalidating a group covers its subgroups and every query below them.

group
,
type interface Optional<TDecl extends Decl>

In a library's binding: a plugin whose options its queries set where the client has it, without needing it.

Optional
,
type interface Plugin<TDecl extends Decl = NoDecl>

One piece of a client's behavior: any of a link that wraps every request, a feature's setup, and values for every queryFn's context. TDecl is what it declares: see plugin.

Plugin
,
function plugin<TDecl extends OptionsDecl = NoDecl>(definition?: PlainDefinition<NoInfer<TDecl>>): Plugin<NoInfer<TDecl>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
,
type Retry, } from "@raf-query/react"; export interface CmsClient {
CmsClient.entry(id: string, init: {
    signal: AbortSignal;
}): Promise<{
    title: string;
}>
entry
(id: stringid: string,
init: {
    signal: AbortSignal;
}
init
: { signal: AbortSignalsignal: AbortSignal }): interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<{ title: stringtitle: string }>;
} // What the package's plugin declares: a client for every `queryFn` export interface Cms { readonly
Cms.context: {
    readonly cms: CmsClient;
}
context
: { readonly cms: CmsClientcms: CmsClient };
} export function function cms(client: CmsClient): Plugin<Cms>cms(client: CmsClientclient: CmsClient): interface Plugin<TDecl extends Decl = NoDecl>

One piece of a client's behavior: any of a link that wraps every request, a feature's setup, and values for every queryFn's context. TDecl is what it declares: see plugin.

Plugin
<Cms> {
return plugin<Cms>(definition: ClientContextDefinition<NoInfer<Cms>>): Plugin<NoInfer<Cms>> (+2 overloads)

A plugin for a client, with what it declares: the per-query options it reads and the context it gives every queryFn. A client's queries take those options, and get that context, only when the client has the plugin.

plugin
<Cms>({
ClientContextDefinition<NoInfer<Cms>>.context: {
    readonly cms: CmsClient;
}

Merged into the context of every queryFn the client runs.

context
: { cms: CmsClientcms: client: CmsClientclient } });
} // The package's own builder: its factories need `cms()`, and set `retry` // on the clients that have `retry()`. const
const queryOptions: QueryOptionsBuilder<{
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
queryOptions
=
bindQueryOptions<Cms & Optional<Retry>>(): QueryOptionsBuilder<{
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}, {
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
<Cms & interface Optional<TDecl extends Decl>

In a library's binding: a plugin whose options its queries set where the client has it, without needing it.

Optional
<Retry>>();
const const entries: Group<readonly ["cms"]>entries = group<"cms">(name: "cms"): Group<readonly ["cms"]> (+1 overload)

A group, or a subgroup inside parent. Call it for a query's key: a flat, plain array that starts with the group's path. Invalidating a group covers its subgroups and every query below them.

group
("cms");
export function
function entryQuery(input: {
    id: string;
}): QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>
entryQuery
(
input: {
    id: string;
}
input
: { id: stringid: string }) {
return
const queryOptions: QueryOptionsBuilder
<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}>(options: BaseOptions<readonly ["cms", string]> & Partial<{
    readonly retry: number | false | undefined;
}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["cms", string], {
        readonly "~options": {};
        readonly context: {
            readonly cms: CmsClient;
        };
        readonly options: {};
    }>) => Awaitable<{
        title: string;
    }>;
    readonly select?: ((data: {
        title: string;
    }) => {
        title: string;
    }) | undefined;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    ...;
}> (+1 overload)
queryOptions
({
BaseOptions<readonly ["cms", string]>.queryKey: readonly ["cms", string]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
:
const entries: Group
<readonly [string]>(rest_0: string) => readonly ["cms", string]
entries
(
input: {
    id: string;
}
input
.id: stringid),
queryFn: (context: QueryFunctionContext<readonly ["cms", string], {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>) => Awaitable<{
    title: string;
}>
queryFn
: ({ cms: CmsClientcms, signal: AbortSignal

Aborted when the request is restarted or its entry is removed.

signal
}) => cms: CmsClientcms.
CmsClient.entry(id: string, init: {
    signal: AbortSignal;
}): Promise<{
    title: string;
}>
entry
(
input: {
    id: string;
}
input
.id: stringid, { signal: AbortSignalsignal }),
// The CMS client retries on its own retry?: number | false | undefinedretry: false, }); }

The app gives its client the package's plugin, and the package's factories run on it. On a client without the plugin, here the last one, they're a type error:

import { function invalidateOne<TFactory extends QueryFactory>(client: ClientFor<TFactory>, factory: TFactory, ...input: InputArgs<TFactory>): Promise<void>

Mark one query stale: a factory and its full input. If it's read, it refetches; resolves when that settles.

invalidateOne
} from "@raf-query/react";
// With `retry()`, which reads the query's `retry: false` const
const retrying: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
retrying
=
createQueryClient<readonly [Plugin<Retry>, Plugin<Cms>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
        readonly retry: number | false | undefined;
    }>> | undefined;
    readonly plugins?: readonly [Plugin<Retry>, Plugin<Cms>] | undefined;
}): QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({ plugins?: readonly [Plugin<Retry>, Plugin<Cms>] | undefinedplugins: [function retry(options?: RetryOptions): Plugin<Retry>

Retry failed requests. Thrown Responses (router redirects and not-founds) and cancelled requests aren't retried, server clients never retry, and a browser that is offline waits until it's back online before retrying. A query sets its own attempts with retry.

retry
(), function cms(client: CmsClient): Plugin<Cms>cms(const cmsClient: CmsClientcmsClient)] });
await
invalidateOne<(input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>>(client: ClientFor<(input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>>, factory: (input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>, input: {
    ...;
}): Promise<void>

Mark one query stale: a factory and its full input. If it's read, it refetches; resolves when that settles.

invalidateOne
(
const retrying: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
retrying
,
function entryQuery(input: {
    id: string;
}): QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>
entryQuery
, { id: stringid: "home" });
// Without it: the option does nothing const
const plain: QueryClient<{
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>
plain
=
createQueryClient<readonly [Plugin<Cms>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{}>> | undefined;
    readonly plugins?: readonly [Plugin<Cms>] | undefined;
}): QueryClient<{
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({ plugins?: readonly [Plugin<Cms>] | undefinedplugins: [function cms(client: CmsClient): Plugin<Cms>cms(const cmsClient: CmsClientcmsClient)] });
await
invalidateOne<(input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>>(client: ClientFor<(input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>>, factory: (input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>, input: {
    ...;
}): Promise<void>

Mark one query stale: a factory and its full input. If it's read, it refetches; resolves when that settles.

invalidateOne
(
const plain: QueryClient<{
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>
plain
,
function entryQuery(input: {
    id: string;
}): QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>
entryQuery
, { id: stringid: "home" });
const
const withoutCms: QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>
withoutCms
=
createQueryClient<readonly [Plugin<Retry>]>(config?: Omit<QueryClientConfig, "defaults" | "plugins"> & {
    readonly defaults?: NoInfer<Omit<CoreOptions, "ssr"> & Partial<{
        readonly retry: number | false | undefined;
    }>> | undefined;
    readonly plugins?: readonly [Plugin<Retry>] | undefined;
}): QueryClient<{
    readonly "~options": {
        readonly retry: (value: number | false | undefined) => number | false | undefined;
    };
    readonly context: {};
    readonly options: {
        readonly retry: number | false | undefined;
    };
}>

Create a query client. Behaviors are opt-in: pass plugins, such as recommended(). The client's root is what they declare.

createQueryClient
({ plugins?: readonly [Plugin<Retry>] | undefinedplugins: [function retry(options?: RetryOptions): Plugin<Retry>

Retry failed requests. Thrown Responses (router redirects and not-founds) and cancelled requests aren't retried, server clients never retry, and a browser that is offline waits until it's back online before retrying. A query sets its own attempts with retry.

retry
()] });
await
invalidateOne<(input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>>(client: ClientFor<(input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>>, factory: (input: {
    id: string;
}) => QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>, input: {
    ...;
}): Promise<void>

Mark one query stale: a factory and its full input. If it's read, it refetches; resolves when that settles.

invalidateOne
(withoutCms,
function entryQuery(input: {
    id: string;
}): QueryOptions<readonly ["cms", string], {
    title: string;
}, {
    title: string;
}, {
    readonly "~options": {};
    readonly context: {
        readonly cms: CmsClient;
    };
    readonly options: {};
}>
entryQuery
, { id: stringid: "home" });
Argument of type 'QueryClient<{ readonly "~options": { readonly retry: (value: number | false | undefined) => number | false | undefined; }; readonly context: {}; readonly options: { readonly retry: number | false | undefined; }; }>' is not assignable to parameter of type 'ClientFor<(input: { id: string; }) => QueryOptions<readonly ["cms", string], { title: string; }, { title: string; }, { readonly "~options": {}; readonly context: { readonly cms: CmsClient; }; readonly options: {}; }>>'. Type '{ readonly "~options": { readonly retry: (value: number | false | undefined) => number | false | undefined; }; readonly context: {}; readonly options: { readonly retry: number | false | undefined; }; }' is not assignable to type '{ readonly "~options": {}; readonly context: { readonly cms: CmsClient; }; readonly options: {}; }'. Types of property 'context' are incompatible. Property 'cms' is missing in type '{}' but required in type '{ readonly cms: CmsClient; }'.

A package whose factories need no plugin calls bindQueryOptions() without a type argument. That builder takes the core's options only (staleTime, gcTime, structuralSharing, ssr), its queryFn gets client, queryKey and signal, and its factories run on any client:

import { function bindQueryOptions<T = NoDecl>(): QueryOptionsBuilder<RootOf<T>, SetsOf<T>>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
, function group<const TName extends string>(name: TName): Group<readonly [TName]> (+1 overload)

A group, or a subgroup inside parent. Call it for a query's key: a flat, plain array that starts with the group's path. Invalidating a group covers its subgroups and every query below them.

group
} from "@raf-query/react";
// No type argument: the builder takes the core's options only, and its // factories run on any client. const
const queryOptions: QueryOptionsBuilder<{
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}, {
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>
queryOptions
=
bindQueryOptions<NoDecl>(): QueryOptionsBuilder<{
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}, {
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>

Makes queryOptions, the builder of a query factory's options, bound to the clients its factories run on:

bindQueryOptions
();
const const status: Group<readonly ["status-page"]>status = group<"status-page">(name: "status-page"): Group<readonly ["status-page"]> (+1 overload)

A group, or a subgroup inside parent. Call it for a query's key: a flat, plain array that starts with the group's path. Invalidating a group covers its subgroups and every query below them.

group
("status-page");
export function
function incidentsQuery(): QueryOptions<readonly ["status-page", "incidents"], readonly Incident[], readonly Incident[], {
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>
incidentsQuery
() {
return
const queryOptions: QueryOptionsBuilder
<readonly ["status-page", "incidents"], readonly Incident[], readonly Incident[]>(options: BaseOptions<readonly ["status-page", "incidents"]> & Partial<{}> & {
    readonly queryFn: (context: QueryFunctionContext<readonly ["status-page", "incidents"], {
        readonly "~options": {};
        readonly context: {};
        readonly options: {};
    }>) => Awaitable<readonly Incident[]>;
    readonly select?: ((data: readonly Incident[]) => readonly Incident[]) | undefined;
}) => QueryOptions<readonly ["status-page", "incidents"], readonly Incident[], readonly Incident[], {
    ...;
}> (+1 overload)
queryOptions
({
BaseOptions<readonly ["status-page", "incidents"]>.queryKey: readonly ["status-page", "incidents"]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
:
const status: Group
<readonly ["incidents"]>(rest_0: "incidents") => readonly ["status-page", "incidents"]
status
("incidents"),
queryFn: (context: QueryFunctionContext<readonly ["status-page", "incidents"], {
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>) => Awaitable<readonly Incident[]>
queryFn
: ({ signal: AbortSignal

Aborted when the request is restarted or its entry is removed.

signal
}) =>
function listIncidents(init: {
    signal: AbortSignal;
}): Promise<ReadonlyArray<Incident>>
listIncidents
({ signal: AbortSignalsignal }),
CoreOptions.staleTime?: number | undefined

How long data stays fresh, in ms. Default 0.

staleTime
: 60_000,
}); } queryOptions({
No overload matches this call. Overload 1 of 2, '(options: BaseOptions<readonly ["status-page", "incidents", "retried"]> & Partial<{}> & { readonly queryFn: (context: QueryFunctionContext<readonly ["status-page", "incidents", "retried"], { readonly "~options": {}; readonly context: {}; readonly options: {}; }>) => AsyncIterable<...>; readonly stream: StreamOptions<...>; }): QueryOptions<...>', gave the following error. Property '[Symbol.asyncIterator]' is missing in type 'Promise<readonly Incident[]>' but required in type 'AsyncIterable<unknown>'. Overload 2 of 2, '(options: BaseOptions<readonly ["status-page", "incidents", "retried"]> & Partial<{}> & { readonly queryFn: (context: QueryFunctionContext<readonly ["status-page", "incidents", "retried"], { readonly "~options": {}; readonly context: {}; readonly options: {}; }>) => Awaitable<...>; readonly select?: ((data: readonly Incident[]) => readonly Incident[]) | undefined; }): QueryOptions<...>', gave the following error. Object literal may only specify known properties, and 'retry' does not exist in type 'BaseOptions<readonly ["status-page", "incidents", "retried"]> & Partial<{}> & { readonly queryFn: (context: QueryFunctionContext<readonly ["status-page", "incidents", "retried"], { readonly "~options": {}; readonly context: {}; readonly options: {}; }>) => Awaitable<...>; readonly select?: ((data: readonly Incident[...'.
BaseOptions<readonly ["status-page", "incidents", "retried"]>.queryKey: readonly ["status-page", "incidents", "retried"]

A plain array, usually built by a group(). Handles keep its literal type.

queryKey
:
const status: Group
<readonly ["incidents", "retried"]>(rest_0: "incidents", rest_1: "retried") => readonly ["status-page", "incidents", "retried"]
status
("incidents", "retried"),
queryFn: (context: QueryFunctionContext<readonly ["status-page", "incidents", "retried"], {
    readonly "~options": {};
    readonly context: {};
    readonly options: {};
}>) => AsyncIterable<unknown>
queryFn
: ({ signal: AbortSignal

Aborted when the request is restarted or its entry is removed.

signal
}) =>
function listIncidents(init: {
    signal: AbortSignal;
}): Promise<ReadonlyArray<Incident>>
listIncidents
({ signal: AbortSignalsignal }),
retry: numberretry: 1, });

Serialization

Options aren't sent with dehydrated state during SSR: they come from the factory, so they can hold anything, functions included. An entry only hydrated, which nothing has read through its factory yet, has {} as its options until it's read. Invalidations still reach it: they're checked again when the entry is next read.

A plugin's context isn't sent either. Each client has its own, from the plugins it was made with.