UNPKG

@apollo-orbit/angular

Version:

A full-featured GraphQL client for Angular

1,125 lines (1,108 loc) 51.5 kB
import { ApolloCache, OperationVariables, DocumentNode, TypedDocumentNode, MissingFieldError, DataState, ErrorLike, NetworkStatus, GetDataState, SubscribeToMoreUpdateQueryFn, DefaultContext, Unmasked, MutationQueryReducersMap, NormalizedExecutionResult, InternalRefetchQueriesInclude, MutationUpdaterFunction, OnQueryUpdated, ErrorPolicy, MutationFetchPolicy, WatchQueryFetchPolicy, ApolloClient, RefetchWritePolicy, FetchPolicy, ObservableQuery, UpdateQueryMapFn, StoreObject, Reference, FragmentType } from '@apollo/client'; export { ApolloCache, ApolloClient, Cache, CombinedGraphQLErrors, CombinedProtocolErrors, DataState, DefaultContext, DocumentNode, ErrorLike, ErrorPolicy, FetchPolicy, GetDataState, InMemoryCache, LinkError, MissingFieldError, NetworkStatus, NormalizedCache, NormalizedCacheObject, OperationVariables, ServerError, ServerParseError, StoreObject, TypedDocumentNode, UnconventionalError, UpdateQueryOptions, gql } from '@apollo/client'; import { DeepPartial } from '@apollo/client/utilities'; export { DeepPartial } from '@apollo/client/utilities'; import { Observable, OperatorFunction } from 'rxjs'; import { IgnoreModifier, MissingTree } from '@apollo/client/cache'; import { VariablesOption } from '@apollo/client/utilities/internal'; import * as i0 from '@angular/core'; import { Injector, Signal, WritableSignal, InjectionToken, Type, Provider, EnvironmentProviders } from '@angular/core'; interface CacheWatchQueryOptions<TData, TVariables> { query: DocumentNode | TypedDocumentNode<TData, TVariables>; variables?: TVariables; optimistic?: boolean; immediate?: boolean; /** * If set to true, the observable will emit the partial data that is available in the cache. * If set to false, the observable will throw an error if the complete data is not available in the cache. * @default false */ returnPartialData?: boolean; } interface CacheWatchQueryCompleteResult<TData> { data: TData; complete: true; missing?: never; } interface CacheWatchQueryPartialResult<TData> { data: DeepPartial<TData> | undefined; complete: false; missing?: Array<MissingFieldError>; } type CacheWatchQueryResult<TData> = CacheWatchQueryCompleteResult<TData> | CacheWatchQueryPartialResult<TData>; interface ApolloCacheEx extends ApolloCache { /** * Watches the cache store for the query document provided. */ watchQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: CacheWatchQueryOptions<TData, TVariables> & { returnPartialData: true; }): Observable<CacheWatchQueryPartialResult<TData>>; watchQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: CacheWatchQueryOptions<TData, TVariables>): Observable<CacheWatchQueryCompleteResult<TData>>; } interface ApolloOptions extends ApolloClient.Options { /** * Client identifier in a multi-client setup */ id?: string; defaultOptions?: DefaultOptions; } interface DefaultOptions { watchQuery?: Partial<WatchQueryOptions<any, any>>; query?: Partial<QueryOptions<any, any>>; mutate?: Partial<MutationOptions<any, any, any>>; } type WatchQueryOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = { /** * Specifies how the query interacts with the Apollo Client cache during execution (for example, whether it checks the cache for results before sending a request to the server). * * For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy). * * The default value is `cache-first`. * * @docGroup 3. Caching options */ fetchPolicy?: WatchQueryFetchPolicy; /** * Specifies the `FetchPolicy` to be used after this query has completed. * * @docGroup 3. Caching options */ nextFetchPolicy?: ApolloClient.WatchQueryOptions<TData, TVariables>['nextFetchPolicy']; /** * Defaults to the initial value of options.fetchPolicy, but can be explicitly * configured to specify the WatchQueryFetchPolicy to revert back to whenever * variables change (unless nextFetchPolicy intervenes). * * @docGroup 3. Caching options */ initialFetchPolicy?: WatchQueryFetchPolicy; /** * Specifies whether a `NetworkStatus.refetch` operation should merge * incoming field data with existing data, or overwrite the existing data. * Overwriting is probably preferable, but merging is currently the default * behavior, for backwards compatibility with Apollo Client 3.x. * * @docGroup 3. Caching options */ refetchWritePolicy?: RefetchWritePolicy; /** * Specifies how the query handles a response that returns both GraphQL errors and partial results. * * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies). * * The default value is `none`, meaning that the query result includes error details but not partial results. * * @docGroup 1. Operation options */ errorPolicy?: ErrorPolicy; /** * If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain. * * @docGroup 2. Networking options */ context?: DefaultContext; /** * Specifies the interval (in milliseconds) at which the query polls for updated results. * * The default value is `0` (no polling). * * @docGroup 2. Networking options */ pollInterval?: number; /** * If `true`, the in-progress query's associated component re-renders whenever the network status changes or a network error occurs. * * The default value is `true`. * * @docGroup 2. Networking options */ notifyOnNetworkStatusChange?: boolean; /** * If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields. * * The default value is `false`. * * @docGroup 3. Caching options */ returnPartialData?: boolean; /** * A callback function that's called whenever a refetch attempt occurs * while polling. If the function returns `true`, the refetch is * skipped and not reattempted until the next poll interval. * * @docGroup 2. Networking options */ skipPollAttempt?: () => boolean; /** * A GraphQL query string parsed into an AST with the gql template literal. * * @docGroup 1. Operation options */ query: DocumentNode | TypedDocumentNode<TData, TVariables>; /** * Whether or not observers should receive initial network loading status when subscribing to this observable. * @default true */ notifyOnLoading?: boolean; } & VariablesOption<NoInfer<TVariables>>; type QueryOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = { /** * A GraphQL query string parsed into an AST with the gql template literal. * * @docGroup 1. Operation options */ query: DocumentNode | TypedDocumentNode<TData, TVariables>; /** * Specifies how the query handles a response that returns both GraphQL errors and partial results. * * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies). * * The default value is `none`, meaning that the query result includes error details but not partial results. * * @docGroup 1. Operation options */ errorPolicy?: ErrorPolicy; /** * If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain. * * @docGroup 2. Networking options */ context?: DefaultContext; /** * Specifies how the query interacts with the Apollo Client cache during execution (for example, whether it checks the cache for results before sending a request to the server). * * For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy). * * The default value is `cache-first`. * * @docGroup 3. Caching options */ fetchPolicy?: FetchPolicy; /** * Whether or not observers should receive initial network loading status when subscribing to this observable. * @default false */ notifyOnLoading?: boolean; /** * Throw errors on the observable's error stream instead of assigning them to the error property of the result object. * @default true */ throwError?: boolean; } & VariablesOption<NoInfer<TVariables>>; type SubscriptionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = { /** * A GraphQL document, often created with `gql` from the `graphql-tag` * package, that contains a single subscription inside of it. */ subscription: DocumentNode | TypedDocumentNode<TData, TVariables>; /** * How you want your component to interact with the Apollo cache. For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy). */ fetchPolicy?: FetchPolicy; /** * Specifies the `ErrorPolicy` to be used for this operation */ errorPolicy?: ErrorPolicy; /** * Shared context between your component and your network interface (Apollo Link). */ context?: DefaultContext; /** * Shared context between your component and your network interface (Apollo Link). */ extensions?: Record<string, any>; } & VariablesOption<NoInfer<TVariables>>; type MutationOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = { /** * By providing either an object or a callback function that, when invoked after * a mutation, allows you to return optimistic data and optionally skip updates * via the `IGNORE` sentinel object, Apollo Client caches this temporary * (and potentially incorrect) response until the mutation completes, enabling * more responsive UI updates. * * For more information, see [Optimistic mutation results](https://www.apollographql.com/docs/react/performance/optimistic-ui/). * * @docGroup 3. Caching options */ optimisticResponse?: Unmasked<NoInfer<TData>> | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; }) => Unmasked<NoInfer<TData>> | IgnoreModifier); /** * A `MutationQueryReducersMap`, which is map from query names to * mutation query reducers. Briefly, this map defines how to incorporate the * results of the mutation into the results of queries that are currently * being watched by your application. */ updateQueries?: MutationQueryReducersMap<TData>; /** * An array (or a function that _returns_ an array) that specifies which queries you want to refetch after the mutation occurs. * * Each array value can be either: * * - An object containing the `query` to execute, along with any `variables` * * - A string indicating the operation name of the query to refetch * * @docGroup 1. Operation options */ refetchQueries?: ((result: NormalizedExecutionResult<Unmasked<TData>>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; /** * If `true`, makes sure all queries included in `refetchQueries` are completed before the mutation is considered complete. * * The default value is `false` (queries are refetched asynchronously). * * @docGroup 1. Operation options */ awaitRefetchQueries?: boolean; /** * A function used to update the Apollo Client cache after the mutation completes. * * For more information, see [Updating the cache after a mutation](https://www.apollographql.com/docs/react/data/mutations#updating-the-cache-after-a-mutation). * * @docGroup 3. Caching options */ update?: MutationUpdaterFunction<TData, TVariables, TCache>; /** * Optional callback for intercepting queries whose cache data has been updated by the mutation, as well as any queries specified in the `refetchQueries: [...]` list passed to `client.mutate`. * * Returning a `Promise` from `onQueryUpdated` will cause the final mutation `Promise` to await the returned `Promise`. Returning `false` causes the query to be ignored. * * @docGroup 1. Operation options */ onQueryUpdated?: OnQueryUpdated<any>; /** * Specifies how the mutation handles a response that returns both GraphQL errors and partial results. * * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies). * * The default value is `none`, meaning that the mutation result includes error details but _not_ partial results. * * @docGroup 1. Operation options */ errorPolicy?: ErrorPolicy; /** * If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain. * * @docGroup 2. Networking options */ context?: DefaultContext; /** * Provide `no-cache` if the mutation's result should _not_ be written to the Apollo Client cache. * * The default value is `network-only` (which means the result _is_ written to the cache). * * Unlike queries, mutations _do not_ support [fetch policies](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy) besides `network-only` and `no-cache`. * * @docGroup 3. Caching options */ fetchPolicy?: MutationFetchPolicy; /** * To avoid retaining sensitive information from mutation root field * arguments, Apollo Client v3.4+ automatically clears any `ROOT_MUTATION` * fields from the cache after each mutation finishes. If you need this * information to remain in the cache, you can prevent the removal by passing * `keepRootFields: true` to the mutation. `ROOT_MUTATION` result data are * also passed to the mutation `update` function, so we recommend obtaining * the results that way, rather than using this option, if possible. */ keepRootFields?: boolean; /** * A GraphQL document, often created with `gql` from the `graphql-tag` * package, that contains a single mutation inside of it. * * @docGroup 1. Operation options */ mutation: DocumentNode | TypedDocumentNode<TData, TVariables>; } & VariablesOption<NoInfer<TVariables>>; interface ExtraWatchQueryOptions { /** * Whether or not observers should receive initial network loading status when subscribing to this observable. * @default true */ notifyOnLoading?: boolean; } interface ExtraQueryOptions { /** * Whether or not observers should receive initial network loading status when subscribing to this observable. * @default true */ notifyOnLoading?: boolean; /** * Throw errors on the observable's error stream instead of assigning them to the error property of the result object. * @default true */ throwError?: boolean; } interface SubscribeToMoreOptions<TData = unknown, TSubscriptionVariables extends OperationVariables = OperationVariables, TSubscriptionData = TData, TVariables extends OperationVariables = TSubscriptionVariables> { subscription: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>; variables?: TSubscriptionVariables; updateQuery?: SubscribeToMoreUpdateQueryFn<TData, TVariables, TSubscriptionData>; onError?: (error: ErrorLike) => void; context?: DefaultContext; } type QueryResult<TData, TStates extends DataState<TData>['dataState'] = DataState<TData>['dataState']> = { /** * A single ErrorLike object describing the error that occurred during the latest * query execution. * * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/). * * @docGroup 1. Operation data */ error?: ErrorLike; /** * If `true`, the query is still in flight. * * @docGroup 2. Network info */ loading: boolean; /** * A number indicating the current network state of the query's associated request. [See possible values.](https://github.com/apollographql/apollo-client/blob/d96f4578f89b933c281bb775a39503f6cdb59ee8/src/core/networkStatus.ts#L4) * * Used in conjunction with the [`notifyOnNetworkStatusChange`](#notifyonnetworkstatuschange) option. * * @docGroup 2. Network info */ networkStatus: NetworkStatus; /** * An object containing the result from the most recent _previous_ execution of this query. * * This value is `undefined` if this is the query's first execution. */ previousData?: GetData<TData, TStates>; } & GetDataState<TData, TStates>; type GetData<TData, TState extends DataState<TData>['dataState']> = GetDataState<TData, TState>['data']; interface SingleQueryResult<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; /** * A single ErrorLike object describing the error that occurred during the latest * query execution. * * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/). * * @docGroup 1. Operation data */ error?: ErrorLike; } interface MutationResult<TData = unknown> { data: TData | undefined; error?: ErrorLike; extensions?: Record<string, any>; } interface SubscriptionResult<TData = unknown> { data?: TData; error?: ErrorLike; extensions?: Record<string, any>; } declare class QueryObservable<TData = unknown, TVariables extends OperationVariables = OperationVariables, TStates extends DataState<TData>['dataState'] = DataState<TData>['dataState']> extends Observable<QueryResult<TData, TStates>> { private readonly observableQuery; private previousData; constructor(observableQuery: ObservableQuery<TData, TVariables>, { notifyOnLoading }: ExtraWatchQueryOptions); get query(): TypedDocumentNode<TData, TVariables>; get variables(): TVariables | undefined; get options(): ObservableQuery.Options<TData, TVariables>; get queryName(): string | undefined; getCurrentResult(): QueryResult<TData, TStates>; /** * Update the variables of this observable query, and fetch the new results. * This method should be preferred over `setVariables` in most use cases. * * Returns a `ResultPromise` with an additional `.retain()` method. Calling * `.retain()` keeps the network operation running even if the `ObservableQuery` * no longer requires the result. * * Note: `refetch()` guarantees that a value will be emitted from the * observable, even if the result is deep equal to the previous value. * * @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<SingleQueryResult<TData>>; fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>): Promise<SingleQueryResult<TFetchData>>; subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => 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: `setVariables()` guarantees that a value will be emitted from the * observable, even if the result is deeply equal to the previous value. * * Note: the promise will resolve with the last emitted result * when either the variables match the current variables or there * are no subscribers to the query. * * @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<SingleQueryResult<TData>>; /** * A function that enables you to update the query's cached result without executing a followup GraphQL operation. * * See [using updateQuery and updateFragment](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-updatequery-and-updatefragment) for additional information. */ updateQuery(mapFn: UpdateQueryMapFn<TData, TVariables>): void; /** * A function that instructs the query to begin re-executing at a specified interval (in milliseconds). */ startPolling(pollInterval: number): void; /** * A function that instructs the query to stop polling after a previous call to `startPolling`. */ stopPolling(): void; /** * Reevaluate the query, optionally against new options. New options will be * merged with the current options when given. * * Note: `variables` can be reset back to their defaults (typically empty) by calling `reobserve` with * `variables: undefined`. */ reobserve(newOptions?: Partial<WatchQueryOptions<TData, TVariables>>): Promise<SingleQueryResult<TData>>; hasObservers(): boolean; /** * Tears down the `ObservableQuery` and stops all active operations by sending a `complete` notification. */ stop(): void; } interface SignalCacheQueryOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> { /** * A GraphQL query document parsed into an AST by gql. */ query: DocumentNode | TypedDocumentNode<TData, TVariables>; /** * An object containing all of the variables your query needs to execute. * Can be provided as a static object, a signal, or a function that returns the variables. * When provided as a function, it will be executed in a computed context and will * automatically re-execute the query when any reactive dependencies change. */ variables?: NoInfer<TVariables> | (() => NoInfer<TVariables>); /** * If `true`, the query will be evaluated against both the optimistic cache layer * and the normal cache layer. This allows optimistic updates to be reflected * in the query results immediately. * @default true */ optimistic?: boolean; immediate?: boolean; /** * If set to `true`, the observable will emit the partial data that is available in the cache. * If set to `false`, the observable will throw an error if the complete data is not available in the cache. * @default false */ returnPartialData?: boolean; /** * Custom injector to use for this signal. */ injector?: Injector; } type SignalCacheQueryResult<TData> = TData extends undefined ? CacheWatchQueryPartialResult<TData> : CacheWatchQueryCompleteResult<TData>; declare class SignalCacheQuery<TData, TVariables extends OperationVariables = OperationVariables> { private readonly cache; private readonly options; /** * The cache query result, containing `data`, `complete`, and `missing`. */ readonly result: Signal<SignalCacheQueryResult<TData>>; /** * The data returned by the cache query. */ readonly data: Signal<TData>; /** * A signal indicating whether the query result contains complete data. * - `true`: All requested fields are available in the cache * - `false`: Some fields are missing from the cache * - `undefined`: Query has not been executed yet */ readonly complete: Signal<boolean | undefined>; /** * A signal containing an array of missing field errors if the query is incomplete. * Will be `undefined` if the query is complete or has not been executed. */ readonly missing: Signal<Array<MissingFieldError> | undefined>; private readonly _result; private readonly variables; private subscription; constructor(injector: Injector, cache: ApolloCacheEx, options: SignalCacheQueryOptions<TData, TVariables>); private subscribe; } type SignalFragmentResult<TData> = { data: TData; complete: true; missing?: never; } | { data: DeepPartial<TData>; complete: false; missing?: MissingTree; }; interface SignalFragmentOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> { /** * A GraphQL fragment document parsed into an AST with the `gql` * template literal. * * @docGroup 1. Required options */ fragment: DocumentNode | TypedDocumentNode<TData, TVariables>; /** * An object containing a `__typename` and primary key fields * (such as `id`) identifying the entity object from which the fragment will * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID * (uncommon). * * @docGroup 1. Required options */ from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string | (() => StoreObject | Reference | FragmentType<NoInfer<TData>> | string); /** * Any variables that the GraphQL fragment may depend on. * * @docGroup 2. Cache options */ variables?: NoInfer<TVariables> | (() => NoInfer<TVariables>); /** * The name of the fragment defined in the fragment document. * * Required if the fragment document includes more than one fragment, * optional otherwise. * * @docGroup 2. Cache options */ fragmentName?: string; /** * If `true`, `watchFragment` returns optimistic results. * * The default value is `true`. * * @docGroup 2. Cache options */ optimistic?: boolean; /** * Custom injector to use for this signal. */ injector?: Injector; } declare class SignalFragment<TData, TVariables extends OperationVariables = OperationVariables> { private readonly apollo; private readonly options; /** * The fragment result, containing `data`, `complete`, and `missing`. */ readonly result: Signal<SignalFragmentResult<TData>>; /** * The data returned by the fragment. */ readonly data: Signal<DeepPartial<TData>>; /** * `true` if all requested fields in the fragment are present in the cache, `false` otherwise. */ readonly complete: Signal<boolean>; /** * If `complete` is `false`, this field describes which fields are missing. */ readonly missing: Signal<MissingTree | undefined>; private readonly _result; private readonly from; private readonly variables; private subscription; constructor(injector: Injector, apollo: Apollo, options: SignalFragmentOptions<TData, TVariables>); private subscribe; } interface SignalMutationResult<TData> extends MutationResult<TData> { loading: boolean; called: boolean; } type SignalMutationOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = Omit<SignalMutationExecutionOptions<TData, TVariables>, 'variables'>; type SignalMutationExecutionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = Omit<MutationOptions<TData, TVariables>, 'mutation'> & { /** * Callback executed when the mutation completes successfully. */ onData?: (data: TData, options?: MutationOptions<TData, TVariables>) => void; /** * Callback executed when the mutation encounters an error. */ onError?: (error: ErrorLike, options?: MutationOptions<TData, TVariables>) => void; }; declare class SignalMutation<TData, TVariables extends OperationVariables = OperationVariables> { private readonly apollo; private readonly mutation; private readonly options?; /** * The mutation result, containing `data`, `loading`, and `error` and `called`. */ readonly result: Signal<SignalMutationResult<TData>>; /** * If `true`, the mutation is currently in flight. */ readonly loading: Signal<boolean>; /** * The data returned from the mutation. */ readonly data: Signal<TData | undefined>; /** * The error encountered during the mutation. */ readonly error: Signal<ErrorLike | undefined>; /** * If `true`, the mutation's mutate method has been called. */ readonly called: Signal<boolean>; private readonly _result; private mutationId; constructor(apollo: Apollo, mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SignalMutationOptions<TData, TVariables> | undefined); /** * Execute the mutation with the provided variables and options. */ mutate(...[executeOptions]: {} extends TVariables ? [executeOptions?: SignalMutationExecutionOptions<TData, TVariables>] : [executeOptions: SignalMutationExecutionOptions<TData, TVariables>]): Promise<MutationResult<TData>>; /** * Reset the mutation result to its initial state. */ reset(): void; } type SignalVariablesOption<TVariables extends OperationVariables> = {} extends TVariables ? { /** * A function or signal returning an object containing all of the GraphQL variables your operation requires to execute. * * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value. * * When `null` is returned, the operation will be terminated until a non-null value is returned again. */ variables?: () => TVariables | undefined | null; } : { /** * A function or signal returning an object containing all of the GraphQL variables your operation requires to execute. * * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value. * * When `null` is returned, the operation will be terminated until a non-null value is returned again. */ variables: () => TVariables | null; }; declare class SignalQueryExecutionError extends Error { constructor(methodName: keyof SignalQuery<any, any>); } type SignalQueryOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = { /** * Specifies how the query interacts with the Apollo Client cache during execution (for example, whether it checks the cache for results before sending a request to the server). * * For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy). * * The default value is `cache-first`. * * @docGroup 3. Caching options */ fetchPolicy?: WatchQueryFetchPolicy; /** * Specifies the `FetchPolicy` to be used after this query has completed. * * @docGroup 3. Caching options */ nextFetchPolicy?: ApolloClient.WatchQueryOptions<TData, TVariables>['nextFetchPolicy']; /** * Defaults to the initial value of options.fetchPolicy, but can be explicitly * configured to specify the WatchQueryFetchPolicy to revert back to whenever * variables change (unless nextFetchPolicy intervenes). * * @docGroup 3. Caching options */ initialFetchPolicy?: WatchQueryFetchPolicy; /** * Specifies whether a `NetworkStatus.refetch` operation should merge * incoming field data with existing data, or overwrite the existing data. * Overwriting is probably preferable, but merging is currently the default * behavior, for backwards compatibility with Apollo Client 3.x. * * @docGroup 3. Caching options */ refetchWritePolicy?: RefetchWritePolicy; /** * Specifies how the query handles a response that returns both GraphQL errors and partial results. * * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies). * * The default value is `none`, meaning that the query result includes error details but not partial results. * * @docGroup 1. Operation options */ errorPolicy?: ErrorPolicy; /** * If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain. * * @docGroup 2. Networking options */ context?: DefaultContext; /** * Specifies the interval (in milliseconds) at which the query polls for updated results. * * The default value is `0` (no polling). * * @docGroup 2. Networking options */ pollInterval?: number; /** * If `true`, the in-progress query's associated component re-renders whenever the network status changes or a network error occurs. * * The default value is `true`. * * @docGroup 2. Networking options */ notifyOnNetworkStatusChange?: boolean; /** * If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields. * * The default value is `false`. * * @docGroup 3. Caching options */ returnPartialData?: boolean; /** * A callback function that's called whenever a refetch attempt occurs * while polling. If the function returns `true`, the refetch is * skipped and not reattempted until the next poll interval. * * @docGroup 2. Networking options */ skipPollAttempt?: () => boolean; /** * A GraphQL query string parsed into an AST with the gql template literal. * * @docGroup 1. Operation options */ query: DocumentNode | TypedDocumentNode<TData, TVariables>; /** * Whether or not to track initial network loading status. * @default true */ notifyOnLoading?: boolean; /** * Whether to execute query immediately or lazily via `execute` method. */ lazy?: boolean; /** * Custom injector to use for this query. */ injector?: Injector; } & ({ /** * Whether to execute query immediately or lazily via `execute` method. */ lazy: true; /** * A function or signal returning an object containing all of the GraphQL variables your query requires to execute. * * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value. * * When `null` is returned, the query will be terminated until a non-null value is returned again. */ variables?: () => TVariables | undefined | null; } | SignalVariablesOption<NoInfer<TVariables>>); interface SignalQueryExecOptions<TVariables extends OperationVariables = OperationVariables> { /** * Variables to use for this query execution. */ variables?: TVariables; /** * Context to use for this execution. */ context?: DefaultContext; } declare class SignalQuery<TData, TVariables extends OperationVariables = OperationVariables, TStates extends DataState<TData>['dataState'] = 'empty' | 'complete' | 'streaming'> { private readonly apollo; private readonly options; /** * The query result, containing `data`, `loading`, `error`, `networkStatus`, `previousData`, `dataState`. */ readonly result: Signal<QueryResult<TData, TStates>>; /** * If `true`, the query is currently in flight. */ readonly loading: Signal<boolean>; /** * The current network status of the query. */ readonly networkStatus: Signal<NetworkStatus>; /** * The data returned by the query, or `undefined` if loading, errored, or no data received yet. */ readonly data: Signal<GetData<TData, TStates> | undefined>; /** * The data from the previous successful result, useful for displaying stale data during refetches. */ readonly previousData: Signal<GetData<TData, TStates> | undefined>; /** * An error object if the query failed, `undefined` otherwise. */ readonly error: Signal<ErrorLike | undefined>; /** * A writable signal that represents the current query variables. */ readonly variables: WritableSignal<TVariables | undefined | null>; /** * Whether the query is currently active, subscribed to the underlying observable and receiving cache updates. */ readonly active: Signal<boolean>; /** * Whether the query is currently enabled. * * This property starts as `true` for non-lazy queries and `false` for lazy queries. * * Calling `execute()` sets it to `true`, while calling `terminate()` sets it to `false`. * * When `true`: * - The query automatically executes when variables change from `null` to a non-null value * - Variable changes trigger re-execution with the new variables * * When `false`: * - Variable changes are ignored and do not trigger re-execution * - The query must be manually started via `execute()` * * Note: This is different from `active`, which indicates whether the query is currently connected to its observable and actively watching the cache. */ readonly enabled: Signal<boolean>; private observable; private subscription; private readonly _active; private readonly _result; private readonly _enabled; constructor(injector: Injector, apollo: Apollo, options: SignalQueryOptions<TData, TVariables>); /** * Execute the query with the provided options. */ execute(execOptions?: SignalQueryExecOptions<TVariables>): Promise<SingleQueryResult<TData>>; /** * Terminate query execution and unsubscribe from the observable. */ terminate(): void; /** * Refetch the query with the current variables. */ refetch(variables?: Partial<TVariables>): Promise<SingleQueryResult<TData>>; /** * Fetch more data and merge it with the existing result. */ fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>): Promise<SingleQueryResult<TFetchData>>; /** * Update the query's cached data. */ updateQuery(mapFn: UpdateQueryMapFn<TData, TVariables>): void; /** * Start polling the query. */ startPolling(pollInterval: number): void; /** * Stop polling the query. */ stopPolling(): void; /** * Subscribe to more data. */ subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>): () => void; private _execute; private _terminate; } type SignalSubscriptionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = { /** * A GraphQL document, often created with `gql` from the `graphql-tag` * package, that contains a single subscription inside of it. */ subscription: DocumentNode | TypedDocumentNode<TData, TVariables>; /** * How you want your component to interact with the Apollo cache. For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy). */ fetchPolicy?: FetchPolicy; /** * Specifies the `ErrorPolicy` to be used for this operation */ errorPolicy?: ErrorPolicy; /** * Shared context between your component and your network interface (Apollo Link). */ context?: DefaultContext; /** * Shared context between your component and your network interface (Apollo Link). */ extensions?: Record<string, any>; /** * Whether to execute subscription immediately or lazily via `execute` method. */ lazy?: boolean; /** * Callback for when new data is received */ onData?: (data: TData) => void; /** * Callback for when the subscription is completed */ onComplete?: () => void; /** * Callback for when an error occurs */ onError?: (error: ErrorLike) => void; /** * Custom injector to use for this subscription. */ injector?: Injector; } & ({ /** * Whether to execute subscription immediately or lazily via `execute` method. */ lazy: true; /** * A function or signal returning an object containing all of the GraphQL variables your operation requires to execute. * * Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.* * * When `null` is returned, the subscription will be terminated until a non-null value is returned again. */ variables?: () => TVariables | undefined | null; } | SignalVariablesOption<NoInfer<TVariables>>); interface SignalSubscriptionExecOptions<TVariables extends OperationVariables = OperationVariables> { /** * Variables to use for this query execution. */ variables?: TVariables; /** * Context to use for this execution. */ context?: DefaultContext; } interface SignalSubscriptionResult<TData> extends SubscriptionResult<TData> { /** * Whether the subscription is currently loading */ loading: boolean; } declare class SignalSubscription<TData, TVariables extends OperationVariables = OperationVariables> { private readonly apollo; private readonly options; /** * The subscription result, containing `data`, `loading`, and `error`. */ readonly result: Signal<SignalSubscriptionResult<TData>>; /** * If `true`, the subscription is currently loading the initial result. */ readonly loading: Signal<boolean>; /** * The data returned by the subscription, or `undefined` if loading, errored, or no data received yet. */ readonly data: Signal<TData | undefined>; /** * An error object if the subscription failed, `undefined` otherwise. */ readonly error: Signal<ErrorLike | undefined>; /** * A writable signal that represents the current subscription variables. */ readonly variables: WritableSignal<TVariables | undefined | null>; /** * Whether the subscription is currently active, connected to the server and receiving real-time updates. */ readonly active: Signal<boolean>; /** * Whether the subscription is currently enabled. * * This property starts as `true` for non-lazy subscriptions and `false` for lazy subscriptions. * * Calling `execute()` sets it to `true`, while calling `terminate()` sets it to `false`. * * When `true`: * - The subscription automatically starts when variables change from `null` to a non-null value * - Variable changes trigger re-subscription with the new variables * * When `false`: * - Variable changes are ignored and do not trigger re-subscription * - The subscription must be manually started via `execute()` * * Note: This is different from `active`, which indicates whether the subscription is currently connected to the server and receiving real-time updates. */ readonly enabled: Signal<boolean>; private subscription; private readonly _active; private readonly _result; private readonly _enabled; constructor(injector: Injector, apollo: Apollo, options: SignalSubscriptionOptions<TData, TVariables>); /** * Execute subscription. */ execute(execOptions?: SignalSubscriptionExecOptions<TVariables>): void; /** * Terminate subscription. */ terminate(): void; private _execute; private _terminate; } declare class ApolloSignal { private readonly apollo; constructor(apollo: Apollo); query<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: SignalQueryOptions<TData, TVariables> & { returnPartialData: true; }): SignalQuery<TData, TVariables, 'empty' | 'complete' | 'streaming' | 'partial'>; query<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: SignalQueryOptions<TData, TVariables>): SignalQuery<TData, TVariables, 'empty' | 'complete' | 'streaming'>; mutation<TData = unknown, TVariables extends OperationVariables = OperationVariables>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SignalMutationOptions<TData, TVariables>): SignalMutation<TData, TVariables>; subscription<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: SignalSubscriptionOptions<TData, TVariables>): SignalSubscription<TData, TVariables>; fragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: SignalFragmentOptions<TData, TVariables>): SignalFragment<TData, TVariables>; cacheQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: SignalCacheQueryOptions<TData, TVariables> & { returnPartialData: true; }): SignalCacheQuery<DeepPartial<TData> | undefined, TVariables>; cacheQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: SignalCacheQueryOptions<TData, TVariables>): SignalCacheQuery<TData, TVariables>; } declare class Apollo { /** * Instance of ApolloClient */ readonly client: ApolloClient; readonly cache: ApolloCacheEx; readonly signal: ApolloSignal; private readonly defaultOptions?; constructor(client: ApolloClient, defaultOptions?: DefaultOptions); query<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: QueryOptions<TData, TVariables>): Observable<QueryResult<TData, 'empty' | 'complete'>>; watchQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TData, TVariables> & { returnPartialData: true; }): QueryObservable<TData, TVariables, 'empty' | 'complete' | 'streaming' | 'partial'>; watchQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TData, TVariables>): QueryObservable<TData, TVariables, 'empty' | 'complete' | 'streaming'>; watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables>): Observable<ApolloClient.WatchFragmentResult<TData>>; mutate<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: MutationOptions<TData, TVariables>): Observable<MutationResult<TData>>; subscribe<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: SubscriptionOptions<TData, TVariables>): Observable<SubscriptionResult<TData>>; static ɵfac: i0.ɵɵFactoryDeclaration<Apollo, never>; static ɵprov: i0.ɵɵInjectableDeclaration<Apollo>; } type ApolloClientFactory = (options: ApolloClient.Options) => ApolloClient; declare const APOLLO_CLIENT_FACTORY: InjectionToken<ApolloClientFactory>; interface FragmentIdentifier<TData> { id: string; fragmentName: string; fragment: DocumentNode | TypedDocumentNode<TData>; } declare function identifyFragment<TData = unknown>(fragment: DocumentNode | TypedDocumentNode<TData>, id: string, fragmentName?: string): FragmentIdentifier<TData>; declare function identifyFragmentType<TData = unknown>(fragment: DocumentNode | TypedDocumentNode<TData>, fragmentName?: string): string; declare class ApolloRegistry { private readonly providers; private _instances; register(token: Type<any> | InjectionToken<Apollo>): void; get instances(): Array<Apollo>; static ɵfac: i0.ɵɵFactoryDeclaration<ApolloRegistry, never>; static ɵprov: i0.ɵɵInjectableDeclaration<ApolloRegistry>; } type ApolloInstanceFactory = (clientId: string, client: ApolloClient, defaultOptions?: DefaultOptions) => Apollo; declare const APOLLO_INSTANCE_FACTORY: InjectionToken<ApolloInstanceFactory>; declare function mapQuery<T, R, TStates extends DataState<T>['dataState']>(mapFn: (data: GetData<T, Exclude<TStates, 'empty'>>) => R | undefined): OperatorFunction<QueryResult<T, TStates>, QueryResult<R, TStates>>; declare function mapMutation<T, R>(mapFn: (data: T) => R | undefined): OperatorFunction<MutationResult<T>, MutationResult<R>>; declare function mapSubscription<T, R>(mapFn: (data: T) => R | undefined): OperatorFunction<SubscriptionResult<T>, SubscriptionResult<R>>; declare function mapQueryResult<T, R, TStates extends DataState<T>['dataState']>(result: QueryResult<T, TStates>, mapFn: (data: GetData<T, Exclude<TStates, 'empty'>>) => R | undefined): QueryResult<R, TStates>; declare function mapMutationResult<T, R>(result: MutationResult<T>, mapFn: (data: T) => R | undefined): MutationResult<R>; declare function mapSubscriptionResult<T, R>(result: SubscriptionResult<T>, mapFn: (data: T) => R | undefined): SubscriptionResult<R>; interface ApolloOrbitFeature { kind: `APOLLO_ORBIT_${string}`; providers: Array<Provider>; } declare function withApolloOptions(options: ApolloOptions): ApolloOrbitFeature; declare function withApolloOptions(optionsFactory: () => ApolloOptions): ApolloOrbitFeature; declare function provideApollo(...features: Array<ApolloOrbitFeature>): EnvironmentProviders; declare function provideApolloIn