@depup/graphql-codegen__typescript-operations 5.0.9-depup.0 → 6.1.1-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,7 @@
1
- import { AvoidOptionalsConfig, RawDocumentsConfig } from '@graphql-codegen/visitor-plugin-common';
1
+ import { RawDocumentsConfig, type ConvertSchemaEnumToDeclarationBlockString, type EnumValuesMap } from '@graphql-codegen/visitor-plugin-common';
2
2
  /**
3
3
  * @description This plugin generates TypeScript types based on your GraphQLSchema _and_ your GraphQL operations and fragments.
4
4
  * It generates types for your GraphQL documents: Query, Mutation, Subscription and Fragment.
5
- *
6
- * Note: In most configurations, this plugin requires you to use `typescript as well, because it depends on its base types.
7
5
  */
8
6
  export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
9
7
  /**
@@ -22,7 +20,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
22
20
  * // ...
23
21
  * generates: {
24
22
  * 'path/to/file.ts': {
25
- * plugins: ['typescript'],
23
+ * plugins: ['typescript-operations'],
26
24
  * config: {
27
25
  * arrayInputCoercion: false
28
26
  * },
@@ -33,57 +31,6 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
33
31
  * ```
34
32
  */
35
33
  arrayInputCoercion?: boolean;
36
- /**
37
- * @description This will cause the generator to avoid using TypeScript optionals (`?`) on types,
38
- * so the following definition: `type A { myField: String }` will output `myField: Maybe<string>`
39
- * instead of `myField?: Maybe<string>`.
40
- * @default false
41
- *
42
- * @exampleMarkdown
43
- * ## Override all definition types
44
- *
45
- * ```ts filename="codegen.ts"
46
- * import type { CodegenConfig } from '@graphql-codegen/cli';
47
- *
48
- * const config: CodegenConfig = {
49
- * // ...
50
- * generates: {
51
- * 'path/to/file.ts': {
52
- * plugins: ['typescript'],
53
- * config: {
54
- * avoidOptionals: true
55
- * },
56
- * },
57
- * },
58
- * };
59
- * export default config;
60
- * ```
61
- *
62
- * ## Override only specific definition types
63
- *
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
- * avoidOptionals: {
74
- * field: true
75
- * inputValue: true
76
- * object: true
77
- * defaultValue: true
78
- * }
79
- * },
80
- * },
81
- * },
82
- * };
83
- * export default config;
84
- * ```
85
- */
86
- avoidOptionals?: boolean | AvoidOptionalsConfig;
87
34
  /**
88
35
  * @description Generates immutable types by adding `readonly` to properties and uses `ReadonlyArray`.
89
36
  * @default false
@@ -96,7 +43,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
96
43
  * // ...
97
44
  * generates: {
98
45
  * 'path/to/file.ts': {
99
- * plugins: ['typescript'],
46
+ * plugins: ['typescript-operations'],
100
47
  * config: {
101
48
  * immutableTypes: true
102
49
  * },
@@ -119,7 +66,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
119
66
  * // ...
120
67
  * generates: {
121
68
  * 'path/to/file.ts': {
122
- * plugins: ['typescript', 'typescript-operations'],
69
+ * plugins: ['typescript-operations'],
123
70
  * config: {
124
71
  * flattenGeneratedTypes: true
125
72
  * },
@@ -142,7 +89,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
142
89
  * // ...
143
90
  * generates: {
144
91
  * 'path/to/file.ts': {
145
- * plugins: ['typescript', 'typescript-operations'],
92
+ * plugins: ['typescript-operations'],
146
93
  * config: {
147
94
  * flattenGeneratedTypes: true,
148
95
  * flattenGeneratedTypesIncludeFragments: true
@@ -167,7 +114,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
167
114
  * // ...
168
115
  * generates: {
169
116
  * 'path/to/file.ts': {
170
- * plugins: ['typescript'],
117
+ * plugins: ['typescript-operations'],
171
118
  * config: {
172
119
  * noExport: true
173
120
  * },
@@ -178,7 +125,6 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
178
125
  * ```
179
126
  */
180
127
  noExport?: boolean;
