import { DirectiveNode, FieldNode, FragmentSpreadNode, GraphQLNamedType, GraphQLObjectType, GraphQLSchema, InlineFragmentNode, SelectionNode, SelectionSetNode } from 'graphql'; import { ParsedDocumentsConfig } from './base-documents-visitor.js'; import { BaseVisitorConvertOptions } from './base-visitor.js'; import { BaseSelectionSetProcessor, LinkField, NameAndType, PrimitiveAliasedFields, PrimitiveField, type SelectionSetProcessorConfig as BaseSelectionSetProcessorConfig } from './selection-set-processor/base.js'; import type { ConvertNameFn, GetFragmentSuffixFn, LoadedFragment, NormalizedScalarsMap } from './types.js'; import { DeclarationBlockConfig } from './utils.js'; type FragmentSpreadUsage = { fragmentName: string; typeName: string; onType: string; selectionNodes: Array; fragmentDirectives: DirectiveNode[]; }; /** * @description EnrichedFieldNode are field nodes enriched with Codegen metadata for subsequent processing */ export type EnrichedFieldNode = FieldNode & { /** * A field node may implicitly inherit fragment directives from parents * For example, if the field's parent is marked with `@skip`, the field is implicitly marked with `@skip` as well */ fragmentDirectives?: DirectiveNode[]; }; interface DependentType { name: string; content: string; isUnionType?: boolean; } /** * Each grouped TypeName has an array of nodes. * These are collected when parsing the selection set, * then turned into TypeScript strings */ type GroupedTypeNameNode = EnrichedFieldNode | FragmentSpreadNode | InlineFragmentNode | FragmentSpreadUsage | DirectiveNode; type GroupedStringifiedTypes = Record>; export declare class SelectionSetToObject { protected _processor: BaseSelectionSetProcessor; protected _scalars: NormalizedScalarsMap; protected _schema: GraphQLSchema; protected _convertName: ConvertNameFn; protected _getFragmentSuffix: GetFragmentSuffixFn; protected _loadedFragments: LoadedFragment[]; protected _config: Config; protected _parentSchemaType?: GraphQLNamedType | undefined; protected _selectionSet?: SelectionSetNode | undefined; protected _primitiveFields: PrimitiveField[]; protected _primitiveAliasedFields: PrimitiveAliasedFields[]; protected _linksFields: LinkField[]; protected _queriedForTypename: boolean; protected _seenFieldNames: Map; constructor(_processor: BaseSelectionSetProcessor, _scalars: NormalizedScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn, _getFragmentSuffix: GetFragmentSuffixFn, _loadedFragments: LoadedFragment[], _config: Config, _parentSchemaType?: GraphQLNamedType | undefined, _selectionSet?: SelectionSetNode | undefined); createNext(parentSchemaType: GraphQLNamedType, selectionSet: SelectionSetNode): SelectionSetToObject; /** * traverse the inline fragment nodes recursively for collecting the selectionSets on each type */ _collectInlineFragments(parentType: GraphQLNamedType, nodes: Array, types: Map>): void; /** * The `buildFragmentSpreadsUsage` method is used to collect fields from fragment spreads in the selection set. * It creates a record of fragment spread usages, which includes the fragment name, type name, and the selection nodes * inside the fragment. */ protected buildFragmentSpreadsUsage(spreads: FragmentSpreadNode[]): Record; protected flattenSelectionSet(selections: ReadonlyArray, parentSchemaType?: GraphQLObjectType): { selectionNodesByTypeName: Map>; selectionNodesByTypeNameConditional: Array>>; }; private _appendToTypeMap; protected _buildGroupedSelections(parentName: string): { grouped: GroupedStringifiedTypes; dependentTypes: DependentType[]; mustAddEmptyObject: boolean; }; protected selectionSetStringFromFields(fields: (string | NameAndType)[]): string | null; protected buildSelectionSet(parentSchemaType: GraphQLObjectType, selectionNodes: Array, options: { unsetTypes?: boolean; partialTypes?: boolean; parentFieldName?: string; }): { typeInfo: { name: string; type: string; } | null; fields: string[]; dependentTypes: DependentType[]; }; protected buildTypeNameField(type: GraphQLObjectType, nonOptionalTypename: boolean, queriedForTypename: boolean, skipTypeNameForRoot: boolean): { name: string; type: string; } | null; protected getUnknownType(): string; protected getEmptyObjectType(): string; private getEmptyObjectTypeString; transformSelectionSet(fieldName: string): { mergedTypeString: string; dependentTypes: DependentType[]; isUnionType?: boolean; }; private transformSelectionSetUncached; transformFragmentSelectionSetToTypes(fragmentName: string, fragmentSuffix: string, declarationBlockConfig: DeclarationBlockConfig): string; protected buildFragmentTypeName(name: string, suffix: string, typeName?: string): string; protected buildParentFieldName(typeName: string, parentName: string): string; } export {};