import type { DocumentNode, FormattedExecutionResult } from "graphql";
import type { NextNotification, Observable, ObservableNotification } from "rxjs";
import type { ApolloCache } from "@apollo/client/cache";
import type { Cache } from "@apollo/client/cache";
import type { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
import type { Unmasked } from "@apollo/client/masking";
import type { DeepPartial, HKT } from "@apollo/client/utilities";
import type { ApplyHKTImplementationWithDefault, IsAny } from "@apollo/client/utilities/internal";
import type { NetworkStatus } from "./networkStatus.js";
import type { ObservableQuery } from "./ObservableQuery.js";
import type { QueryOptions } from "./watchQueryOptions.js";
export type { TypedDocumentNode } from "@graphql-typed-document-node/core";
export type MethodKeys<T> = {
    [P in keyof T]: T[P] extends Function ? P : never;
}[keyof T];
export interface TypeOverrides {
}
declare namespace OverridableTypes {
    export interface Defaults {
        Streaming: Streaming;
    }
    interface Streaming extends HKT {
        arg1: unknown;
        return: this["arg1"];
    }
    export {};
}
/**
 * Returns a representation of `TData` while it is streaming.
 *
 * @defaultValue `TData` if no overrides are provided.
 *
 * @example
 * You can override this type globally - this example shows how to override it
 * with `DeepPartial<TData>`:
 *
 * ```ts
 * import { HKT, DeepPartial } from "@apollo/client/utilities";
 *
 * type StreamingOverride<TData> = DeepPartial<TData>;
 *
 * interface StreamingOverrideHKT extends HKT {
 *   return: StreamingOverride<this["arg1"]>;
 * }
 *
 * declare module "@apollo/client" {
 *   export interface TypeOverrides {
 *     Streaming: StreamingOverrideHKT;
 *   }
 * }
 * ```
 */
export type Streaming<TData> = ApplyHKTImplementationWithDefault<TypeOverrides, "Streaming", OverridableTypes.Defaults, TData>;
export interface DefaultContext extends Record<string, any> {
    /**
     * Indicates whether `queryDeduplication` was enabled for the request.
     */
    queryDeduplication?: boolean;
    clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;
}
/**
 * Represents an `Error` type, but used throughout Apollo Client to represent
 * errors that may otherwise fail `instanceof` checks if they are cross-realm
 * Error instances (see the [`Error.isError` proposal](https://github.com/tc39/proposal-is-error) for more details).
 *
 * Apollo Client uses several types of errors throughout the client which can be
 * narrowed using `instanceof`:
 * - `CombinedGraphQLErrors` - `errors` returned from a GraphQL result
 * - `CombinedProtocolErrors` - Transport-level errors from multipart subscriptions.
 * - `ServerParseError` - A JSON-parse error when parsing the server response.
 * - `ServerError` - A non-200 server response.
 *
 * @example
 * ```ts
 * import { CombinedGraphQLErrors } from "@apollo/client";
 *
 * try {
 *   await client.query({ query });
 * } catch (error) {
 *   // Use `instanceof` to check for more specific types of errors.
 *   if (error instanceof CombinedGraphQLErrors) {
 *     error.errors.map(graphQLError => console.log(graphQLError.message));
 *   } else {
 *     console.error(errors);
 *   }
 * }
 * ```
 */
export interface ErrorLike {
    message: string;
    name: string;
    stack?: string;
}
export type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache.DiffResult<any>, lastDiff: Cache.DiffResult<any> | undefined) => boolean | TResult;
export type RefetchQueryDescriptor = string | DocumentNode;
export type InternalRefetchQueryDescriptor = RefetchQueryDescriptor | QueryOptions;
type RefetchQueriesIncludeShorthand = "all" | "active";
export type RefetchQueriesInclude = RefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand;
export type InternalRefetchQueriesInclude = InternalRefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand;
export interface RefetchQueriesOptions<TCache extends ApolloCache, TResult> {
    updateCache?: (cache: TCache) => void;
    include?: RefetchQueriesInclude;
    optimistic?: boolean;
    onQueryUpdated?: OnQueryUpdated<TResult> | null;
}
export type RefetchQueriesPromiseResults<TResult> = IsAny<TResult> extends true ? any[] : TResult extends boolean ? QueryResult<any>[] : TResult extends PromiseLike<infer U> ? U[] : TResult[];
export interface RefetchQueriesResult<TResult> extends Promise<RefetchQueriesPromiseResults<TResult>> {
    queries: ObservableQuery<any>[];
    results: InternalRefetchQueriesResult<TResult>[];
}
export interface InternalRefetchQueriesOptions<TCache extends ApolloCache, TResult> extends Omit<RefetchQueriesOptions<TCache, TResult>, "include"> {
    include?: InternalRefetchQueriesInclude;
    removeOptimistic?: string;
}
export type InternalRefetchQueriesResult<TResult> = TResult extends boolean ? Promise<QueryResult<any>> : TResult;
export type InternalRefetchQueriesMap<TResult> = Map<ObservableQuery<any>, InternalRefetchQueriesResult<TResult>>;
export type OperationVariables = Record<string, any>;
export type ApolloQueryResult<TData, TStates extends DataState<TData>["dataState"] = DataState<TData>["dataState"]> = {
    /**
     * The single Error object that is passed to onError and useQuery hooks, and is often thrown during manual `client.query` calls.
     * This will contain both a NetworkError field and any GraphQLErrors.
     * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
     */
    error?: ErrorLike;
    loading: boolean;
    networkStatus: NetworkStatus;
    /**
     * Describes whether `data` is a complete or partial result. This flag is only
     * set when `returnPartialData` is `true` in query options.
     *
     * @deprecated This field will be removed in a future version of Apollo Client.
     */
    partial: boolean;
} & GetDataState<TData, TStates>;
export type DataState<TData> = {
    data: TData;
    /**
    * Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
    */
    dataState: "complete";
} | {
    data: Streaming<TData>;
    /**
    * Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
    */
    dataState: "streaming";
} | {
    data: DeepPartial<TData>;
    /**
    * Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
    */
    dataState: "partial";
} | {
    data: undefined;
    /**
    * Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
    */
    dataState: "empty";
};
export type GetDataState<TData, TState extends DataState<TData>["dataState"]> = Extract<DataState<TData>, {
    dataState: TState;
}>;
/**
 * Represents a result that might be complete or still streaming and
 * has been normalized into a plain GraphQL result. When the result is
 * still `streaming`, some fields might not yet be available.
 */
