UNPKG

4.75 kBTypeScriptView Raw
1import { DocumentNode, EnumTypeDefinitionNode, EnumTypeExtensionNode, FieldDefinitionNode, InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, OperationTypeDefinitionNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode, TypeNode, TypeSystemDefinitionNode, TypeSystemExtensionNode, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql';
2import type { ClassDeclarationStructure, EnumDeclarationStructure, InterfaceDeclarationStructure, MethodDeclarationStructure, MethodSignatureStructure, OptionalKind, ParameterDeclarationStructure, PropertyDeclarationStructure, PropertySignatureStructure, SourceFile, TypeAliasDeclarationStructure } from 'ts-morph';
3export interface DefinitionsGeneratorOptions {
4 /**
5 * If true, the additional "__typename" field is generated for every object type.
6 * @default false
7 */
8 emitTypenameField?: boolean;
9 /**
10 * If true, resolvers (query/mutation/etc) are generated as plain fields without arguments.
11 * @default false
12 */
13 skipResolverArgs?: boolean;
14 /**
15 * If provided, specifies a default generated TypeScript type for custom scalars.
16 * @default 'any'
17 */
18 defaultScalarType?: string;
19 /**
20 * If provided, specifies a mapping of types to use for custom scalars
21 * @default undefined
22 */
23 customScalarTypeMapping?: Record<string, string | {
24 name: string;
25 }>;
26 /**
27 * If provided, specifies a mapping of default scalar types (Int, Boolean, ID, Float, String).
28 * @default undefined
29 */
30 defaultTypeMapping?: Partial<Record<'ID' | 'Boolean' | 'Float' | 'String' | 'Int', string>>;
31 /**
32 * If provided, specifies a custom header to add after the
33 * to the output file (eg. for custom type imports or comments)
34 * @default undefined
35 */
36 additionalHeader?: string;
37 /**
38 * If true, enums are generated as string literal union types.
39 * @default false
40 */
41 enumsAsTypes?: boolean;
42}
43export declare class GraphQLAstExplorer {
44 private readonly root;
45 explore(documentNode: DocumentNode, outputPath: string, mode: 'class' | 'interface', options?: DefinitionsGeneratorOptions): Promise<SourceFile>;
46 toDefinitionStructures(item: Readonly<TypeSystemDefinitionNode | TypeSystemExtensionNode>, mode: 'class' | 'interface', options: DefinitionsGeneratorOptions): ClassDeclarationStructure | EnumDeclarationStructure | InterfaceDeclarationStructure | TypeAliasDeclarationStructure;
47 toRootSchemaDefinitionStructure(operationTypes: ReadonlyArray<OperationTypeDefinitionNode>, mode: 'class' | 'interface'): ClassDeclarationStructure | InterfaceDeclarationStructure;
48 toObjectTypeDefinitionStructure(item: ObjectTypeDefinitionNode | ObjectTypeExtensionNode | InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode | InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, mode: 'class' | 'interface', options: DefinitionsGeneratorOptions): ClassDeclarationStructure | InterfaceDeclarationStructure;
49 toPropertyDeclarationStructure(item: FieldDefinitionNode | InputValueDefinitionNode, options: DefinitionsGeneratorOptions): OptionalKind<PropertyDeclarationStructure> & OptionalKind<PropertySignatureStructure>;
50 toMethodDeclarationStructure(item: FieldDefinitionNode | InputValueDefinitionNode, mode: 'class' | 'interface', options: DefinitionsGeneratorOptions): OptionalKind<MethodDeclarationStructure> & OptionalKind<MethodSignatureStructure>;
51 getFieldTypeDefinition(typeNode: TypeNode, options: DefinitionsGeneratorOptions): {
52 name: string;
53 required: boolean;
54 };
55 unwrapTypeIfNonNull(type: TypeNode): {
56 type: TypeNode;
57 required: boolean;
58 };
59 getType(typeName: string, options: DefinitionsGeneratorOptions): string;
60 getDefaultTypes(options: DefinitionsGeneratorOptions): {
61 [type: string]: string;
62 };
63 getFunctionParameters(inputs: ReadonlyArray<InputValueDefinitionNode>, options: DefinitionsGeneratorOptions): ParameterDeclarationStructure[];
64 toScalarDefinitionStructure(item: ScalarTypeDefinitionNode | ScalarTypeExtensionNode, options: DefinitionsGeneratorOptions): TypeAliasDeclarationStructure;
65 toEnumDefinitionStructure(item: EnumTypeDefinitionNode | EnumTypeExtensionNode, options: DefinitionsGeneratorOptions): TypeAliasDeclarationStructure | EnumDeclarationStructure;
66 toUnionDefinitionStructure(item: UnionTypeDefinitionNode | UnionTypeExtensionNode): TypeAliasDeclarationStructure;
67 addSymbolIfRoot(name: string): string;
68 isRoot(name: string): boolean;
69}
70//# sourceMappingURL=graphql-ast.explorer.d.ts.map
\No newline at end of file