UNPKG

4.36 kBTypeScriptView Raw
1import type { DocumentNode, GraphQLFormattedError } from "graphql";
2import type { ApolloCache } from "../cache/index.js";
3import type { FetchResult } from "../link/core/index.js";
4import type { ApolloError } from "../errors/index.js";
5import type { QueryInfo } from "./QueryInfo.js";
6import type { NetworkStatus } from "./networkStatus.js";
7import type { Resolver } from "./LocalState.js";
8import type { ObservableQuery } from "./ObservableQuery.js";
9import type { QueryOptions } from "./watchQueryOptions.js";
10import type { Cache } from "../cache/index.js";
11import type { IsStrictlyAny } from "../utilities/index.js";
12export type { TypedDocumentNode } from "@graphql-typed-document-node/core";
13export type MethodKeys<T> = {
14 [P in keyof T]: T[P] extends Function ? P : never;
15}[keyof T];
16export interface DefaultContext extends Record<string, any> {
17}
18export type QueryListener = (queryInfo: QueryInfo) => void;
19export type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache.DiffResult<any>, lastDiff: Cache.DiffResult<any> | undefined) => boolean | TResult;
20export type RefetchQueryDescriptor = string | DocumentNode;
21export type InternalRefetchQueryDescriptor = RefetchQueryDescriptor | QueryOptions;
22type RefetchQueriesIncludeShorthand = "all" | "active";
23export type RefetchQueriesInclude = RefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand;
24export type InternalRefetchQueriesInclude = InternalRefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand;
25export interface RefetchQueriesOptions<TCache extends ApolloCache<any>, TResult> {
26 updateCache?: (cache: TCache) => void;
27 include?: RefetchQueriesInclude;
28 optimistic?: boolean;
29 onQueryUpdated?: OnQueryUpdated<TResult> | null;
30}
31export type RefetchQueriesPromiseResults<TResult> = IsStrictlyAny<TResult> extends true ? any[] : TResult extends boolean ? ApolloQueryResult<any>[] : TResult extends PromiseLike<infer U> ? U[] : TResult[];
32export interface RefetchQueriesResult<TResult> extends Promise<RefetchQueriesPromiseResults<TResult>> {
33 queries: ObservableQuery<any>[];
34 results: InternalRefetchQueriesResult<TResult>[];
35}
36export interface InternalRefetchQueriesOptions<TCache extends ApolloCache<any>, TResult> extends Omit<RefetchQueriesOptions<TCache, TResult>, "include"> {
37 include?: InternalRefetchQueriesInclude;
38 removeOptimistic?: string;
39}
40export type InternalRefetchQueriesResult<TResult> = TResult extends boolean ? Promise<ApolloQueryResult<any>> : TResult;
41export type InternalRefetchQueriesMap<TResult> = Map<ObservableQuery<any>, InternalRefetchQueriesResult<TResult>>;
42export type { QueryOptions as PureQueryOptions };
43export type OperationVariables = Record<string, any>;
44export interface ApolloQueryResult<T> {
45 data: T;
46 /**
47 * A list of any errors that occurred during server-side execution of a GraphQL operation.
48 * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
49 */
50 errors?: ReadonlyArray<GraphQLFormattedError>;
51 /**
52 * The single Error object that is passed to onError and useQuery hooks, and is often thrown during manual `client.query` calls.
53 * This will contain both a NetworkError field and any GraphQLErrors.
54 * See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
55 */
56 error?: ApolloError;
57 loading: boolean;
58 networkStatus: NetworkStatus;
59 partial?: boolean;
60}
61export type MutationQueryReducer<T> = (previousResult: Record<string, any>, options: {
62 mutationResult: FetchResult<T>;
63 queryName: string | undefined;
64 queryVariables: Record<string, any>;
65}) => Record<string, any>;
66export type MutationQueryReducersMap<T = {
67 [key: string]: any;
68}> = {
69 [queryName: string]: MutationQueryReducer<T>;
70};
71/**
72 * @deprecated Use `MutationUpdaterFunction` instead.
73 */
74export type MutationUpdaterFn<T = {
75 [key: string]: any;
76}> = (cache: ApolloCache<T>, mutationResult: FetchResult<T>) => void;
77export type MutationUpdaterFunction<TData, TVariables, TContext, TCache extends ApolloCache<any>> = (cache: TCache, result: Omit<FetchResult<TData>, "context">, options: {
78 context?: TContext;
79 variables?: TVariables;
80}) => void;
81export interface Resolvers {
82 [key: string]: {
83 [field: string]: Resolver;
84 };
85}
86//# sourceMappingURL=types.d.ts.map
\No newline at end of file