UNPKG

4.9 kBTypeScriptView Raw
1import { DocumentNode, EnumTypeDefinitionNode, EnumTypeExtensionNode, FieldDefinitionNode, InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, NamedTypeNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, OperationTypeDefinitionNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode, TypeNode, TypeSystemDefinitionNode, TypeSystemExtensionNode, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql';
2import { ClassDeclaration, ClassDeclarationStructure, InterfaceDeclaration, InterfaceDeclarationStructure, ParameterDeclarationStructure, SourceFile } 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 lookupDefinition(item: Readonly<TypeSystemDefinitionNode | TypeSystemExtensionNode>, tsFile: SourceFile, mode: 'class' | 'interface', options: DefinitionsGeneratorOptions): void | import("ts-morph").TypeAliasDeclaration;
47 lookupRootSchemaDefinition(operationTypes: ReadonlyArray<OperationTypeDefinitionNode>, tsFile: SourceFile, mode: 'class' | 'interface'): void;
48 addObjectTypeDefinition(item: ObjectTypeDefinitionNode | ObjectTypeExtensionNode | InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode | InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, tsFile: SourceFile, mode: 'class' | 'interface', options: DefinitionsGeneratorOptions): void;
49 lookupFieldDefiniton(item: FieldDefinitionNode | InputValueDefinitionNode, parentRef: InterfaceDeclaration | ClassDeclaration, mode: 'class' | 'interface', options: DefinitionsGeneratorOptions): void;
50 lookupField(item: FieldDefinitionNode | InputValueDefinitionNode, parentRef: InterfaceDeclaration | ClassDeclaration, mode: 'class' | 'interface', options: DefinitionsGeneratorOptions): void;
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 addScalarDefinition(item: ScalarTypeDefinitionNode | ScalarTypeExtensionNode, tsFile: SourceFile, options: DefinitionsGeneratorOptions): void;
65 addExtendInterfaces(interfaces: NamedTypeNode[], parentRef: InterfaceDeclaration): void;
66 addImplementsInterfaces(interfaces: NamedTypeNode[], parentRef: ClassDeclaration): void;
67 addEnumDefinition(item: EnumTypeDefinitionNode | EnumTypeExtensionNode, tsFile: SourceFile, options: DefinitionsGeneratorOptions): import("ts-morph").TypeAliasDeclaration;
68 addUnionDefinition(item: UnionTypeDefinitionNode | UnionTypeExtensionNode, tsFile: SourceFile): void;
69 addSymbolIfRoot(name: string): string;
70 isRoot(name: string): boolean;
71 addClassOrInterface(tsFile: SourceFile, mode: 'class' | 'interface', options: InterfaceDeclarationStructure | ClassDeclarationStructure): InterfaceDeclaration | ClassDeclaration;
72 getClassOrInterface(tsFile: SourceFile, mode: 'class' | 'interface', name: string): InterfaceDeclaration | ClassDeclaration;
73}
74//# sourceMappingURL=graphql-ast.explorer.d.ts.map
\No newline at end of file