UNPKG

6.95 kBTypeScriptView Raw
1import { NetworkStatus } from "./networkStatus.js";
2import type { Concast, Observer, ObservableSubscription } from "../utilities/index.js";
3import { Observable } from "../utilities/index.js";
4import type { ApolloError } from "../errors/index.js";
5import type { QueryManager } from "./QueryManager.js";
6import type { ApolloQueryResult, OperationVariables, TypedDocumentNode } from "./types.js";
7import type { WatchQueryOptions, FetchMoreQueryOptions, SubscribeToMoreOptions } from "./watchQueryOptions.js";
8import type { QueryInfo } from "./QueryInfo.js";
9import type { MissingFieldError } from "../cache/index.js";
10import type { MissingTree } from "../cache/core/types/common.js";
11export interface FetchMoreOptions<TData = any, TVariables = OperationVariables> {
12 updateQuery?: (previousQueryResult: TData, options: {
13 fetchMoreResult?: TData;
14 variables?: TVariables;
15 }) => TData;
16}
17export interface UpdateQueryOptions<TVariables> {
18 variables?: TVariables;
19}
20export declare class ObservableQuery<TData = any, TVariables extends OperationVariables = OperationVariables> extends Observable<ApolloQueryResult<TData>> {
21 readonly options: WatchQueryOptions<TVariables, TData>;
22 readonly queryId: string;
23 readonly queryName?: string;
24 get query(): TypedDocumentNode<TData, TVariables>;
25 /**
26 * An object containing the variables that were provided for the query.
27 */
28 get variables(): TVariables | undefined;
29 private isTornDown;
30 private queryManager;
31 private observers;
32 private subscriptions;
33 private waitForOwnResult;
34 private last?;
35 private lastQuery?;
36 private queryInfo;
37 private concast?;
38 private observer?;
39 private pollingInfo?;
40 constructor({ queryManager, queryInfo, options, }: {
41 queryManager: QueryManager<any>;
42 queryInfo: QueryInfo;
43 options: WatchQueryOptions<TVariables, TData>;
44 });
45 result(): Promise<ApolloQueryResult<TData>>;
46 /** @internal */
47 resetDiff(): void;
48 getCurrentResult(saveAsLastResult?: boolean): ApolloQueryResult<TData>;
49 isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
50 private getLast;
51 getLastResult(variablesMustMatch?: boolean): ApolloQueryResult<TData> | undefined;
52 getLastError(variablesMustMatch?: boolean): ApolloError | undefined;
53 resetLastResults(): void;
54 resetQueryStoreErrors(): void;
55 /**
56 * Update the variables of this observable query, and fetch the new results.
57 * This method should be preferred over `setVariables` in most use cases.
58 *
59 * @param variables - The new set of variables. If there are missing variables,
60 * the previous values of those variables will be used.
61 */
62 refetch(variables?: Partial<TVariables>): Promise<ApolloQueryResult<TData>>;
63 /**
64 * A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
65 */
66 fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(fetchMoreOptions: FetchMoreQueryOptions<TFetchVars, TFetchData> & {
67 updateQuery?: (previousQueryResult: TData, options: {
68 fetchMoreResult: TFetchData;
69 variables: TFetchVars;
70 }) => TData;
71 }): Promise<ApolloQueryResult<TFetchData>>;
72 /**
73 * A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
74 *
75 * This function returns _another_ function that you can call to terminate the subscription.
76 */
77 subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>): () => void;
78 setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<TData>>;
79 silentSetOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): void;
80 /**
81 * Update the variables of this observable query, and fetch the new results
82 * if they've changed. Most users should prefer `refetch` instead of
83 * `setVariables` in order to to be properly notified of results even when
84 * they come from the cache.
85 *
86 * Note: the `next` callback will *not* fire if the variables have not changed
87 * or if the result is coming from cache.
88 *
89 * Note: the promise will return the old results immediately if the variables
90 * have not changed.
91 *
92 * Note: the promise will return null immediately if the query is not active
93 * (there are no subscribers).
94 *
95 * @param variables - The new set of variables. If there are missing variables,
96 * the previous values of those variables will be used.
97 */
98 setVariables(variables: TVariables): Promise<ApolloQueryResult<TData> | void>;
99 /**
100 * A function that enables you to update the query's cached result without executing a followup GraphQL operation.
101 *
102 * See [using updateQuery and updateFragment](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-updatequery-and-updatefragment) for additional information.
103 */
104 updateQuery<TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: TData, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => TData): void;
105 /**
106 * A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
107 */
108 startPolling(pollInterval: number): void;
109 /**
110 * A function that instructs the query to stop polling after a previous call to `startPolling`.
111 */
112 stopPolling(): void;
113 private applyNextFetchPolicy;
114 private fetch;
115 private updatePolling;
116 private updateLastResult;
117 reobserveAsConcast(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus): Concast<ApolloQueryResult<TData>>;
118 reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus): Promise<ApolloQueryResult<TData>>;
119 resubscribeAfterError(onNext: (value: ApolloQueryResult<TData>) => void, onError?: (error: any) => void, onComplete?: () => void): ObservableSubscription;
120 resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): ObservableSubscription;
121 private observe;
122 private reportResult;
123 private reportError;
124 hasObservers(): boolean;
125 private tearDownQuery;
126 private transformDocument;
127}
128export declare function reobserveCacheFirst<TData, TVars extends OperationVariables>(obsQuery: ObservableQuery<TData, TVars>): Promise<ApolloQueryResult<TData>>;
129export declare function logMissingFieldErrors(missing: MissingFieldError[] | MissingTree | undefined): void;
130//# sourceMappingURL=ObservableQuery.d.ts.map
\No newline at end of file