import { Trie } from "@wry/trie";
import type { DocumentNode } from "graphql";
import { Observable } from "rxjs";
import type { ApolloCache, Cache } from "@apollo/client/cache";
import type { ApolloLink, FetchResult } from "@apollo/client/link/core";
import type { MaybeMasked } from "@apollo/client/masking";
import { DocumentTransform } from "@apollo/client/utilities";
import type { DefaultOptions } from "./ApolloClient.js";
import type { LocalState } from "./LocalState.js";
import { NetworkStatus } from "./networkStatus.js";
import { ObservableQuery } from "./ObservableQuery.js";
import { QueryInfo } from "./QueryInfo.js";
import type { ApolloQueryResult, DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutateResult, MutationUpdaterFunction, OnQueryUpdated, OperationVariables, QueryResult, SubscribeResult } from "./types.js";
import type { ErrorPolicy, MutationFetchPolicy, MutationOptions, QueryOptions, SubscriptionOptions, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
interface MutationStoreValue {
    mutation: DocumentNode;
    variables: Record<string, any>;
    loading: boolean;
    error: Error | null;
}
type UpdateQueries<TData> = MutationOptions<TData, any, any>["updateQueries"];
interface TransformCacheEntry {
    hasClientExports: boolean;
    hasForcedResolvers: boolean;
    hasNonreactiveDirective: boolean;
    nonReactiveQuery: DocumentNode;
    clientQuery: DocumentNode | null;
    serverQuery: DocumentNode | null;
    defaultVars: OperationVariables;
    asQuery: DocumentNode;
}
interface MaskFragmentOptions<TData> {
    fragment: DocumentNode;
    data: TData;
    fragmentName?: string;
}
interface MaskOperationOptions<TData> {
    document: DocumentNode;
    data: TData;
    id: string;
    fetchPolicy?: WatchQueryFetchPolicy;
}
interface QueryManagerOptions {
    cache: ApolloCache;
    link: ApolloLink;
    defaultOptions: DefaultOptions;
    documentTransform: DocumentTransform | null | undefined;
    queryDeduplication: boolean;
    onBroadcast: undefined | (() => void);
    ssrMode: boolean;
    clientAwareness: Record<string, string>;
    localState: LocalState;
    assumeImmutableResults: boolean;
    defaultContext: Partial<DefaultContext> | undefined;
    dataMasking: boolean;
}
export declare class QueryManager {
    cache: ApolloCache;
    link: ApolloLink;
    defaultOptions: DefaultOptions;
    readonly assumeImmutableResults: boolean;
    readonly documentTransform: DocumentTransform;
    readonly ssrMode: boolean;
    readonly defaultContext: Partial<DefaultContext>;
    readonly dataMasking: boolean;
    private queryDeduplication;
    private clientAwareness;
    private localState;
    /**
     * Whether to prioritize cache values over network results when
     * `fetchObservableWithInfo` is called.
     * This will essentially turn a `"network-only"` or `"cache-and-network"`
     * fetchPolicy into a `"cache-first"` fetchPolicy, but without influencing
     * the `fetchPolicy` of the `ObservableQuery`.
     *
     * This can e.g. be used to prioritize the cache during the first render after
     * SSR.
     */
    prioritizeCacheValues: boolean;
    private onBroadcast?;
    mutationStore?: {
        [mutationId: string]: MutationStoreValue;
    };
    private queries;
    protected fetchCancelFns: Map<string, (error: any) => any>;
    constructor(options: QueryManagerOptions);
    /**
     * Call this method to terminate any active query processes, making it safe
     * to dispose of this QueryManager instance.
     */
    stop(): void;
    private cancelPendingFetches;
    mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<MutateResult<MaybeMasked<TData>>>;
    markMutationResult<TData, TVariables extends OperationVariables, TContext, TCache extends ApolloCache>(mutation: {
        mutationId: string;
        result: FetchResult<TData>;
        document: DocumentNode;
        variables?: TVariables;
        fetchPolicy?: MutationFetchPolicy;
        errorPolicy: ErrorPolicy;
        context?: TContext;
        updateQueries: UpdateQueries<TData>;
        update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
        awaitRefetchQueries?: boolean;
        refetchQueries?: InternalRefetchQueriesInclude;
        removeOptimistic?: string;
        onQueryUpdated?: OnQueryUpdated<any>;
        keepRootFields?: boolean;
    }, cache?: ApolloCache): Promise<FetchResult<TData>>;
    markMutationOptimistic<TData, TVariables extends OperationVariables, TContext, TCache extends ApolloCache>(optimisticResponse: any, mutation: {
        mutationId: string;
        document: DocumentNode;
        variables?: TVariables;
        fetchPolicy?: MutationFetchPolicy;
        errorPolicy: ErrorPolicy;
        context?: TContext;
        updateQueries: UpdateQueries<TData>;
        update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
        keepRootFields?: boolean;
    }): boolean;
    fetchQuery<TData, TVars extends OperationVariables>(queryId: string, options: WatchQueryOptions<TVars, TData>, networkStatus?: NetworkStatus): Promise<QueryResult<TData>>;
    transform(document: DocumentNode): DocumentNode;
    private transformCache;
    getDocumentInfo(document: DocumentNode): TransformCacheEntry;
    private getVariables;
    watchQuery<T, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
    query<TData, TVars extends OperationVariables = OperationVariables>(options: QueryOptions<TVars, TData>, queryId?: string): Promise<QueryResult<MaybeMasked<TData>>>;
    private queryIdCounter;
    generateQueryId(): string;
    private requestIdCounter;
    generateRequestId(): number;
    private mutationIdCounter;
    generateMutationId(): string;
    clearStore(options?: Cache.ResetOptions): Promise<void>;
    getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
    reFetchObservableQueries(includeStandby?: boolean): Promise<QueryResult<any>[]>;
    startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<SubscribeResult<TData>>;
    stopQuery(queryId: string): void;
    removeQuery(queryId: string): void;
    broadcastQueries(): void;
    getLocalState(): LocalState;
    protected inFlightLinkObservables: Trie<{
        observable?: Observable<FetchResult<any>>;
    }>;
    private getObservableFromLink;
    private getResultsFromLink;
    fetchObservableWithInfo<TData, TVars extends OperationVariables>(queryInfo: QueryInfo, options: WatchQueryOptions<TVars, TData>, networkStatus?: NetworkStatus, query?: DocumentNode | import("@graphql-typed-document-node/core").TypedDocumentNode<TData, TVars>, emitLoadingState?: boolean): ObservableAndInfo<TData>;
    refetchQueries<TResult>({ updateCache, include, optimistic, removeOptimistic, onQueryUpdated, }: InternalRefetchQueriesOptions<ApolloCache, TResult>): InternalRefetchQueriesMap<TResult>;
    private noCacheWarningsByQueryId;
    maskOperation<TData = unknown>(options: MaskOperationOptions<TData>): MaybeMasked<TData>;
    maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
    private fetchQueryByPolicy;
    getOrCreateQuery(queryId: string): QueryInfo;
    private prepareContext;
}
export interface ObservableAndInfo<TData> {
    fromLink: boolean;
    observable: Observable<ApolloQueryResult<TData>>;
}
export {};
//# sourceMappingURL=QueryManager.d.ts.map
