@apollo-orbit/angular
Version:
A fully-featured GraphQL client for Angular with modular state management.
68 lines (67 loc) • 4.37 kB
TypeScript
import { ApolloError, ApolloQueryResult, WatchQueryOptions as CoreWatchQueryOptions, FetchMoreQueryOptions, NetworkStatus, ObservableQuery, OperationVariables, TypedDocumentNode, OperationVariables as Variables } from '@apollo/client/core';
import { Concast, ObservableSubscription, Observer } from '@apollo/client/utilities';
import { Observable } from 'rxjs';
import { ExtraWatchQueryOptions, QueryResult, SubscribeToMoreOptions } from './types';
export declare class QueryObservable<TData = any, TVariables extends Variables = Variables> extends Observable<QueryResult<TData>> {
private readonly observableQuery;
private previousData;
constructor(observableQuery: ObservableQuery<TData, TVariables>, { notifyOnLoading, throwError }: ExtraWatchQueryOptions);
get query(): TypedDocumentNode<TData, TVariables>;
get variables(): TVariables | undefined;
get options(): CoreWatchQueryOptions<TVariables>;
get queryId(): string;
get queryName(): string | undefined;
result(): Promise<ApolloQueryResult<TData>>;
getCurrentResult(saveAsLastResult?: boolean): QueryResult<TData>;
isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
getLastResult(variablesMustMatch?: boolean): ApolloQueryResult<TData> | undefined;
getLastError(variablesMustMatch?: boolean): ApolloError | undefined;
resetLastResults(): void;
resetQueryStoreErrors(): void;
/**
* Update the variables of this observable query, and fetch the new results.
* This method should be preferred over `setVariables` in most use cases.
*
* @param variables: The new set of variables. If there are missing variables,
* the previous values of those variables will be used.
*/
refetch(variables?: Partial<TVariables>): Promise<ApolloQueryResult<TData>>;
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(fetchMoreOptions: FetchMoreQueryOptions<TFetchVars, TFetchData> & {
updateQuery?: (previousQueryResult: TData, options: {
fetchMoreResult: TFetchData;
variables: TFetchVars;
}) => TData;
}): Promise<ApolloQueryResult<TFetchData>>;
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends Variables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>): () => void;
setOptions(newOptions: Partial<CoreWatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<TData>>;
silentSetOptions(newOptions: Partial<CoreWatchQueryOptions<TVariables, TData>>): void;
/**
* Update the variables of this observable query, and fetch the new results
* if they've changed. Most users should prefer `refetch` instead of
* `setVariables` in order to to be properly notified of results even when
* they come from the cache.
*
* Note: the `next` callback will *not* fire if the variables have not changed
* or if the result is coming from cache.
*
* Note: the promise will return the old results immediately if the variables
* have not changed.
*
* Note: the promise will return null immediately if the query is not active
* (there are no subscribers).
*
* @private
*
* @param variables: The new set of variables. If there are missing variables,
* the previous values of those variables will be used.
*/
setVariables(variables: TVariables): Promise<ApolloQueryResult<TData> | void>;
updateQuery<TVars extends Variables = TVariables>(mapFn: (previousQueryResult: TData, options: Pick<CoreWatchQueryOptions<TVars, TData>, 'variables'>) => TData): void;
startPolling(pollInterval: number): void;
stopPolling(): void;
reobserveAsConcast(newOptions?: Partial<CoreWatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus): Concast<ApolloQueryResult<TData>>;
reobserve(newOptions?: Partial<CoreWatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus): Promise<ApolloQueryResult<TData>>;
resubscribeAfterError(onNext: (value: ApolloQueryResult<TData>) => void, onError?: (error: any) => void, onComplete?: () => void): ObservableSubscription;
resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): ObservableSubscription;
hasObservers(): boolean;
}