181
- globalNamespace?: boolean;
182
128
  /**
183
129
  * @name addOperationExport
184
130
  * @type boolean
@@ -199,23 +145,19 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
199
145
  * const config: CodegenConfig = {
200
146
  * // ...
201
147
  * generates: {
202
- * "./typings/api.ts": {
203
- * "plugins": [
204
- * "typescript"
205
- * ]
206
- * },
207
- * "./": {
148
+ * "./": {
208
149
  * "preset": "near-operation-file",
209
150
  * "presetConfig": {
210
- * "baseTypesPath": "./typings/api.ts",
211
- * "extension": ".gql.d.ts"
151
+ * "baseTypesPath": "./typings/api.ts",
152
+ * "extension": ".gql.d.ts"
212
153
  * },
213
154
  * "plugins": [
214
- * "@graphql-codegen/typescript-operations"
155
+ * "typescript-operations"
215
156
  * ],
216
157
  * "config": {
217
- * "addOperationExport": true
158
+ * "addOperationExport": true
218
159
  * }
160
+ * }
219
161
  * }
220
162
  * };
221
163
  * export default config;
@@ -223,11 +165,13 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
223
165
  */
224
166
  addOperationExport?: boolean;
225
167
  /**
226
- * @description Allow to override the type value of `Maybe`.
168
+ * @description Allows overriding the type value of nullable fields to match GraphQL client's runtime behaviour.
227
169
  * @default T | null
228
170
  *
229
171
  * @exampleMarkdown
230
172
  * ## Allow undefined
173
+ * By default, a GraphQL server will return either the expected type or `null` for a nullable field.
174
+ * `maybeValue` option could be used to change this behaviour if your GraphQL client does something different such as returning `undefined`.
231
175
  * ```ts filename="codegen.ts"
232
176
  * import type { CodegenConfig } from '@graphql-codegen/cli';
233
177
  *
@@ -235,7 +179,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
235
179
  * // ...
236
180
  * generates: {
237
181
  * 'path/to/file.ts': {
238
- * plugins: ['typescript'],
182
+ * plugins: ['typescript-operations'],
239
183
  * config: {
240
184
  * maybeValue: 'T | null | undefined'
241
185
  * },
@@ -244,26 +188,37 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
244
188
  * };
245
189
  * export default config;
246
190
  * ```
191
+ */
192
+ maybeValue?: string;
193
+ /**
194
+ * @description Allows overriding the type of Input and Variables nullable types.
195
+ * @default T | null | undefined
196
+ *
197
+ * @exampleMarkdown
198
+ * ## Disallow `undefined`
199
+ * Disallowing `undefined` is useful if you want to force explicit null to be passed in as Variables to the server. Use `inputMaybeValue: 'T | null'` with `avoidOptionals.inputValue: true` to achieve this.
247
200
  *
248
- * ## Allow `null` in resolvers:
249
201
  * ```ts filename="codegen.ts"
250
- * import type { CodegenConfig } from '@graphql-codegen/cli';
202
+ * import type { CodegenConfig } from '@graphql-codegen/cli'
251
203
  *
252
- * const config: CodegenConfig = {
253
- * // ...
254
- * generates: {
255
- * 'path/to/file.ts': {
256
- * plugins: ['typescript'],
257
- * config: {
258
- * maybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'
259
- * },
260
- * },
261
- * },
262
- * };
263
- * export default config;
204
+ * const config: CodegenConfig = {
205
+ * // ...
206
+ * generates: {
207
+ * 'path/to/file.ts': {
208
+ * plugins: ['typescript-operations'],
209
+ * config: {
210
+ * avoidOptionals: {
211
+ * inputValue: true,
212
+ * },
213
+ * inputMaybeValue: 'T | null'
214
+ * }
215
+ * }
216
+ * }
217
+ * }
218
+ * export default config
264
219
  * ```
265
220
  */
