UNPKG

2.6 kBTypeScriptView Raw
1import type { DirectiveNode, FieldNode, VariableNode, InlineFragmentNode, ValueNode, SelectionNode, NameNode, SelectionSetNode, DocumentNode } from "graphql";
2import type { FragmentMap } from "./fragments.js";
3export interface Reference {
4 readonly __ref: string;
5}
6export declare function makeReference(id: string): Reference;
7export declare function isReference(obj: any): obj is Reference;
8export type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object;
9export interface StoreObject {
10 __typename?: string;
11 [storeFieldName: string]: StoreValue;
12}
13/**
14 * Workaround for a TypeScript quirk:
15 * types per default have an implicit index signature that makes them
16 * assignable to `StoreObject`.
17 * interfaces do not have that implicit index signature, so they cannot
18 * be assigned to `StoreObject`.
19 * This type just maps over a type or interface that is passed in,
20 * implicitly adding the index signature.
21 * That way, the result can be assigned to `StoreObject`.
22 *
23 * This is important if some user-defined interface is used e.g.
24 * in cache.modify, where the `toReference` method expects a
25 * `StoreObject` as input.
26 */
27export type AsStoreObject<T extends {
28 __typename?: string;
29}> = {
30 [K in keyof T]: T[K];
31};
32export declare function isDocumentNode(value: any): value is DocumentNode;
33export declare function valueToObjectRepresentation(argObj: any, name: NameNode, value: ValueNode, variables?: Object): void;
34export declare function storeKeyNameFromField(field: FieldNode, variables?: Object): string;
35export type Directives = {
36 [directiveName: string]: {
37 [argName: string]: any;
38 };
39};
40declare let storeKeyNameStringify: (value: any) => string;
41export declare const getStoreKeyName: ((fieldName: string, args?: Record<string, any> | null, directives?: Directives) => string) & {
42 setStringify(s: typeof storeKeyNameStringify): (value: any) => string;
43};
44export declare function argumentsObjectFromField(field: FieldNode | DirectiveNode, variables?: Record<string, any>): Object | null;
45export declare function resultKeyNameFromField(field: FieldNode): string;
46export declare function getTypenameFromResult(result: Record<string, any>, selectionSet: SelectionSetNode, fragmentMap?: FragmentMap): string | undefined;
47export declare function isField(selection: SelectionNode): selection is FieldNode;
48export declare function isInlineFragment(selection: SelectionNode): selection is InlineFragmentNode;
49export type VariableValue = (node: VariableNode) => any;
50export {};
51//# sourceMappingURL=storeUtils.d.ts.map
\No newline at end of file