export type NormalizedExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = Omit<FormattedExecutionResult<TData, TExtensions>, "data"> & ({
    data: TData;
    /**
    * Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
    */
    dataState: "complete";
} | {
    data: Streaming<TData>;
    /**
    * Describes the completeness of `data`. - `empty`: No data could be fulfilled from the cache or the result is incomplete. `data` is `undefined`. - `partial`: Some data could be fulfilled from the cache but `data` is incomplete. This is only possible when `returnPartialData` is `true`. - `streaming`: `data` is incomplete as a result of a deferred query and the result is still streaming in. - `complete`: `data` is a fully satisfied query result fulfilled either from the cache or network.
    */
    dataState: "streaming";
});
export type MutationQueryReducer<T> = (previousResult: Record<string, any>, options: {
    mutationResult: NormalizedExecutionResult<Unmasked<T>>;
    queryName: string | undefined;
    queryVariables: Record<string, any>;
}) => Record<string, any>;
export type MutationQueryReducersMap<T = {
    [key: string]: any;
}> = {
    [queryName: string]: MutationQueryReducer<T>;
};
export type MutationUpdaterFunction<TData, TVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
    context?: DefaultContext;
    variables?: TVariables;
}) => void;
export interface MutateResult<TData = unknown> {
    /**
    * The data returned from your mutation. Can be `undefined` if `ignoreResults` is `true`.
    */
    data: TData | undefined;
    /**
    * If the mutation produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
    * 
    * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
    */
    error?: ErrorLike;
    /**
    * Custom extensions returned from the GraphQL server
    */
    extensions?: Record<string, unknown>;
}
export interface SubscribeResult<TData = unknown> {
    /**
    * The data returned from your mutation. Can be `undefined` if `ignoreResults` is `true`.
    */
    data: TData | undefined;
    /**
    * If the mutation produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
    * 
    * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
    */
    error?: ErrorLike;
    /**
    * Custom extensions returned from the GraphQL server
    */
    extensions?: Record<string, unknown>;
}
export interface QueryResult<TData = unknown> {
    /**
    * An object containing the result of your GraphQL query after it completes.
    * 
    * This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
    * 
    * @docGroup
    * 
    * 1. Operation data
    */
    data: TData | undefined;
    /**
    * If the query produces one or more errors, this object contains either an array of `graphQLErrors` or a single `networkError`. Otherwise, this value is `undefined`.
    * 
    * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
    * 
    * @docGroup
    * 
    * 1. Operation data
    */
    error?: ErrorLike;
}
export declare namespace QueryNotification {
    type NewNetworkStatus<TData> = NextNotification<{
        resetError?: boolean;
    }> & {
        source: "newNetworkStatus";
    };
    type SetResult<TData> = NextNotification<ApolloQueryResult<TData>> & {
        source: "setResult";
    };
    type FromNetwork<TData> = ObservableNotification<ApolloQueryResult<TData>> & {
        source: "network";
    };
    type FromCache<TData> = NextNotification<ApolloQueryResult<TData>> & {
        source: "cache";
    };
    type Value<TData> = FromCache<TData> | FromNetwork<TData> | NewNetworkStatus<TData> | SetResult<TData>;
}
/** Observable created by initiating a subscription operation. */
export interface SubscriptionObservable<T> extends Observable<T> {
    /**
     * Used to restart the connection to the link chain. Calling this on a
     * deduplicated subscription will restart the connection for all observables
     * that share the request.
     *
     * @example
     *
     * ```ts
     * const observable = client.subscribe({ query: subscription });
     * observable.subscribe((value) => {
     *   // ...
     * });
     *
     * observable.restart();
     * ```
     */
    restart: () => void;
}
//# sourceMappingURL=types.d.ts.map
