UNPKG

2.79 kBTypeScriptView Raw
1import type { DocumentNode, SelectionNode, FieldNode, ASTNode } from "graphql";
2import type { ApolloCache } from "../cache/index.js";
3import type { FragmentMap, StoreObject } from "../utilities/index.js";
4import type { ApolloClient } from "./ApolloClient.js";
5import type { Resolvers, OperationVariables } from "./types.js";
6import type { FetchResult } from "../link/core/index.js";
7export type Resolver = (rootValue?: any, args?: any, context?: any, info?: {
8 field: FieldNode;
9 fragmentMap: FragmentMap;
10}) => any;
11export type VariableMap = {
12 [name: string]: any;
13};
14export type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean;
15export type ExecContext = {
16 fragmentMap: FragmentMap;
17 context: any;
18 variables: VariableMap;
19 fragmentMatcher: FragmentMatcher;
20 defaultOperationType: string;
21 exportedVariables: Record<string, any>;
22 onlyRunForcedResolvers: boolean;
23 selectionsToResolve: Set<SelectionNode>;
24};
25export type LocalStateOptions<TCacheShape> = {
26 cache: ApolloCache<TCacheShape>;
27 client?: ApolloClient<TCacheShape>;
28 resolvers?: Resolvers | Resolvers[];
29 fragmentMatcher?: FragmentMatcher;
30};
31export declare class LocalState<TCacheShape> {
32 private cache;
33 private client?;
34 private resolvers?;
35 private fragmentMatcher?;
36 private selectionsToResolveCache;
37 constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions<TCacheShape>);
38 addResolvers(resolvers: Resolvers | Resolvers[]): void;
39 setResolvers(resolvers: Resolvers | Resolvers[]): void;
40 getResolvers(): Resolvers;
41 runResolvers<TData>({ document, remoteResult, context, variables, onlyRunForcedResolvers, }: {
42 document: DocumentNode | null;
43 remoteResult: FetchResult<TData>;
44 context?: Record<string, any>;
45 variables?: Record<string, any>;
46 onlyRunForcedResolvers?: boolean;
47 }): Promise<FetchResult<TData>>;
48 setFragmentMatcher(fragmentMatcher: FragmentMatcher): void;
49 getFragmentMatcher(): FragmentMatcher | undefined;
50 clientQuery(document: DocumentNode): DocumentNode | null;
51 serverQuery(document: DocumentNode): DocumentNode | null;
52 prepareContext(context?: Record<string, any>): {
53 cache: ApolloCache<TCacheShape>;
54 getCacheKey(obj: StoreObject): string | undefined;
55 };
56 addExportedVariables<TVars extends OperationVariables>(document: DocumentNode, variables?: TVars, context?: {}): Promise<TVars>;
57 shouldForceResolvers(document: ASTNode): boolean;
58 private buildRootValueFromCache;
59 private resolveDocument;
60 private resolveSelectionSet;
61 private resolveField;
62 private resolveSubSelectedArray;
63 private collectSelectionsToResolve;
64}
65//# sourceMappingURL=LocalState.d.ts.map
\No newline at end of file