1 | import { AvoidOptionalsConfig, RawTypesConfig } from '@graphql-codegen/visitor-plugin-common';
|
2 | /**
|
3 | * @description This plugin generates the base TypeScript types, based on your GraphQL schema.
|
4 | *
|
5 | * The types generated by this plugin are simple, and refers to the exact structure of your schema, and it's used as the base types for other plugins (such as `typescript-operations` / `typescript-resolvers`)
|
6 | */
|
7 | export interface TypeScriptPluginConfig extends RawTypesConfig {
|
8 | /**
|
9 | * @description This will cause the generator to avoid using TypeScript optionals (`?`) on types,
|
10 | * so the following definition: `type A { myField: String }` will output `myField: Maybe<string>`
|
11 | * instead of `myField?: Maybe<string>`.
|
12 | * @default false
|
13 | *
|
14 | * @exampleMarkdown
|
15 | * ## Override all definition types
|
16 | *
|
17 | * ```ts filename="codegen.ts"
|
18 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
19 | *
|
20 | * const config: CodegenConfig = {
|
21 | * // ...
|
22 | * generates: {
|
23 | * 'path/to/file.ts': {
|
24 | * plugins: ['typescript'],
|
25 | * config: {
|
26 | * avoidOptionals: true
|
27 | * }
|
28 | * }
|
29 | * }
|
30 | * }
|
31 | * export default config
|
32 | * ```
|
33 | *
|
34 | * ## Override only specific definition types
|
35 | *
|
36 | * ```ts filename="codegen.ts"
|
37 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
38 | *
|
39 | * const config: CodegenConfig = {
|
40 | * // ...
|
41 | * generates: {
|
42 | * 'path/to/file.ts': {
|
43 | * plugins: ['typescript'],
|
44 | * config: {
|
45 | * avoidOptionals: {
|
46 | * field: true
|
47 | * inputValue: true
|
48 | * object: true
|
49 | * defaultValue: true
|
50 | * }
|
51 | * }
|
52 | * }
|
53 | * }
|
54 | * }
|
55 | * export default config
|
56 | * ```
|
57 | */
|
58 | avoidOptionals?: boolean | AvoidOptionalsConfig;
|
59 | /**
|
60 | * @description Will prefix every generated `enum` with `const`, you can read more about const enums here: https://www.typescriptlang.org/docs/handbook/enums.html.
|
61 | * @default false
|
62 | *
|
63 | * @exampleMarkdown
|
64 | * ```ts filename="codegen.ts"
|
65 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
66 | *
|
67 | * const config: CodegenConfig = {
|
68 | * // ...
|
69 | * generates: {
|
70 | * 'path/to/file.ts': {
|
71 | * plugins: ['typescript'],
|
72 | * config: {
|
73 | * constEnums: true
|
74 | * }
|
75 | * }
|
76 | * }
|
77 | * }
|
78 | * export default config
|
79 | * ```
|
80 | */
|
81 | constEnums?: boolean;
|
82 | /**
|
83 | * @description Generates enum as TypeScript string union `type` instead of an `enum`. Useful if you wish to generate `.d.ts` declaration file instead of `.ts`, or if you want to avoid using TypeScript enums due to bundle size concerns
|
84 | * @default false
|
85 | *
|
86 | * @exampleMarkdown
|
87 | * ```ts filename="codegen.ts"
|
88 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
89 | *
|
90 | * const config: CodegenConfig = {
|
91 | * // ...
|
92 | * generates: {
|
93 | * 'path/to/file.ts': {
|
94 | * plugins: ['typescript'],
|
95 | * config: {
|
96 | * enumsAsTypes: true
|
97 | * }
|
98 | * }
|
99 | * }
|
100 | * }
|
101 | * export default config
|
102 | * ```
|
103 | */
|
104 | enumsAsTypes?: boolean;
|
105 | /**
|
106 | * @description Controls whether to preserve typescript enum values as numbers
|
107 | * @default false
|
108 | *
|
109 | * @exampleMarkdown
|
110 | * ```ts filename="codegen.ts"
|
111 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
112 | *
|
113 | * const config: CodegenConfig = {
|
114 | * // ...
|
115 | * generates: {
|
116 | * 'path/to/file.ts': {
|
117 | * plugins: ['typescript'],
|
118 | * config: {
|
119 | * numericEnums: true
|
120 | * }
|
121 | * }
|
122 | * }
|
123 | * }
|
124 | * export default config
|
125 | * ```
|
126 | */
|
127 | numericEnums?: boolean;
|
128 | /**
|
129 | * @description This option controls whether or not a catch-all entry is added to enum type definitions for values that may be added in the future.
|
130 | * This is useful if you are using `relay`.
|
131 | * @default false
|
132 | *
|
133 | * @exampleMarkdown
|
134 | * ```ts filename="codegen.ts"
|
135 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
136 | *
|
137 | * const config: CodegenConfig = {
|
138 | * // ...
|
139 | * generates: {
|
140 | * 'path/to/file.ts': {
|
141 | * plugins: ['typescript'],
|
142 | * config: {
|
143 | * enumsAsTypes: true,
|
144 | * futureProofEnums: true
|
145 | * }
|
146 | * }
|
147 | * }
|
148 | * }
|
149 | * export default config
|
150 | * ```
|
151 | */
|
152 | futureProofEnums?: boolean;
|
153 | /**
|
154 | * @description This option controls whether or not a catch-all entry is added to union type definitions for values that may be added in the future.
|
155 | * This is useful if you are using `relay`.
|
156 | * @default false
|
157 | *
|
158 | * @exampleMarkdown
|
159 | * ```ts filename="codegen.ts"
|
160 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
161 | *
|
162 | * const config: CodegenConfig = {
|
163 | * // ...
|
164 | * generates: {
|
165 | * 'path/to/file.ts': {
|
166 | * plugins: ['typescript'],
|
167 | * config: {
|
168 | * futureProofUnions: true
|
169 | * }
|
170 | * }
|
171 | * }
|
172 | * }
|
173 | * export default config
|
174 | * ```
|
175 | */
|
176 | futureProofUnions?: boolean;
|
177 | /**
|
178 | * @description Generates enum as TypeScript `const assertions` instead of `enum`. This can even be used to enable enum-like patterns in plain JavaScript code if you choose not to use TypeScript’s enum construct.
|
179 | * @default false
|
180 | *
|
181 | * @exampleMarkdown
|
182 | * ```ts filename="codegen.ts"
|
183 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
184 | *
|
185 | * const config: CodegenConfig = {
|
186 | * // ...
|
187 | * generates: {
|
188 | * 'path/to/file.ts': {
|
189 | * plugins: ['typescript'],
|
190 | * config: {
|
191 | * enumsAsConst: true
|
192 | * }
|
193 | * }
|
194 | * }
|
195 | * }
|
196 | * export default config
|
197 | * ```
|
198 | */
|
199 | enumsAsConst?: boolean;
|
200 | /**
|
201 | * @description This will cause the generator to emit types for enums only.
|
202 | * @default false
|
203 | *
|
204 | * @exampleMarkdown
|
205 | * Override all definition types
|
206 | *
|
207 | * ```ts filename="codegen.ts"
|
208 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
209 | *
|
210 | * const config: CodegenConfig = {
|
211 | * // ...
|
212 | * generates: {
|
213 | * 'path/to/file.ts': {
|
214 | * plugins: ['typescript'],
|
215 | * config: {
|
216 | * onlyEnums: true
|
217 | * }
|
218 | * }
|
219 | * }
|
220 | * }
|
221 | * export default config
|
222 | * ```
|
223 | */
|
224 | onlyEnums?: boolean;
|
225 | /**
|
226 | * @description This will cause the generator to emit types for operations only (basically only enums and scalars).
|
227 | * Interacts well with `preResolveTypes: true`
|
228 | * @default false
|
229 | *
|
230 | * @exampleMarkdown
|
231 | * Override all definition types
|
232 | *
|
233 | * ```ts filename="codegen.ts"
|
234 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
235 | *
|
236 | * const config: CodegenConfig = {
|
237 | * // ...
|
238 | * generates: {
|
239 | * 'path/to/file.ts': {
|
240 | * plugins: ['typescript'],
|
241 | * config: {
|
242 | * onlyOperationTypes: true
|
243 | * }
|
244 | * }
|
245 | * }
|
246 | * }
|
247 | * export default config
|
248 | * ```
|
249 | */
|
250 | onlyOperationTypes?: boolean;
|
251 | /**
|
252 | * @description Generates immutable types by adding `readonly` to properties and uses `ReadonlyArray`.
|
253 | * @default false
|
254 | *
|
255 | * @exampleMarkdown
|
256 | * ```ts filename="codegen.ts"
|
257 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
258 | *
|
259 | * const config: CodegenConfig = {
|
260 | * // ...
|
261 | * generates: {
|
262 | * 'path/to/file.ts': {
|
263 | * plugins: ['typescript'],
|
264 | * config: {
|
265 | * immutableTypes: true
|
266 | * }
|
267 | * }
|
268 | * }
|
269 | * }
|
270 | * export default config
|
271 | * ```
|
272 | */
|
273 | immutableTypes?: boolean;
|
274 | /**
|
275 | * @description Allow to override the type value of `Maybe`.
|
276 | * @default T | null
|
277 | *
|
278 | * @exampleMarkdown
|
279 | * ## Allow undefined
|
280 | *
|
281 | * ```ts filename="codegen.ts"
|
282 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
283 | *
|
284 | * const config: CodegenConfig = {
|
285 | * // ...
|
286 | * generates: {
|
287 | * 'path/to/file.ts': {
|
288 | * plugins: ['typescript'],
|
289 | * config: {
|
290 | * maybeValue: 'T | null | undefined'
|
291 | * }
|
292 | * }
|
293 | * }
|
294 | * }
|
295 | * export default config
|
296 | * ```
|
297 | *
|
298 | * ## Allow `null` in resolvers:
|
299 | *
|
300 | * ```ts filename="codegen.ts"
|
301 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
302 | *
|
303 | * const config: CodegenConfig = {
|
304 | * // ...
|
305 | * generates: {
|
306 | * 'path/to/file.ts': {
|
307 | * plugins: ['typescript', 'typescript-resolvers'],
|
308 | * config: {
|
309 | * maybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'
|
310 | * }
|
311 | * }
|
312 | * }
|
313 | * }
|
314 | * export default config
|
315 | * ```
|
316 | */
|
317 | maybeValue?: string;
|
318 | /**
|
319 | * @description Allow to override the type value of `Maybe` for input types and arguments.
|
320 | * This is useful in case you want to differentiate between the wrapper of input and output types.
|
321 | * By default, this type just refers to `Maybe` type, but you can override its definition.
|
322 | *
|
323 | * @default Maybe<T>
|
324 | *
|
325 | * @exampleMarkdown
|
326 | * ## Allow undefined
|
327 | * ```ts filename="codegen.ts"
|
328 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
329 | *
|
330 | * const config: CodegenConfig = {
|
331 | * // ...
|
332 | * generates: {
|
333 | * 'path/to/file.ts': {
|
334 | * plugins: ['typescript'],
|
335 | * config: {
|
336 | * inputMaybeValue: 'T | null | undefined'
|
337 | * }
|
338 | * }
|
339 | * }
|
340 | * }
|
341 | * export default config
|
342 | * ```
|
343 | *
|
344 | * ## Allow `null` in resolvers:
|
345 | * ```ts filename="codegen.ts"
|
346 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
347 | *
|
348 | * const config: CodegenConfig = {
|
349 | * // ...
|
350 | * generates: {
|
351 | * 'path/to/file.ts': {
|
352 | * plugins: ['typescript'],
|
353 | * config: {
|
354 | * inputMaybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'
|
355 | * }
|
356 | * }
|
357 | * }
|
358 | * }
|
359 | * export default config
|
360 | * ```
|
361 | */
|
362 | inputMaybeValue?: string;
|
363 | /**
|
364 | * @description Set to `true` in order to generate output without `export` modifier.
|
365 | * This is useful if you are generating `.d.ts` file and want it to be globally available.
|
366 | * @default false
|
367 | *
|
368 | * @exampleMarkdown
|
369 | * ## Disable all export from a file
|
370 | *
|
371 | * ```ts filename="codegen.ts"
|
372 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
373 | *
|
374 | * const config: CodegenConfig = {
|
375 | * // ...
|
376 | * generates: {
|
377 | * 'path/to/file.ts': {
|
378 | * plugins: ['typescript'],
|
379 | * config: {
|
380 | * noExport: true
|
381 | * }
|
382 | * }
|
383 | * }
|
384 | * }
|
385 | * export default config
|
386 | * ```
|
387 | */
|
388 | noExport?: boolean;
|
389 | /**
|
390 | * @description Set the value to `true` in order to disable all description generation.
|
391 | * @default false
|
392 | *
|
393 | * @exampleMarkdown
|
394 | * ## Disable description generation
|
395 | * ```ts filename="codegen.ts"
|
396 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
397 | *
|
398 | * const config: CodegenConfig = {
|
399 | * // ...
|
400 | * generates: {
|
401 | * 'path/to/file.ts': {
|
402 | * plugins: ['typescript'],
|
403 | * config: {
|
404 | * disableDescriptions: true
|
405 | * }
|
406 | * }
|
407 | * }
|
408 | * }
|
409 | * export default config
|
410 | * ```
|
411 | */
|
412 | disableDescriptions?: boolean;
|
413 | /**
|
414 | * @description When a GraphQL interface is used for a field, this flag will use the implementing types, instead of the interface itself.
|
415 | * @default false
|
416 | *
|
417 | * @exampleMarkdown
|
418 | * ## Override all definition types
|
419 | *
|
420 | * ```ts filename="codegen.ts"
|
421 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
422 | *
|
423 | * const config: CodegenConfig = {
|
424 | * // ...
|
425 | * generates: {
|
426 | * 'path/to/file.ts': {
|
427 | * plugins: ['typescript'],
|
428 | * config: {
|
429 | * useImplementingTypes: true
|
430 | * }
|
431 | * }
|
432 | * }
|
433 | * }
|
434 | * export default config
|
435 | * ```
|
436 | */
|
437 | useImplementingTypes?: boolean;
|
438 | /**
|
439 | * @name wrapEntireFieldDefinitions
|
440 | * @type boolean
|
441 | * @description Set to `true` in order to wrap field definitions with `EntireFieldWrapper`.
|
442 | * This is useful to allow return types such as Promises and functions for fields.
|
443 | * Differs from `wrapFieldDefinitions` in that this wraps the entire field definition if i.e. the field is an Array, while
|
444 | * `wrapFieldDefinitions` will wrap every single value inside the array.
|
445 | * @default false
|
446 | *
|
447 | * @example Enable wrapping entire fields
|
448 | * ```ts filename="codegen.ts"
|
449 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
450 | *
|
451 | * const config: CodegenConfig = {
|
452 | * // ...
|
453 | * generates: {
|
454 | * 'path/to/file.ts': {
|
455 | * plugins: ['typescript'],
|
456 | * config: {
|
457 | * wrapEntireFieldDefinitions: true
|
458 | * }
|
459 | * }
|
460 | * }
|
461 | * }
|
462 | * export default config
|
463 | * ```
|
464 | */
|
465 | wrapEntireFieldDefinitions?: boolean;
|
466 | /**
|
467 | * @name entireFieldWrapperValue
|
468 | * @type string
|
469 | * @description Allow to override the type value of `EntireFieldWrapper`. This wrapper applies outside of Array and Maybe
|
470 | * unlike `fieldWrapperValue`, that will wrap the inner type.
|
471 | * @default T | Promise<T> | (() => T | Promise<T>)
|
472 | *
|
473 | * @example Only allow values
|
474 | * ```ts filename="codegen.ts"
|
475 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
476 | *
|
477 | * const config: CodegenConfig = {
|
478 | * // ...
|
479 | * generates: {
|
480 | * 'path/to/file.ts': {
|
481 | * plugins: ['typescript'],
|
482 | * config: {
|
483 | * entireFieldWrapperValue: 'T'
|
484 | * }
|
485 | * }
|
486 | * }
|
487 | * }
|
488 | * export default config
|
489 | * ```
|
490 | */
|
491 | entireFieldWrapperValue?: string;
|
492 | /**
|
493 | * @description Allow using enum string values directly.
|
494 | *
|
495 | * @exampleMarkdown
|
496 | * ```ts filename="codegen.ts"
|
497 | * import type { CodegenConfig } from '@graphql-codegen/cli'
|
498 | *
|
499 | * const config: CodegenConfig = {
|
500 | * // ...
|
501 | * generates: {
|
502 | * 'path/to/file.ts': {
|
503 | * plugins: ['typescript'],
|
504 | * config: {
|
505 | * allowEnumStringTypes: true
|
506 | * }
|
507 | * }
|
508 | * }
|
509 | * }
|
510 | * export default config
|
511 | * ```
|
512 | */
|
513 | allowEnumStringTypes?: boolean;
|
514 | }
|