UNPKG

4.16 kBTypeScriptView Raw
1import { DirectiveNode, FieldNode, FragmentSpreadNode, GraphQLNamedType, GraphQLObjectType, GraphQLSchema, InlineFragmentNode, SelectionNode, SelectionSetNode } from 'graphql';
2import { ParsedDocumentsConfig } from './base-documents-visitor.js';
3import { BaseVisitorConvertOptions } from './base-visitor.js';
4import { BaseSelectionSetProcessor, LinkField, NameAndType, PrimitiveAliasedFields, PrimitiveField } from './selection-set-processor/base.js';
5import { ConvertNameFn, FragmentDirectives, GetFragmentSuffixFn, LoadedFragment, NormalizedScalarsMap } from './types.js';
6type FragmentSpreadUsage = {
7 fragmentName: string;
8 typeName: string;
9 onType: string;
10 selectionNodes: Array<SelectionNode>;
11 fragmentDirectives?: DirectiveNode[];
12};
13type CollectedFragmentNode = (SelectionNode | FragmentSpreadUsage | DirectiveNode) & FragmentDirectives;
14type GroupedStringifiedTypes = Record<string, Array<string | {
15 union: string[];
16}>>;
17export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedDocumentsConfig> {
18 protected _processor: BaseSelectionSetProcessor<any>;
19 protected _scalars: NormalizedScalarsMap;
20 protected _schema: GraphQLSchema;
21 protected _convertName: ConvertNameFn<BaseVisitorConvertOptions>;
22 protected _getFragmentSuffix: GetFragmentSuffixFn;
23 protected _loadedFragments: LoadedFragment[];
24 protected _config: Config;
25 protected _parentSchemaType?: GraphQLNamedType;
26 protected _selectionSet?: SelectionSetNode;
27 protected _primitiveFields: PrimitiveField[];
28 protected _primitiveAliasedFields: PrimitiveAliasedFields[];
29 protected _linksFields: LinkField[];
30 protected _queriedForTypename: boolean;
31 constructor(_processor: BaseSelectionSetProcessor<any>, _scalars: NormalizedScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _getFragmentSuffix: GetFragmentSuffixFn, _loadedFragments: LoadedFragment[], _config: Config, _parentSchemaType?: GraphQLNamedType, _selectionSet?: SelectionSetNode);
32 createNext(parentSchemaType: GraphQLNamedType, selectionSet: SelectionSetNode): SelectionSetToObject;
33 /**
34 * traverse the inline fragment nodes recursively for collecting the selectionSets on each type
35 */
36 _collectInlineFragments(parentType: GraphQLNamedType, nodes: Array<InlineFragmentNode & FragmentDirectives>, types: Map<string, Array<CollectedFragmentNode>>): any;
37 protected _createInlineFragmentForFieldNodes(parentType: GraphQLNamedType, fieldNodes: FieldNode[]): InlineFragmentNode;
38 protected buildFragmentSpreadsUsage(spreads: FragmentSpreadNode[]): Record<string, FragmentSpreadUsage[]>;
39 protected flattenSelectionSet(selections: ReadonlyArray<SelectionNode>, parentSchemaType?: GraphQLObjectType<any, any>): Map<string, Array<SelectionNode | FragmentSpreadUsage>>;
40 private _appendToTypeMap;
41 /**
42 * mustAddEmptyObject indicates that not all possible types on a union or interface field are covered.
43 */
44 protected _buildGroupedSelections(): {
45 grouped: GroupedStringifiedTypes;
46 mustAddEmptyObject: boolean;
47 };
48 protected selectionSetStringFromFields(fields: (string | NameAndType)[]): string | null;
49 protected buildSelectionSet(parentSchemaType: GraphQLObjectType, selectionNodes: Array<SelectionNode | FragmentSpreadUsage | DirectiveNode>, options?: {
50 unsetTypes: boolean;
51 }): {
52 typeInfo: {
53 name: string;
54 type: string;
55 };
56 fields: string[];
57 };
58 protected buildTypeNameField(type: GraphQLObjectType, nonOptionalTypename?: boolean, addTypename?: boolean, queriedForTypename?: boolean, skipTypeNameForRoot?: boolean): {
59 name: string;
60 type: string;
61 };
62 protected getUnknownType(): string;
63 protected getEmptyObjectType(): string;
64 private getEmptyObjectTypeString;
65 transformSelectionSet(): string;
66 transformFragmentSelectionSetToTypes(fragmentName: string, fragmentSuffix: string, declarationBlockConfig: any): string;
67 protected buildFragmentTypeName(name: string, suffix: string, typeName?: string): string;
68}
69export {};