1 | import { ParsedConfig, RawConfig, BaseVisitor, BaseVisitorConvertOptions } from './base-visitor';
|
2 | import { NormalizedScalarsMap, EnumValuesMap, ParsedEnumValuesMap, DeclarationKind, ConvertOptions } from './types';
|
3 | import { DeclarationBlockConfig } from './utils';
|
4 | import { NameNode, ListTypeNode, NamedTypeNode, FieldDefinitionNode, ObjectTypeDefinitionNode, GraphQLSchema, NonNullTypeNode, UnionTypeDefinitionNode, ScalarTypeDefinitionNode, InterfaceTypeDefinitionNode, GraphQLNamedType, DirectiveDefinitionNode, InputValueDefinitionNode, EnumTypeDefinitionNode, ASTNode } from 'graphql';
|
5 | import { OperationVariablesToObject } from './variables-to-object';
|
6 | import { ParsedMapper } from './mappers';
|
7 | import { ApolloFederation } from '@graphql-codegen/plugin-helpers';
|
8 | export interface ParsedResolversConfig extends ParsedConfig {
|
9 | contextType: ParsedMapper;
|
10 | fieldContextTypes: Array<string>;
|
11 | rootValueType: ParsedMapper;
|
12 | mappers: {
|
13 | [typeName: string]: ParsedMapper;
|
14 | };
|
15 | defaultMapper: ParsedMapper | null;
|
16 | avoidOptionals: boolean;
|
17 | addUnderscoreToArgsType: boolean;
|
18 | enumValues: ParsedEnumValuesMap;
|
19 | resolverTypeWrapperSignature: string;
|
20 | federation: boolean;
|
21 | enumPrefix: boolean;
|
22 | optionalResolveType: boolean;
|
23 | immutableTypes: boolean;
|
24 | namespacedImportName: string;
|
25 | resolverTypeSuffix: string;
|
26 | allResolversTypeName: string;
|
27 | }
|
28 | export interface RawResolversConfig extends RawConfig {
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | addUnderscoreToArgsType?: boolean;
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | contextType?: string;
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | fieldContextTypes?: Array<string>;
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | rootValueType?: string;
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | mapperTypeSuffix?: string;
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | mappers?: {
|
127 | [typeName: string]: string;
|
128 | };
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | defaultMapper?: string;
|
169 | |
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | avoidOptionals?: boolean;
|
186 | |
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 | showUnusedMappers?: boolean;
|
202 | |
203 |
|
204 |
|
205 |
|
206 |
|
207 | enumValues?: EnumValuesMap;
|
208 | |
209 |
|
210 |
|
211 |
|
212 | resolverTypeWrapperSignature?: string;
|
213 | |
214 |
|
215 |
|
216 |
|
217 | federation?: boolean;
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | enumPrefix?: boolean;
|
231 | |
232 |
|
233 |
|
234 |
|
235 | optionalResolveType?: boolean;
|
236 | |
237 |
|
238 |
|
239 |
|
240 | immutableTypes?: boolean;
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 | namespacedImportName?: string;
|
247 | |
248 |
|
249 |
|
250 |
|
251 | resolverTypeSuffix?: string;
|
252 | |
253 |
|
254 |
|
255 |
|
256 | allResolversTypeName?: string;
|
257 | }
|
258 | export declare type ResolverTypes = {
|
259 | [gqlType: string]: string;
|
260 | };
|
261 | export declare type ResolverParentTypes = {
|
262 | [gqlType: string]: string;
|
263 | };
|
264 | export declare type GroupedMappers = Record<string, {
|
265 | identifier: string;
|
266 | asDefault?: boolean;
|
267 | }[]>;
|
268 | declare type FieldContextTypeMap = Record<string, ParsedMapper>;
|
269 | export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig = RawResolversConfig, TPluginConfig extends ParsedResolversConfig = ParsedResolversConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
|
270 | private _schema;
|
271 | protected _parsedConfig: TPluginConfig;
|
272 | protected _declarationBlockConfig: DeclarationBlockConfig;
|
273 | protected _collectedResolvers: {
|
274 | [key: string]: string;
|
275 | };
|
276 | protected _collectedDirectiveResolvers: {
|
277 | [key: string]: string;
|
278 | };
|
279 | protected _variablesTransfomer: OperationVariablesToObject;
|
280 | protected _usedMappers: {
|
281 | [key: string]: boolean;
|
282 | };
|
283 | protected _resolversTypes: ResolverTypes;
|
284 | protected _resolversParentTypes: ResolverParentTypes;
|
285 | protected _rootTypeNames: string[];
|
286 | protected _globalDeclarations: Set<string>;
|
287 | protected _federation: ApolloFederation;
|
288 | protected _hasScalars: boolean;
|
289 | protected _hasFederation: boolean;
|
290 | protected _fieldContextTypeMap: FieldContextTypeMap;
|
291 | constructor(rawConfig: TRawConfig, additionalConfig: TPluginConfig, _schema: GraphQLSchema, defaultScalars?: NormalizedScalarsMap);
|
292 | getResolverTypeWrapperSignature(): string;
|
293 | protected shouldMapType(type: GraphQLNamedType, checkedBefore?: {
|
294 | [typeName: string]: boolean;
|
295 | }, duringCheck?: string[]): boolean;
|
296 | convertName(node: ASTNode | string, options?: BaseVisitorConvertOptions & ConvertOptions, applyNamespacedImport?: boolean): string;
|
297 | protected createResolversFields(applyWrapper: (str: string) => string, clearWrapper: (str: string) => string, getTypeToUse: (str: string) => string, shouldInclude?: (type: GraphQLNamedType) => boolean): ResolverTypes;
|
298 | protected replaceFieldsInType(typeName: string, relevantFields: {
|
299 | addOptionalSign: boolean;
|
300 | fieldName: string;
|
301 | replaceWithType: string;
|
302 | }[]): string;
|
303 | protected applyMaybe(str: string): string;
|
304 | protected applyResolverTypeWrapper(str: string): string;
|
305 | protected clearMaybe(str: string): string;
|
306 | protected clearResolverTypeWrapper(str: string): string;
|
307 | protected wrapWithArray(t: string): string;
|
308 | protected createFieldContextTypeMap(): FieldContextTypeMap;
|
309 | buildResolversTypes(): string;
|
310 | buildResolversParentTypes(): string;
|
311 | get schema(): GraphQLSchema;
|
312 | get defaultMapperType(): string;
|
313 | get unusedMappers(): string[];
|
314 | get globalDeclarations(): string[];
|
315 | protected isMapperImported(groupedMappers: GroupedMappers, identifier: string, source: string): boolean;
|
316 | get mappersImports(): string[];
|
317 | protected buildMapperImport(source: string, types: {
|
318 | identifier: string;
|
319 | asDefault?: boolean;
|
320 | }[]): string | null;
|
321 | setDeclarationBlockConfig(config: DeclarationBlockConfig): void;
|
322 | setVariablesTransformer(variablesTransfomer: OperationVariablesToObject): void;
|
323 | hasScalars(): boolean;
|
324 | hasFederation(): boolean;
|
325 | getRootResolver(): string;
|
326 | protected formatRootResolver(schemaTypeName: string, resolverType: string, declarationKind: DeclarationKind): string;
|
327 | getAllDirectiveResolvers(): string;
|
328 | Name(node: NameNode): string;
|
329 | ListType(node: ListTypeNode): string;
|
330 | protected _getScalar(name: string): string;
|
331 | NamedType(node: NamedTypeNode): string;
|
332 | NonNullType(node: NonNullTypeNode): string;
|
333 | protected markMapperAsUsed(name: string): void;
|
334 | protected getTypeToUse(name: string): string;
|
335 | protected getParentTypeToUse(name: string): string;
|
336 | protected getParentTypeForSignature(node: FieldDefinitionNode): string;
|
337 | protected transformParentGenericType(parentType: string): string;
|
338 | FieldDefinition(node: FieldDefinitionNode, key: string | number, parent: any): (parentName: string) => string | null;
|
339 | protected applyRequireFields(argsType: string, fields: InputValueDefinitionNode[]): string;
|
340 | protected applyOptionalFields(argsType: string, fields: readonly InputValueDefinitionNode[]): string;
|
341 | ObjectTypeDefinition(node: ObjectTypeDefinitionNode): string;
|
342 | UnionTypeDefinition(node: UnionTypeDefinitionNode, key: string | number, parent: any): string;
|
343 | ScalarTypeDefinition(node: ScalarTypeDefinitionNode): string;
|
344 | DirectiveDefinition(node: DirectiveDefinitionNode, key: string | number, parent: any): string;
|
345 | protected buildEnumResolverContentBlock(node: EnumTypeDefinitionNode, mappedEnumType: string): string;
|
346 | protected buildEnumResolversExplicitMappedValues(node: EnumTypeDefinitionNode, valuesMapping: {
|
347 | [valueName: string]: string | number;
|
348 | }): string;
|
349 | EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
|
350 | InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode): string;
|
351 | SchemaDefinition(): any;
|
352 | }
|
353 | export {};
|