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 { ApolloClient } from "./ApolloClient.js"; import type { ObservableQuery } from "./ObservableQuery.js"; export type { TypedDocumentNode } from "@graphql-typed-document-node/core"; export interface TypeOverrides { } declare namespace OverridableTypes { interface Defaults { Complete: Complete; Streaming: Streaming; Partial: Partial; } interface Complete extends HKT { arg1: unknown; return: this["arg1"]; } interface Streaming extends HKT { arg1: unknown; return: this["arg1"]; } interface Partial extends HKT { arg1: unknown; return: DeepPartial; } } export declare namespace DataValue { /** * Returns a representation of `TData` in it's "complete" state. * * @defaultValue `TData` if no overrides are provided. * * @example * You can override this type globally - this example shows how to override it * with `DeepPartial`: * * ```ts * import { HKT, DeepPartial } from "@apollo/client/utilities"; * * type CompleteOverride = * TData extends { _complete?: infer _Complete } ? _Complete : TData; * * interface CompleteOverrideHKT extends HKT { * return: CompleteOverride; * } * * declare module "@apollo/client" { * export interface TypeOverrides { * Complete: CompleteOverrideHKT; * } * } * ``` */ type Complete = ApplyHKTImplementationWithDefault; /** * 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`: * * ```ts * import { HKT, DeepPartial } from "@apollo/client/utilities"; * * type StreamingOverride = DeepPartial; * * interface StreamingOverrideHKT extends HKT { * return: StreamingOverride; * } * * declare module "@apollo/client" { * export interface TypeOverrides { * Streaming: StreamingOverrideHKT; * } * } * ``` */ type Streaming = ApplyHKTImplementationWithDefault; /** * Returns a representation of `TData` while it is partial. * * @defaultValue `DeepPartial` if no overrides are provided. * * @example * You can override this type globally - this example shows how to override it * with `DeepPartial`: * * ```ts * import { HKT, DeepPartial } from "@apollo/client/utilities"; * * type PartialOverride = DeepPartial>; * * interface PartialOverrideHKT extends HKT { * return: PartialOverride; * } * * declare module "@apollo/client" { * export interface TypeOverrides { * Partial: PartialOverrideHKT; * } * } * ``` */ type Partial = ApplyHKTImplementationWithDefault; } export interface DefaultContext extends Record { /** * 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 = (observableQuery: ObservableQuery, diff: Cache.DiffResult, lastDiff: Cache.DiffResult | undefined) => boolean | TResult; export type RefetchQueryDescriptor = string | DocumentNode; export type InternalRefetchQueryDescriptor = RefetchQueryDescriptor | ApolloClient.QueryOptions; type RefetchQueriesIncludeShorthand = "all" | "active"; export type RefetchQueriesInclude = RefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand; export type InternalRefetchQueriesInclude = InternalRefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand; export type RefetchQueriesPromiseResults = IsAny extends true ? any[] : TResult extends boolean ? ApolloClient.QueryResult[] : TResult extends PromiseLike ? U[] : TResult[]; export interface InternalRefetchQueriesOptions extends Omit, "include"> { include?: InternalRefetchQueriesInclude; removeOptimistic?: string; } export type InternalRefetchQueriesResult = TResult extends boolean ? Promise> : TResult; export type InternalRefetchQueriesMap = Map, InternalRefetchQueriesResult>; export type OperationVariables = Record; export type DataState = { /** * 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: DataValue.Complete; /** * 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. * * @docGroup 1. Operation data */ dataState: "complete"; } | { /** * 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: DataValue.Streaming; /** * 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. * * @docGroup 1. Operation data */ dataState: "streaming"; } | { /** * 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: DataValue.Partial; /** * 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. * * @docGroup 1. Operation data */ dataState: "partial"; } | { /** * 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: 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. * * @docGroup 1. Operation data */ dataState: "empty"; }; export type GetDataState["dataState"]> = Extract, { 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, TExtensions = Record> = Omit, "data"> & GetDataState; export type MutationQueryReducer = (previousResult: Record, options: { mutationResult: NormalizedExecutionResult>; queryName: string | undefined; queryVariables: Record; }) => Record; export type MutationQueryReducersMap = { [queryName: string]: MutationQueryReducer; }; export type MutationUpdaterFunction = (cache: TCache, result: FormattedExecutionResult>, options: { context?: DefaultContext; variables?: TVariables; }) => void; export declare namespace QueryNotification { type NewNetworkStatus = NextNotification<{ resetError?: boolean; }> & { source: "newNetworkStatus"; }; type SetResult = NextNotification> & { source: "setResult"; }; type FromNetwork = ObservableNotification> & { source: "network"; }; type FromCache = NextNotification> & { source: "cache"; }; type Value = FromCache | FromNetwork | NewNetworkStatus | SetResult; } /** Observable created by initiating a subscription operation. */ export interface SubscriptionObservable extends Observable { /** * 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