UNPKG

@graphql-codegen/typescript-operations

Version:

GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments

72 lines (71 loc) 3.23 kB
import { GraphQLEnumType, GraphQLInputObjectType, GraphQLScalarType, InputObjectTypeDefinitionNode, InputValueDefinitionNode, type DocumentNode, type EnumTypeDefinitionNode, type GraphQLSchema, type TypeDefinitionNode } from 'graphql'; import { BaseDocumentsVisitor, DeclarationKind, ParsedDocumentsConfig, type ConvertSchemaEnumToDeclarationBlockString, type ParsedEnumValuesMap } from '@graphql-codegen/visitor-plugin-common'; import type { TypeScriptDocumentsPluginConfig } from './config.js'; export interface TypeScriptDocumentsParsedConfig extends ParsedDocumentsConfig { arrayInputCoercion: boolean; immutableTypes: boolean; noExport: boolean; maybeValue: string; inputMaybeValue: string; allowUndefinedQueryVariables: boolean; enumType: ConvertSchemaEnumToDeclarationBlockString['outputType']; enumValues: ParsedEnumValuesMap; ignoreEnumValuesFromSchema: boolean; futureProofEnums: boolean; } type UsedSchemaTypes = Record<string, { type: 'GraphQLScalarType'; node: GraphQLScalarType; tsType: string; useCases: { input: boolean; output: boolean; variables: boolean; }; } | { type: 'GraphQLEnumType'; node: GraphQLEnumType; tsType: string; } | { type: 'GraphQLInputObjectType'; node: GraphQLInputObjectType; tsType: string; }>; export declare class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<TypeScriptDocumentsPluginConfig, TypeScriptDocumentsParsedConfig> { protected _usedSchemaTypes: UsedSchemaTypes; protected _needsExactUtilityType: boolean; /** * _usedEnumIntrospectionType is a metadata value * which tracks whether an introspection type enum (i.e. __TypeKind or __DirectiveLocation) * has been referred to in selection sets * * If it is, we need to generate the enum values from introspection types */ protected _usedEnumIntrospectionType: boolean; private _outputPath; constructor(schema: GraphQLSchema, config: TypeScriptDocumentsPluginConfig, documentNode: DocumentNode, outputPath: string); EnumTypeDefinition(node: EnumTypeDefinitionNode): string | null; InputObjectTypeDefinition(node: InputObjectTypeDefinitionNode): string | null; InputValueDefinition(node: InputValueDefinitionNode, _key?: number | string, _parent?: any, _path?: Array<string | number>, ancestors?: Array<TypeDefinitionNode>): string; getImports(): Array<string>; getExternalSchemaTypeImports(): Array<string>; getEnumsImports(): string[]; getScalarsImports(): string[]; protected getPunctuation(_declarationKind: DeclarationKind): string; protected applyVariablesWrapper(variablesBlock: string, operationType: string): string; private collectInnerTypesRecursively; /** * @description collects schema types used in operations: * - used Enums for Variables * - used Scalars for Variables * - used Input for Variables (recursively) * * - used Enums for Result * - used Scalars for Result */ private collectUsedSchemaTypesToGenerate; getExactUtilityType(): string | null; getIncrementalUtilityType(): string | null; shouldVisitIntrospectionTypes(): boolean; } export {};