266
- maybeValue?: string;
221
+ inputMaybeValue?: string;
267
222
  /**
268
223
  * @description Adds undefined as a possible type for query variables
269
224
  * @default false
@@ -276,7 +231,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
276
231
  * // ...
277
232
  * generates: {
278
233
  * 'path/to/file.ts': {
279
- * plugins: ['typescript'],
234
+ * plugins: ['typescript-operations'],
280
235
  * config: {
281
236
  * allowUndefinedQueryVariables: true
282
237
  * },
@@ -315,7 +270,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
315
270
  * // ...
316
271
  * generates: {
317
272
  * 'path/to/file.ts': {
318
- * plugins: ['typescript', 'typescript-operations'],
273
+ * plugins: ['typescript-operations'],
319
274
  * config: {
320
275
  * nullability: {
321
276
  * errorHandlingClient: true
@@ -330,4 +285,144 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
330
285
  nullability?: {
331
286
  errorHandlingClient: boolean;
332
287
  };
288
+ /**
289
+ * @description Controls the enum output type. Options: `string-literal` | `native-numeric` | `const` | `native-const` | `native`;
290
+ * @default `string-literal`
291
+ *
292
+ * @exampleMarkdown
293
+ * ```ts filename="codegen.ts"
294
+ * import type { CodegenConfig } from '@graphql-codegen/cli'
295
+ *
296
+ * const config: CodegenConfig = {
297
+ * // ...
298
+ * generates: {
299
+ * 'path/to/file.ts': {
300
+ * plugins: ['typescript-operations'],
301
+ * config: {
302
+ * enumType: 'string-literal',
303
+ * }
304
+ * }
305
+ * }
306
+ * }
307
+ * export default config
308
+ * ```
309
+ */
310
+ enumType?: ConvertSchemaEnumToDeclarationBlockString['outputType'];
311
+ /**
312
+ * @description Overrides the default value of enum values declared in your GraphQL schema.
313
+ * You can also map the entire enum to an external type by providing a string that of `module#type`.
314
+ *
315
+ * @exampleMarkdown
316
+ * ## With Custom Values
317
+ * ```ts filename="codegen.ts"
318
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
319
+ *
320
+ * const config: CodegenConfig = {
321
+ * // ...
322
+ * generates: {
323
+ * 'path/to/file': {
324
+ * // plugins...
325
+ * config: {
326
+ * enumValues: {
327
+ * MyEnum: {
328
+ * A: 'foo'
329
+ * }
330
+ * }
331
+ * },
332
+ * },
333
+ * },
334
+ * };
335
+ * export default config;
336
+ * ```
337
+ *
338
+ * ## With External Enum
339
+ * ```ts filename="codegen.ts"
340
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
341
+ *
342
+ * const config: CodegenConfig = {
343
+ * // ...
344
+ * generates: {
345
+ * 'path/to/file': {
346
+ * // plugins...
347
+ * config: {
348
+ * enumValues: {
349
+ * MyEnum: './my-file#MyCustomEnum',
350
+ * }
351
+ * },
352
+ * },
353
+ * },
354
+ * };
355
+ * export default config;
356
+ * ```
357
+ *
358
+ * ## Import All Enums from a file
359
+ * ```ts filename="codegen.ts"
360
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
361
+ *
362
+ * const config: CodegenConfig = {
363
+ * // ...
364
+ * generates: {
365
+ * 'path/to/file': {
366
+ * // plugins...
367
+ * config: {
368
+ * enumValues: {
369
+ * MyEnum: './my-file',
370
+ * }
371
+ * },
372
+ * },
373
+ * },
374
+ * };
375
+ * export default config;
376
+ * ```
377
+ */
378
+ enumValues?: EnumValuesMap;
379
+ /**
380
+ * @description This will cause the generator to ignore enum values defined in GraphQLSchema
381
+ * @default false
382
+ *
383
+ * @exampleMarkdown
384
+ * ## Ignore enum values from schema
385
+ *
386
+ * ```ts filename="codegen.ts"
387
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
388
+ *
389
+ * const config: CodegenConfig = {
390
+ * // ...
391
+ * generates: {
392
+ * 'path/to/file': {
393
+ * // plugins...
394
+ * config: {
395
+ * ignoreEnumValuesFromSchema: true,
396
+ * },
397
+ * },
398
+ * },
399
+ * };
400
+ * export default config;
401
+ * ```
402
+ */
403
+ ignoreEnumValuesFromSchema?: boolean;
404
+ /**
405
+ * @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.
406
+ * This is useful if you are using `relay`.
407
+ * @default false
408
+ *
409
+ * @exampleMarkdown
410
+ * ```ts filename="codegen.ts"
411
+ * import type { CodegenConfig } from '@graphql-codegen/cli'
412
+ *
413
+ * const config: CodegenConfig = {
414
+ * // ...
415
+ * generates: {
416
+ * 'path/to/file.ts': {
417
+ * plugins: ['typescript-operations'],
418
+ * config: {
419
+ * futureProofEnums: true
420
+ * }
421
+ * }
422
+ * }
423
+ * }
424
+ * export default config
425
+ * ```
426
+ */
427
+ futureProofEnums?: boolean;
333
428
  }