UNPKG

7.78 kBTypeScriptView Raw
1import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode, StringValueNode, DirectiveNode } from 'graphql';
2import { BaseVisitor, ParsedConfig, RawConfig } from './base-visitor';
3import { EnumValuesMap, NormalizedScalarsMap, DeclarationKindConfig, DeclarationKind, ParsedEnumValuesMap } from './types';
4import { DeclarationBlock, DeclarationBlockConfig } from './utils';
5import { OperationVariablesToObject } from './variables-to-object';
6export interface ParsedTypesConfig extends ParsedConfig {
7 enumValues: ParsedEnumValuesMap;
8 declarationKind: DeclarationKindConfig;
9 addUnderscoreToArgsType: boolean;
10 onlyOperationTypes: boolean;
11 enumPrefix: boolean;
12 fieldWrapperValue: string;
13 wrapFieldDefinitions: boolean;
14}
15export interface RawTypesConfig extends RawConfig {
16 /**
17 * @description Adds `_` to generated `Args` types in order to avoid duplicate identifiers.
18 *
19 * @exampleMarkdown
20 * ## With Custom Values
21 * ```yml
22 * config:
23 * addUnderscoreToArgsType: true
24 * ```
25 */
26 addUnderscoreToArgsType?: boolean;
27 /**
28 * @description Overrides the default value of enum values declared in your GraphQL schema.
29 * You can also map the entire enum to an external type by providing a string that of `module#type`.
30 *
31 * @exampleMarkdown
32 * ## With Custom Values
33 * ```yml
34 * config:
35 * enumValues:
36 * MyEnum:
37 * A: 'foo'
38 * ```
39 *
40 * ## With External Enum
41 * ```yml
42 * config:
43 * enumValues:
44 * MyEnum: ./my-file#MyCustomEnum
45 * ```
46 *
47 * ## Import All Enums from a file
48 * ```yml
49 * config:
50 * enumValues: ./my-file
51 * ```
52 */
53 enumValues?: EnumValuesMap;
54 /**
55 * @description Overrides the default output for various GraphQL elements.
56 *
57 * @exampleMarkdown
58 * ## Override all declarations
59 * ```yml
60 * config:
61 * declarationKind: 'interface'
62 * ```
63 *
64 * ## Override only specific declarations
65 * ```yml
66 * config:
67 * declarationKind:
68 * type: 'interface'
69 * input: 'interface'
70 * ```
71 */
72 declarationKind?: DeclarationKind | DeclarationKindConfig;
73 /**
74 * @default true
75 * @description Allow you to disable prefixing for generated enums, works in combination with `typesPrefix`.
76 *
77 * @exampleMarkdown
78 * ## Disable enum prefixes
79 * ```yml
80 * config:
81 * typesPrefix: I
82 * enumPrefix: false
83 * ```
84 */
85 enumPrefix?: boolean;
86 /**
87 * @description Allow you to add wrapper for field type, use T as the generic value. Make sure to set `wrapFieldDefinitions` to `true` in order to make this flag work.
88 * @default T
89 *
90 * @exampleMarkdown
91 * ## Allow Promise
92 * ```yml
93 * generates:
94 * path/to/file.ts:
95 * plugins:
96 * - typescript
97 * config:
98 * wrapFieldDefinitions: true
99 * fieldWrapperValue: T | Promise<T>
100 * ```
101 */
102 fieldWrapperValue?: string;
103 /**
104 * @description Set the to `true` in order to wrap field definitions with `FieldWrapper`.
105 * This is useful to allow return types such as Promises and functions.
106 * @default false
107 *
108 * @exampleMarkdown
109 * ## Enable wrapping fields
110 * ```yml
111 * generates:
112 * path/to/file.ts:
113 * plugins:
114 * - typescript
115 * config:
116 * wrapFieldDefinitions: true
117 * ```
118 */
119 wrapFieldDefinitions?: boolean;
120 /**
121 * @description This will cause the generator to emit types for operations only (basically only enums and scalars)
122 * @default false
123 *
124 * @exampleMarkdown
125 * ## Override all definition types
126 * ```yml
127 * generates:
128 * path/to/file.ts:
129 * plugins:
130 * - typescript
131 * config:
132 * onlyOperationTypes: true
133 * ```
134 */
135 onlyOperationTypes?: boolean;
136}
137export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTypesConfig, TPluginConfig extends ParsedTypesConfig = ParsedTypesConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
138 protected _schema: GraphQLSchema;
139 protected _argumentsTransformer: OperationVariablesToObject;
140 constructor(_schema: GraphQLSchema, rawConfig: TRawConfig, additionalConfig: TPluginConfig, defaultScalars?: NormalizedScalarsMap);
141 protected getExportPrefix(): string;
142 getFieldWrapperValue(): string;
143 getScalarsImports(): string[];
144 get scalarsDefinition(): string;
145 setDeclarationBlockConfig(config: DeclarationBlockConfig): void;
146 setArgumentsTransformer(argumentsTransfomer: OperationVariablesToObject): void;
147 NonNullType(node: NonNullTypeNode): string;
148 getInputObjectDeclarationBlock(node: InputObjectTypeDefinitionNode): DeclarationBlock;
149 InputObjectTypeDefinition(node: InputObjectTypeDefinitionNode): string;
150 InputValueDefinition(node: InputValueDefinitionNode): string;
151 Name(node: NameNode): string;
152 FieldDefinition(node: FieldDefinitionNode): string;
153 UnionTypeDefinition(node: UnionTypeDefinitionNode, key: string | number | undefined, parent: any): string;
154 protected mergeInterfaces(interfaces: string[], hasOtherFields: boolean): string;
155 appendInterfacesAndFieldsToBlock(block: DeclarationBlock, interfaces: string[], fields: string[]): void;
156 getObjectTypeDeclarationBlock(node: ObjectTypeDefinitionNode, originalNode: ObjectTypeDefinitionNode): DeclarationBlock;
157 getFieldComment(node: FieldDefinitionNode): string;
158 protected mergeAllFields(allFields: string[], hasInterfaces: boolean): string;
159 ObjectTypeDefinition(node: ObjectTypeDefinitionNode, key: number | string | undefined, parent: any): string;
160 getInterfaceTypeDeclarationBlock(node: InterfaceTypeDefinitionNode, originalNode: InterfaceTypeDefinitionNode): DeclarationBlock;
161 InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode, key: number | string | undefined, parent: any): string;
162 ScalarTypeDefinition(node: ScalarTypeDefinitionNode): string;
163 protected _buildTypeImport(identifier: string, source: string, asDefault?: boolean): string;
164 protected handleEnumValueMapper(typeIdentifier: string, importIdentifier: string | null, sourceIdentifier: string | null, sourceFile: string | null): string[];
165 getEnumsImports(): string[];
166 EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
167 StringValue(node: StringValueNode): string;
168 protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;
169 DirectiveDefinition(node: DirectiveDefinitionNode): string;
170 getArgumentsObjectDeclarationBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): DeclarationBlock;
171 getArgumentsObjectTypeDefinition(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): string;
172 protected buildArgumentsBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode): string;
173 protected _getScalar(name: string): string;
174 protected _getTypeForNode(node: NamedTypeNode): string;
175 NamedType(node: NamedTypeNode, key: any, parent: any, path: any, ancestors: any): string;
176 ListType(node: ListTypeNode): string;
177 SchemaDefinition(): any;
178 protected getDeprecationReason(directive: DirectiveNode): string | void;
179 protected wrapWithListType(str: string): string;
180}