1 | import type { ApolloEngineOptions } from '@graphql-tools/apollo-engine-loader';
|
2 | import { Source } from '@graphql-tools/utils';
|
3 | import { DocumentNode, GraphQLSchema } from 'graphql';
|
4 | import type { Profiler } from './profiler.js';
|
5 | export declare namespace Types {
|
6 | interface GenerateOptions {
|
7 | filename: string;
|
8 | plugins: Types.ConfiguredPlugin[];
|
9 | schema: DocumentNode;
|
10 | schemaAst?: GraphQLSchema;
|
11 | documents: Types.DocumentFile[];
|
12 | config: {
|
13 | [key: string]: any;
|
14 | };
|
15 | pluginMap: {
|
16 | [name: string]: CodegenPlugin;
|
17 | };
|
18 | skipDocumentsValidation?: Types.SkipDocumentsValidationOptions;
|
19 | pluginContext?: {
|
20 | [key: string]: any;
|
21 | };
|
22 | profiler?: Profiler;
|
23 | cache?<T>(namespace: string, key: string, factory: () => Promise<T>): Promise<T>;
|
24 | documentTransforms?: ConfiguredDocumentTransform[];
|
25 | }
|
26 | type FileOutput = {
|
27 | filename: string;
|
28 | content: string;
|
29 | hooks?: {
|
30 | beforeOneFileWrite?: LifecycleHooksDefinition['beforeOneFileWrite'];
|
31 | afterOneFileWrite?: LifecycleHooksDefinition['afterOneFileWrite'];
|
32 | };
|
33 | };
|
34 | interface DocumentFile extends Source {
|
35 | hash?: string;
|
36 | }
|
37 | type Promisable<T> = T | Promise<T>;
|
38 | type InstanceOrArray<T> = T | T[];
|
39 | /**
|
40 | * @additionalProperties false
|
41 | * @description Loads schema using a pointer, with a custom loader (code file).
|
42 | */
|
43 | interface SchemaWithLoaderOptions {
|
44 | /**
|
45 | * @description Specify a path to a custom code file (local or module) that will handle the schema loading.
|
46 | */
|
47 | loader: string;
|
48 | }
|
49 | interface SchemaWithLoader {
|
50 | [pointer: string]: SchemaWithLoaderOptions;
|
51 | }
|
52 | /**
|
53 | * @additionalProperties false
|
54 | * @description Loads schema using a pointer, without using `require` while looking for schemas in code files.
|
55 | */
|
56 | interface SchemaFromCodeFileOptions {
|
57 | /**
|
58 | * @description Set this to `true` in order to tell codegen not to try to `require` files in order to find schema/docs
|
59 | */
|
60 | noRequire?: boolean;
|
61 | /**
|
62 | * @description Set this to `true` in order to tell codegen not to try to extract GraphQL AST strings schema/docs
|
63 | */
|
64 | noPluck?: boolean;
|
65 | /**
|
66 | * @description Set this to `true` in order to tell codegen to skip documents validation.
|
67 | */
|
68 | assumeValid?: boolean;
|
69 | }
|
70 | interface SchemaFromCodeFile {
|
71 | [path: string]: SchemaFromCodeFileOptions;
|
72 | }
|
73 | /**
|
74 | * @additionalProperties false
|
75 | * @description Loads a schema from remote endpoint, with custom http options.
|
76 | */
|
77 | interface UrlSchemaOptions {
|
78 | /**
|
79 | * @description HTTP headers you wish to add to the HTTP request sent by codegen to fetch your GraphQL remote schema.
|
80 | */
|
81 | headers?: {
|
82 | [headerName: string]: string;
|
83 | };
|
84 | /**
|
85 | * @description Specify a Node module name, or a custom file, to be used instead of standard `fetch`
|
86 | */
|
87 | customFetch?: string;
|
88 | /**
|
89 | * @description HTTP Method to use, either POST (default) or GET.
|
90 | */
|
91 | method?: string;
|
92 | /**
|
93 | * @description Handling the response as SDL will allow you to load schema from remote server that doesn't return a JSON introspection.
|
94 | */
|
95 | handleAsSDL?: boolean;
|
96 | }
|
97 | interface UrlSchemaWithOptions {
|
98 | [url: string]: UrlSchemaOptions;
|
99 | }
|
100 | /**
|
101 | * @additionalProperties false
|
102 | * @description Loads a schema a local file or files, with customized options for parsing/loading.
|
103 | */
|
104 | interface LocalSchemaPathOptions {
|
105 | /**
|
106 | * @description Skips checks for graphql-import syntax and loads the file as-is, without imports support.
|
107 | * @default true
|
108 | */
|
109 | skipGraphQLImport?: boolean;
|
110 | /**
|
111 | * @description Converts all GraphQL comments (`#` sign) to descriptions during the parse phase, to make it available
|
112 | * for plugins later.
|
113 | * @default false
|
114 | */
|
115 | commentDescriptions?: boolean;
|
116 | /**
|
117 | * Set to true to assume the SDL is valid.
|
118 | *
|
119 | * @default false
|
120 | */
|
121 | assumeValidSDL?: boolean;
|
122 | /**
|
123 | * By default, the parser creates AST nodes that know the location
|
124 | * in the source that they correspond to. This configuration flag
|
125 | * disables that behavior for performance or testing.
|
126 | *
|
127 | * @default false
|
128 | */
|
129 | noLocation?: boolean;
|
130 | /**
|
131 | * If enabled, the parser will parse empty fields sets in the Schema
|
132 | * Definition Language. Otherwise, the parser will follow the current
|
133 | * specification.
|
134 | *
|
135 | * This option is provided to ease adoption of the final SDL specification
|
136 | * and will be removed in v16.
|
137 | *
|
138 | * @default false
|
139 | */
|
140 | allowLegacySDLEmptyFields?: boolean;
|
141 | /**
|
142 | * If enabled, the parser will parse implemented interfaces with no `&`
|
143 | * character between each interface. Otherwise, the parser will follow the
|
144 | * current specification.
|
145 | *
|
146 | * This option is provided to ease adoption of the final SDL specification
|
147 | * and will be removed in v16.
|
148 | *
|
149 | * @default false
|
150 | */
|
151 | allowLegacySDLImplementsInterfaces?: boolean;
|
152 | /**
|
153 | * EXPERIMENTAL:
|
154 | *
|
155 | * If enabled, the parser will understand and parse variable definitions
|
156 | * contained in a fragment definition. They'll be represented in the
|
157 | * `variableDefinitions` field of the FragmentDefinitionNode.
|
158 | *
|
159 | * The syntax is identical to normal, query-defined variables. For example:
|
160 | *
|
161 | * fragment A($var: Boolean = false) on T {
|
162 | * ...
|
163 | * }
|
164 | *
|
165 | * Note: this feature is experimental and may change or be removed in the
|
166 | * future.
|
167 | *
|
168 | * @default false
|
169 | */
|
170 | experimentalFragmentVariables?: boolean;
|
171 | }
|
172 | interface LocalSchemaPathWithOptions {
|
173 | [globPath: string]: LocalSchemaPathOptions;
|
174 | }
|
175 | interface ApolloEngineSchemaOptions {
|
176 | 'apollo-engine': ApolloEngineOptions;
|
177 | }
|
178 | interface GitHubSchemaOptions {
|
179 | [githubProtocol: string]: {
|
180 | token: string;
|
181 | };
|
182 | }
|
183 | type SchemaGlobPath = string;
|
184 | /**
|
185 | * @description A URL to your GraphQL endpoint, a local path to `.graphql` file, a glob pattern to your GraphQL schema files, or a JavaScript file that exports the schema to generate code from. This can also be an array which specifies multiple schemas to generate code from. You can read more about the supported formats [here](schema-field#available-formats).
|
186 | */
|
187 | type Schema = string | UrlSchemaWithOptions | ApolloEngineSchemaOptions | GitHubSchemaOptions | LocalSchemaPathWithOptions | SchemaGlobPath | SchemaWithLoader | SchemaFromCodeFile;
|
188 | type OperationDocumentGlobPath = string;
|
189 | /**
|
190 | * @additionalProperties false
|
191 | * @description Specify a path to a custom loader for your GraphQL documents.
|
192 | */
|
193 | interface CustomDocumentLoaderOptions {
|
194 | /**
|
195 | * @description Specify a path to a custom code file (local or module) that will handle the documents loading.
|
196 | */
|
197 | loader: string;
|
198 | }
|
199 | interface CustomDocumentLoader {
|
200 | [path: string]: CustomDocumentLoaderOptions;
|
201 | }
|
202 | type OperationDocument = OperationDocumentGlobPath | CustomDocumentLoader;
|
203 | type PluginConfig<T = any> = {
|
204 | [key: string]: T;
|
205 | };
|
206 | interface ConfiguredPlugin {
|
207 | [name: string]: PluginConfig;
|
208 | }
|
209 | type NamedPlugin = string;
|
210 | type NamedPreset = string;
|
211 | type OutputConfig = NamedPlugin | ConfiguredPlugin;
|
212 | type PresetNamesBase = 'client' | 'near-operation-file' | 'gql-tag-operations' | 'graphql-modules' | 'import-types';
|
213 | type PresetNames = `${PresetNamesBase}-preset` | PresetNamesBase;
|
214 | /**
|
215 | * @additionalProperties false
|
216 | */
|
217 | interface ConfiguredOutput {
|
218 | /**
|
219 | * @type array
|
220 | * @items { "$ref": "#/definitions/GeneratedPluginsMap" }
|
221 | * @description List of plugins to apply to this current output file.
|
222 | *
|
223 | * You can either specify plugins from the community using the NPM package name (after you installed it in your project), or you can use a path to a local file for custom plugins.
|
224 | *
|
225 | * You can find a list of available plugins here: https://the-guild.dev/graphql/codegen/docs/plugins/index
|
226 | * Need a custom plugin? read this: https://the-guild.dev/graphql/codegen/docs/custom-codegen/index
|
227 | */
|
228 | plugins?: OutputConfig[];
|
229 | /**
|
230 | * @description If your setup uses Preset to have a more dynamic setup and output, set the name of your preset here.
|
231 | *
|
232 | * Presets are a way to have more than one file output, for example: https://the-guild.dev/graphql/codegen/docs/presets/near-operation-file
|
233 | *
|
234 | * You can either specify a preset from the community using the NPM package name (after you installed it in your project), or you can use a path to a local file for a custom preset.
|
235 | *
|
236 | * List of available presets: https://graphql-code-generator.com/docs/presets/presets-index
|
237 | */
|
238 | preset?: PresetNames | OutputPreset;
|
239 | /**
|
240 | * @description If your setup uses Preset to have a more dynamic setup and output, set the configuration object of your preset here.
|
241 | *
|
242 | * List of available presets: https://graphql-code-generator.com/docs/presets/presets-index
|
243 | */
|
244 | presetConfig?: {
|
245 | [key: string]: any;
|
246 | };
|
247 | /**
|
248 | * @description A flag to overwrite files if they already exist when generating code (`true` by default).
|
249 | *
|
250 | * For more details: https://graphql-code-generator.com/docs/config-reference/codegen-config
|
251 | */
|
252 | overwrite?: boolean;
|
253 | /**
|
254 | * @description A pointer(s) to your GraphQL documents: query, mutation, subscription and fragment. These documents will be loaded into for all your output files.
|
255 | * You can use one of the following:
|
256 | *
|
257 | * - Path to a local `.graphql` file
|
258 | * - Path to a code file (for example: `.js` or `.tsx`) containing GraphQL operation strings.
|
259 | * - Glob expression pointing to multiple `.graphql` files
|
260 | * - Glob expression pointing to multiple code files
|
261 | * - Inline string containing GraphQL SDL operation definition
|
262 | *
|
263 | * You can specify either a single file, or multiple.
|
264 | *
|
265 | * For more details: https://graphql-code-generator.com/docs/config-reference/documents-field
|
266 | */
|
267 | documents?: InstanceOrArray<OperationDocument>;
|
268 | /**
|
269 | * @description A pointer(s) to your GraphQL schema. This schema will be available only for this specific `generates` record.
|
270 | * You can use one of the following:
|
271 | *
|
272 | * - URL pointing to a GraphQL endpoint
|
273 | * - Path to a local `.json` file
|
274 | * - Path to a local `.graphql` file
|
275 | * - Glob expression pointing to multiple `.graphql` files
|
276 | * - Path to a local code file (for example: `.js`) that exports `GraphQLSchema` object
|
277 | * - Inline string containing GraphQL SDL schema definition
|
278 | *
|
279 | * You can specify either a single schema, or multiple, and GraphQL Code Generator will merge the schemas into a single schema.
|
280 | *
|
281 | * For more details: https://graphql-code-generator.com/docs/config-reference/schema-field
|
282 | */
|
283 | schema?: InstanceOrArray<Schema>;
|
284 | /**
|
285 | * @description Configuration object containing key => value that will be passes to the plugins.
|
286 | * Specifying configuration in this level of your configuration file will pass it to all plugins, in all outputs.
|
287 | *
|
288 | * The options may vary depends on what plugins you are using.
|
289 | *
|
290 | * For more details: https:
|
291 | */
|
292 | config?: PluginConfig;
|
293 | |
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | hooks?: Partial<LifecycleHooksDefinition>;
|
300 | |
301 |
|
302 |
|
303 | documentTransforms?: OutputDocumentTransform[];
|
304 | |
305 |
|
306 |
|
307 | watchPattern?: string | string[];
|
308 | }
|
309 | type PresetFnArgs<Config = any, PluginConfig = {
|
310 | [key: string]: any;
|
311 | }> = {
|
312 | presetConfig: Config;
|
313 | baseOutputDir: string;
|
314 | plugins: Types.ConfiguredPlugin[];
|
315 | schema: DocumentNode;
|
316 | schemaAst?: GraphQLSchema;
|
317 | documents: Types.DocumentFile[];
|
318 | config: PluginConfig;
|
319 | pluginMap: {
|
320 | [name: string]: CodegenPlugin;
|
321 | };
|
322 | pluginContext?: {
|
323 | [name: string]: any;
|
324 | };
|
325 | profiler?: Profiler;
|
326 | cache?<T>(namespace: string, key: string, factory: () => Promise<T>): Promise<T>;
|
327 | documentTransforms?: ConfiguredDocumentTransform[];
|
328 | };
|
329 | type OutputPreset<TPresetConfig = any> = {
|
330 | buildGeneratesSection: (options: PresetFnArgs<TPresetConfig>) => Promisable<GenerateOptions[]>;
|
331 | prepareDocuments?: (outputFilePath: string, outputSpecificDocuments: Types.OperationDocument[]) => Promisable<Types.OperationDocument[]>;
|
332 | };
|
333 | type RequireExtension = InstanceOrArray<string>;
|
334 | type PackageLoaderFn<TExpectedResult> = (name: string) => Promisable<TExpectedResult>;
|
335 | |
336 |
|
337 |
|
338 |
|
339 | interface Config {
|
340 | |
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | schema?: InstanceOrArray<Schema>;
|
356 | |
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 | require?: RequireExtension;
|
366 | |
367 |
|
368 |
|
369 |
|
370 | customFetch?: string;
|
371 | |
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 | documents?: InstanceOrArray<OperationDocument>;
|
386 | |
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 | config?: PluginConfig;
|
397 | |
398 |
|
399 |
|
400 |
|
401 |
|
402 | generates: {
|
403 | [outputPath: string]: ConfiguredOutput | ConfiguredPlugin[];
|
404 | };
|
405 | |
406 |
|
407 |
|
408 |
|
409 |
|
410 | overwrite?: boolean;
|
411 | |
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | watch?: boolean | string | string[];
|
419 | |
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 | watchConfig?: {
|
429 | usePolling: boolean;
|
430 | interval?: number;
|
431 | };
|
432 | |
433 |
|
434 |
|
435 | ignoreNoDocuments?: boolean;
|
436 | |
437 |
|
438 |
|
439 | emitLegacyCommonJSImports?: boolean;
|
440 | |
441 |
|
442 |
|
443 | silent?: boolean;
|
444 | |
445 |
|
446 |
|
447 | verbose?: boolean;
|
448 | |
449 |
|
450 |
|
451 | debug?: boolean;
|
452 | |
453 |
|
454 |
|
455 | errorsOnly?: boolean;
|
456 | |
457 |
|
458 |
|
459 | pluginLoader?: PackageLoaderFn<CodegenPlugin>;
|
460 | |
461 |
|
462 |
|
463 | pluginContext?: {
|
464 | [key: string]: any;
|
465 | };
|
466 | |
467 |
|
468 |
|
469 |
|
470 |
|
471 | pluckConfig?: {
|
472 | |
473 |
|
474 |
|
475 | modules?: Array<{
|
476 | |
477 |
|
478 |
|
479 | name: string;
|
480 | |
481 |
|
482 |
|
483 | identifier?: string;
|
484 | }>;
|
485 | |
486 |
|
487 |
|
488 | gqlMagicComment?: string;
|
489 | |
490 |
|
491 |
|
492 | globalIdentifier?: string;
|
493 | |
494 |
|
495 |
|
496 | globalGqlIdentifierName?: string | string[];
|
497 | };
|
498 | |
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 | hooks?: Partial<LifecycleHooksDefinition>;
|
505 | |
506 |
|
507 |
|
508 | noSilentErrors?: boolean;
|
509 | }
|
510 | type ComplexPluginOutput<M = Record<string, unknown>> = {
|
511 | content: string;
|
512 | prepend?: string[];
|
513 | append?: string[];
|
514 | meta?: M;
|
515 | };
|
516 | type PluginOutput = string | ComplexPluginOutput;
|
517 | type HookFunction = (...args: any[]) => void | Promise<void>;
|
518 | type HookAlterFunction = (...args: any[]) => void | string | Promise<void | string>;
|
519 | type LifeCycleHookValue = string | HookFunction | (string | HookFunction)[];
|
520 | type LifeCycleAlterHookValue = string | HookFunction | HookAlterFunction | (string | HookFunction | HookAlterFunction)[];
|
521 | |
522 |
|
523 |
|
524 |
|
525 | type LifecycleHooksDefinition = {
|
526 | |
527 |
|
528 |
|
529 |
|
530 |
|
531 | afterStart: LifeCycleHookValue;
|
532 | |
533 |
|
534 |
|
535 |
|
536 |
|
537 | beforeDone: LifeCycleHookValue;
|
538 | |
539 |
|
540 |
|
541 |
|
542 | onWatchTriggered: LifeCycleHookValue;
|
543 | |
544 |
|
545 |
|
546 | onError: LifeCycleHookValue;
|
547 | |
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 | afterOneFileWrite: LifeCycleHookValue;
|
554 | |
555 |
|
556 |
|
557 |
|
558 | afterAllFileWrite: LifeCycleHookValue;
|
559 | |
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 | beforeOneFileWrite: LifeCycleAlterHookValue;
|
568 | |
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 | beforeAllFileWrite: LifeCycleHookValue;
|
576 | };
|
577 | type SkipDocumentsValidationOptions = {
|
578 | |
579 |
|
580 |
|
581 |
|
582 | ignoreRules?: string[];
|
583 | |
584 |
|
585 |
|
586 | skipDuplicateValidation?: boolean;
|
587 | |
588 |
|
589 |
|
590 | skipValidationAgainstSchema?: boolean;
|
591 | } | boolean;
|
592 | type DocumentTransformFunction<Config = object> = (options: {
|
593 | documents: Types.DocumentFile[];
|
594 | schema: DocumentNode;
|
595 | config: Config;
|
596 | pluginContext?: {
|
597 | [key: string]: any;
|
598 | };
|
599 | }) => Types.Promisable<Types.DocumentFile[]>;
|
600 | type DocumentTransformObject<T = object> = {
|
601 | transform: DocumentTransformFunction<T>;
|
602 | };
|
603 | type DocumentTransformFileName = string;
|
604 | type DocumentTransformFileConfig<T = object> = {
|
605 | [name: DocumentTransformFileName]: T;
|
606 | };
|
607 | type DocumentTransformFile<T> = DocumentTransformFileName | DocumentTransformFileConfig<T>;
|
608 | type OutputDocumentTransform<T = object> = DocumentTransformObject<T> | DocumentTransformFile<T>;
|
609 | type ConfiguredDocumentTransform<T = object> = {
|
610 | name: string;
|
611 | transformObject: DocumentTransformObject<T>;
|
612 | config?: T;
|
613 | };
|
614 | }
|
615 | export declare function isComplexPluginOutput(obj: Types.PluginOutput): obj is Types.ComplexPluginOutput;
|
616 | export type PluginFunction<T = any, TOutput extends Types.PluginOutput = Types.PluginOutput> = (schema: GraphQLSchema, documents: Types.DocumentFile[], config: T, info?: {
|
617 | outputFile?: string;
|
618 | allPlugins?: Types.ConfiguredPlugin[];
|
619 | pluginContext?: {
|
620 | [key: string]: any;
|
621 | };
|
622 | [key: string]: any;
|
623 | }) => Types.Promisable<TOutput>;
|
624 | export type PluginValidateFn<T = any> = (schema: GraphQLSchema, documents: Types.DocumentFile[], config: T, outputFile: string, allPlugins: Types.ConfiguredPlugin[], pluginContext?: {
|
625 | [key: string]: any;
|
626 | }) => Types.Promisable<void>;
|
627 | export type AddToSchemaResult = string | DocumentNode | undefined;
|
628 | export interface CodegenPlugin<T = any> {
|
629 | plugin: PluginFunction<T>;
|
630 | addToSchema?: AddToSchemaResult | ((config: T) => AddToSchemaResult);
|
631 | validate?: PluginValidateFn;
|
632 | }
|
633 |
|
\ | No newline at end of file |