1 | import { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from 'graphql';
|
2 | import { FragmentMap, StoreValue, StoreObject, Reference, isReference } from '../../utilities';
|
3 | import { IdGetter, MergeInfo, ReadMergeModifyContext } from "./types";
|
4 | import { InMemoryCache } from './inMemoryCache';
|
5 | import { SafeReadonly, FieldSpecifier, ToReferenceFunction, ReadFieldFunction, ReadFieldOptions, CanReadFunction } from '../core/types/common';
|
6 | import { WriteContext } from './writeToStore';
|
7 | export type TypePolicies = {
|
8 | [__typename: string]: TypePolicy;
|
9 | };
|
10 | export type KeySpecifier = ReadonlyArray<string | KeySpecifier>;
|
11 | export type KeyFieldsContext = {
|
12 | typename: string | undefined;
|
13 | storeObject: StoreObject;
|
14 | readField: ReadFieldFunction;
|
15 | selectionSet?: SelectionSetNode;
|
16 | fragmentMap?: FragmentMap;
|
17 | keyObject?: Record<string, any>;
|
18 | };
|
19 | export type KeyFieldsFunction = (object: Readonly<StoreObject>, context: KeyFieldsContext) => KeySpecifier | false | ReturnType<IdGetter>;
|
20 | export type TypePolicy = {
|
21 | keyFields?: KeySpecifier | KeyFieldsFunction | false;
|
22 | merge?: FieldMergeFunction | boolean;
|
23 | queryType?: true;
|
24 | mutationType?: true;
|
25 | subscriptionType?: true;
|
26 | fields?: {
|
27 | [fieldName: string]: FieldPolicy<any> | FieldReadFunction<any>;
|
28 | };
|
29 | };
|
30 | export type KeyArgsFunction = (args: Record<string, any> | null, context: {
|
31 | typename: string;
|
32 | fieldName: string;
|
33 | field: FieldNode | null;
|
34 | variables?: Record<string, any>;
|
35 | }) => KeySpecifier | false | ReturnType<IdGetter>;
|
36 | export type FieldPolicy<TExisting = any, TIncoming = TExisting, TReadResult = TIncoming, TOptions extends FieldFunctionOptions = FieldFunctionOptions> = {
|
37 | keyArgs?: KeySpecifier | KeyArgsFunction | false;
|
38 | read?: FieldReadFunction<TExisting, TReadResult, TOptions>;
|
39 | merge?: FieldMergeFunction<TExisting, TIncoming, TOptions> | boolean;
|
40 | };
|
41 | export type StorageType = Record<string, any>;
|
42 | export interface FieldFunctionOptions<TArgs = Record<string, any>, TVars = Record<string, any>> {
|
43 | args: TArgs | null;
|
44 | fieldName: string;
|
45 | storeFieldName: string;
|
46 | field: FieldNode | null;
|
47 | variables?: TVars;
|
48 | isReference: typeof isReference;
|
49 | toReference: ToReferenceFunction;
|
50 | storage: StorageType;
|
51 | cache: InMemoryCache;
|
52 | readField: ReadFieldFunction;
|
53 | canRead: CanReadFunction;
|
54 | mergeObjects: MergeObjectsFunction;
|
55 | }
|
56 | type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;
|
57 | export type FieldReadFunction<TExisting = any, TReadResult = TExisting, TOptions extends FieldFunctionOptions = FieldFunctionOptions> = (existing: SafeReadonly<TExisting> | undefined, options: TOptions) => TReadResult | undefined;
|
58 | export type FieldMergeFunction<TExisting = any, TIncoming = TExisting, TOptions extends FieldFunctionOptions = FieldFunctionOptions> = (existing: SafeReadonly<TExisting> | undefined, incoming: SafeReadonly<TIncoming>, options: TOptions) => SafeReadonly<TExisting>;
|
59 | export type PossibleTypesMap = {
|
60 | [supertype: string]: string[];
|
61 | };
|
62 | export declare class Policies {
|
63 | private config;
|
64 | private typePolicies;
|
65 | private toBeAdded;
|
66 | private supertypeMap;
|
67 | private fuzzySubtypes;
|
68 | readonly cache: InMemoryCache;
|
69 | readonly rootIdsByTypename: Record<string, string>;
|
70 | readonly rootTypenamesById: Record<string, string>;
|
71 | readonly usingPossibleTypes = false;
|
72 | constructor(config: {
|
73 | cache: InMemoryCache;
|
74 | dataIdFromObject?: KeyFieldsFunction;
|
75 | possibleTypes?: PossibleTypesMap;
|
76 | typePolicies?: TypePolicies;
|
77 | });
|
78 | identify(object: StoreObject, partialContext?: Partial<KeyFieldsContext>): [string?, StoreObject?];
|
79 | addTypePolicies(typePolicies: TypePolicies): void;
|
80 | private updateTypePolicy;
|
81 | private setRootTypename;
|
82 | addPossibleTypes(possibleTypes: PossibleTypesMap): void;
|
83 | private getTypePolicy;
|
84 | private getFieldPolicy;
|
85 | private getSupertypeSet;
|
86 | fragmentMatches(fragment: InlineFragmentNode | FragmentDefinitionNode, typename: string | undefined, result?: Record<string, any>, variables?: Record<string, any>): boolean;
|
87 | hasKeyArgs(typename: string | undefined, fieldName: string): boolean;
|
88 | getStoreFieldName(fieldSpec: FieldSpecifier): string;
|
89 | readField<V = StoreValue>(options: ReadFieldOptions, context: ReadMergeModifyContext): SafeReadonly<V> | undefined;
|
90 | getReadFunction(typename: string | undefined, fieldName: string): FieldReadFunction | undefined;
|
91 | getMergeFunction(parentTypename: string | undefined, fieldName: string, childTypename: string | undefined): FieldMergeFunction | undefined;
|
92 | runMergeFunction(existing: StoreValue, incoming: StoreValue, { field, typename, merge }: MergeInfo, context: WriteContext, storage?: StorageType): any;
|
93 | }
|
94 | export declare function normalizeReadFieldOptions(readFieldArgs: IArguments, objectOrReference: StoreObject | Reference | undefined, variables?: ReadMergeModifyContext["variables"]): ReadFieldOptions;
|
95 | export {};
|
96 |
|
\ | No newline at end of file |