import type { ApolloQueryResult, ObservableQuery, OperationVariables, WatchQueryOptions } from "../../../core/index.js"; import type { PromiseWithState } from "../../../utilities/index.js"; import type { QueryKey } from "./types.js"; type QueryRefPromise = PromiseWithState>; type Listener = (promise: QueryRefPromise) => void; type FetchMoreOptions = Parameters["fetchMore"]>[0]; declare const QUERY_REFERENCE_SYMBOL: unique symbol; declare const PROMISE_SYMBOL: unique symbol; /** * A `QueryReference` is an opaque object returned by {@link useBackgroundQuery}. * A child component reading the `QueryReference` via {@link useReadQuery} will * suspend until the promise resolves. */ export interface QueryReference { /** @internal */ readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference; /** @internal */ [PROMISE_SYMBOL]: QueryRefPromise; /** * A function that returns a promise that resolves when the query has finished * loading. The promise resolves with the `QueryReference` itself. * * @remarks * This method is useful for preloading queries in data loading routers, such * as [React Router](https://reactrouter.com/en/main) or [TanStack Router](https://tanstack.com/router), * to prevent routes from transitioning until the query has finished loading. * `data` is not exposed on the promise to discourage using the data in * `loader` functions and exposing it to your route components. Instead, we * prefer you rely on `useReadQuery` to access the data to ensure your * component can rerender with cache updates. If you need to access raw query * data, use `client.query()` directly. * * @example * Here's an example using React Router's `loader` function: * ```ts * import { createQueryPreloader } from "@apollo/client"; * * const preloadQuery = createQueryPreloader(client); * * export async function loader() { * const queryRef = preloadQuery(GET_DOGS_QUERY); * * return queryRef.toPromise(); * } * * export function RouteComponent() { * const queryRef = useLoaderData(); * const { data } = useReadQuery(queryRef); * * // ... * } * ``` * * @alpha */ toPromise(): Promise>; } interface InternalQueryReferenceOptions { onDispose?: () => void; autoDisposeTimeoutMs?: number; } export declare function wrapQueryRef(internalQueryRef: InternalQueryReference): QueryReference; export declare function getWrappedPromise(queryRef: QueryReference): QueryRefPromise; export declare function unwrapQueryRef(queryRef: QueryReference): InternalQueryReference; export declare function updateWrappedQueryRef(queryRef: QueryReference, promise: QueryRefPromise): void; declare const OBSERVED_CHANGED_OPTIONS: readonly ["canonizeResults", "context", "errorPolicy", "fetchPolicy", "refetchWritePolicy", "returnPartialData"]; type ObservedOptions = Pick; export declare class InternalQueryReference { result: ApolloQueryResult; readonly key: QueryKey; readonly observable: ObservableQuery; promise: QueryRefPromise; private subscription; private listeners; private autoDisposeTimeoutId?; private resolve; private reject; private references; constructor(observable: ObservableQuery, options: InternalQueryReferenceOptions); get disposed(): boolean; get watchQueryOptions(): WatchQueryOptions; reinitialize(): void; retain(): () => void; didChangeOptions(watchQueryOptions: ObservedOptions): boolean; applyOptions(watchQueryOptions: ObservedOptions): QueryRefPromise; listen(listener: Listener): () => void; refetch(variables: OperationVariables | undefined): Promise>; fetchMore(options: FetchMoreOptions): Promise>; private dispose; private onDispose; private handleNext; private handleError; private deliver; private initiateFetch; private subscribeToQuery; private setResult; private createPendingPromise; } export {}; //# sourceMappingURL=QueryReference.d.ts.map