@depup/graphql-codegen__typescript-operations 5.0.9-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.
- package/README.md +33 -0
- package/changes.json +18 -0
- package/cjs/config.js +0 -0
- package/cjs/index.js +83 -0
- package/cjs/package.json +1 -0
- package/cjs/ts-operation-variables-to-object.js +10 -0
- package/cjs/ts-selection-set-processor.js +80 -0
- package/cjs/visitor.js +77 -0
- package/esm/config.js +0 -0
- package/esm/index.js +56 -0
- package/esm/ts-operation-variables-to-object.js +6 -0
- package/esm/ts-selection-set-processor.js +76 -0
- package/esm/visitor.js +72 -0
- package/package.json +81 -0
- package/typings/config.d.cts +333 -0
- package/typings/config.d.ts +333 -0
- package/typings/index.d.cts +6 -0
- package/typings/index.d.ts +6 -0
- package/typings/ts-operation-variables-to-object.d.cts +4 -0
- package/typings/ts-operation-variables-to-object.d.ts +4 -0
- package/typings/ts-selection-set-processor.d.cts +8 -0
- package/typings/ts-selection-set-processor.d.ts +8 -0
- package/typings/visitor.d.cts +17 -0
- package/typings/visitor.d.ts +17 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { AvoidOptionalsConfig, RawDocumentsConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
+
/**
|
|
3
|
+
* @description This plugin generates TypeScript types based on your GraphQLSchema _and_ your GraphQL operations and fragments.
|
|
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
|
+
*/
|
|
8
|
+
export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
|
|
9
|
+
/**
|
|
10
|
+
* @description The [GraphQL spec](https://spec.graphql.org/draft/#sel-FAHjBJFCAACE_Gh7d)
|
|
11
|
+
* allows arrays and a single primitive value for list input. This allows to
|
|
12
|
+
* deactivate that behavior to only accept arrays instead of single values. If
|
|
13
|
+
* set to `false`, the definition: `query foo(bar: [Int!]!): Foo` will output
|
|
14
|
+
* `bar: Array<Int>` instead of `bar: Array<Int> | Int` for the variable part.
|
|
15
|
+
* @default true
|
|
16
|
+
*
|
|
17
|
+
* @exampleMarkdown
|
|
18
|
+
* ```ts filename="codegen.ts"
|
|
19
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
20
|
+
*
|
|
21
|
+
* const config: CodegenConfig = {
|
|
22
|
+
* // ...
|
|
23
|
+
* generates: {
|
|
24
|
+
* 'path/to/file.ts': {
|
|
25
|
+
* plugins: ['typescript'],
|
|
26
|
+
* config: {
|
|
27
|
+
* arrayInputCoercion: false
|
|
28
|
+
* },
|
|
29
|
+
* },
|
|
30
|
+
* },
|
|
31
|
+
* };
|
|
32
|
+
* export default config;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
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
|
+
/**
|
|
88
|
+
* @description Generates immutable types by adding `readonly` to properties and uses `ReadonlyArray`.
|
|
89
|
+
* @default false
|
|
90
|
+
*
|
|
91
|
+
* @exampleMarkdown
|
|
92
|
+
* ```ts filename="codegen.ts"
|
|
93
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
94
|
+
*
|
|
95
|
+
* const config: CodegenConfig = {
|
|
96
|
+
* // ...
|
|
97
|
+
* generates: {
|
|
98
|
+
* 'path/to/file.ts': {
|
|
99
|
+
* plugins: ['typescript'],
|
|
100
|
+
* config: {
|
|
101
|
+
* immutableTypes: true
|
|
102
|
+
* },
|
|
103
|
+
* },
|
|
104
|
+
* },
|
|
105
|
+
* };
|
|
106
|
+
* export default config;
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
immutableTypes?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* @description Flatten fragment spread and inline fragments into a simple selection set before generating.
|
|
112
|
+
* @default false
|
|
113
|
+
*
|
|
114
|
+
* @exampleMarkdown
|
|
115
|
+
* ```ts filename="codegen.ts"
|
|
116
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
117
|
+
*
|
|
118
|
+
* const config: CodegenConfig = {
|
|
119
|
+
* // ...
|
|
120
|
+
* generates: {
|
|
121
|
+
* 'path/to/file.ts': {
|
|
122
|
+
* plugins: ['typescript', 'typescript-operations'],
|
|
123
|
+
* config: {
|
|
124
|
+
* flattenGeneratedTypes: true
|
|
125
|
+
* },
|
|
126
|
+
* },
|
|
127
|
+
* },
|
|
128
|
+
* };
|
|
129
|
+
* export default config;
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
flattenGeneratedTypes?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* @description Include all fragments types when flattenGeneratedTypes is enabled.
|
|
135
|
+
* @default false
|
|
136
|
+
*
|
|
137
|
+
* @exampleMarkdown
|
|
138
|
+
* ```ts filename="codegen.ts"
|
|
139
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
140
|
+
*
|
|
141
|
+
* const config: CodegenConfig = {
|
|
142
|
+
* // ...
|
|
143
|
+
* generates: {
|
|
144
|
+
* 'path/to/file.ts': {
|
|
145
|
+
* plugins: ['typescript', 'typescript-operations'],
|
|
146
|
+
* config: {
|
|
147
|
+
* flattenGeneratedTypes: true,
|
|
148
|
+
* flattenGeneratedTypesIncludeFragments: true
|
|
149
|
+
* },
|
|
150
|
+
* },
|
|
151
|
+
* },
|
|
152
|
+
* };
|
|
153
|
+
* export default config;
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
flattenGeneratedTypesIncludeFragments?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* @description Set to `true` in order to generate output without `export` modifier.
|
|
159
|
+
* This is useful if you are generating `.d.ts` file and want it to be globally available.
|
|
160
|
+
* @default false
|
|
161
|
+
*
|
|
162
|
+
* @exampleMarkdown
|
|
163
|
+
* ```ts filename="codegen.ts"
|
|
164
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
165
|
+
*
|
|
166
|
+
* const config: CodegenConfig = {
|
|
167
|
+
* // ...
|
|
168
|
+
* generates: {
|
|
169
|
+
* 'path/to/file.ts': {
|
|
170
|
+
* plugins: ['typescript'],
|
|
171
|
+
* config: {
|
|
172
|
+
* noExport: true
|
|
173
|
+
* },
|
|
174
|
+
* },
|
|
175
|
+
* },
|
|
176
|
+
* };
|
|
177
|
+
* export default config;
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
noExport?: boolean;
|
|
181
|
+
globalNamespace?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* @name addOperationExport
|
|
184
|
+
* @type boolean
|
|
185
|
+
* @description Add const export of the operation name to output file. Pay attention that the file should be `d.ts`.
|
|
186
|
+
* You can combine it with `near-operation-file preset` and therefore the types will be generated along with graphql file. Then you need to set extension in `presetConfig` to be `.gql.d.ts` and by that you can import `gql` file in `ts` files.
|
|
187
|
+
* It will allow you to get everything with one import:
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* import { GetClient, GetClientQuery, GetClientQueryVariables } from './GetClient.gql.js'
|
|
191
|
+
* ```
|
|
192
|
+
* @default false
|
|
193
|
+
* @see https://github.com/dotansimha/graphql-code-generator/issues/3949
|
|
194
|
+
*
|
|
195
|
+
* @exampleMarkdown
|
|
196
|
+
* ```ts filename="codegen.ts"
|
|
197
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
198
|
+
*
|
|
199
|
+
* const config: CodegenConfig = {
|
|
200
|
+
* // ...
|
|
201
|
+
* generates: {
|
|
202
|
+
* "./typings/api.ts": {
|
|
203
|
+
* "plugins": [
|
|
204
|
+
* "typescript"
|
|
205
|
+
* ]
|
|
206
|
+
* },
|
|
207
|
+
* "./": {
|
|
208
|
+
* "preset": "near-operation-file",
|
|
209
|
+
* "presetConfig": {
|
|
210
|
+
* "baseTypesPath": "./typings/api.ts",
|
|
211
|
+
* "extension": ".gql.d.ts"
|
|
212
|
+
* },
|
|
213
|
+
* "plugins": [
|
|
214
|
+
* "@graphql-codegen/typescript-operations"
|
|
215
|
+
* ],
|
|
216
|
+
* "config": {
|
|
217
|
+
* "addOperationExport": true
|
|
218
|
+
* }
|
|
219
|
+
* }
|
|
220
|
+
* };
|
|
221
|
+
* export default config;
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
addOperationExport?: boolean;
|
|
225
|
+
/**
|
|
226
|
+
* @description Allow to override the type value of `Maybe`.
|
|
227
|
+
* @default T | null
|
|
228
|
+
*
|
|
229
|
+
* @exampleMarkdown
|
|
230
|
+
* ## Allow undefined
|
|
231
|
+
* ```ts filename="codegen.ts"
|
|
232
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
233
|
+
*
|
|
234
|
+
* const config: CodegenConfig = {
|
|
235
|
+
* // ...
|
|
236
|
+
* generates: {
|
|
237
|
+
* 'path/to/file.ts': {
|
|
238
|
+
* plugins: ['typescript'],
|
|
239
|
+
* config: {
|
|
240
|
+
* maybeValue: 'T | null | undefined'
|
|
241
|
+
* },
|
|
242
|
+
* },
|
|
243
|
+
* },
|
|
244
|
+
* };
|
|
245
|
+
* export default config;
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
248
|
+
* ## Allow `null` in resolvers:
|
|
249
|
+
* ```ts filename="codegen.ts"
|
|
250
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
251
|
+
*
|
|
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;
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
maybeValue?: string;
|
|
267
|
+
/**
|
|
268
|
+
* @description Adds undefined as a possible type for query variables
|
|
269
|
+
* @default false
|
|
270
|
+
*
|
|
271
|
+
* @exampleMarkdown
|
|
272
|
+
* ```ts filename="codegen.ts"
|
|
273
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
274
|
+
*
|
|
275
|
+
* const config: CodegenConfig = {
|
|
276
|
+
* // ...
|
|
277
|
+
* generates: {
|
|
278
|
+
* 'path/to/file.ts': {
|
|
279
|
+
* plugins: ['typescript'],
|
|
280
|
+
* config: {
|
|
281
|
+
* allowUndefinedQueryVariables: true
|
|
282
|
+
* },
|
|
283
|
+
* },
|
|
284
|
+
* },
|
|
285
|
+
* };
|
|
286
|
+
* export default config;
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
allowUndefinedQueryVariables?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* @description Options related to handling nullability
|
|
292
|
+
* @exampleMarkdown
|
|
293
|
+
* ## `errorHandlingClient`
|
|
294
|
+
* An error handling client is a client which prevents the user from reading a `null` used as a placeholder for an error in a GraphQL response.
|
|
295
|
+
* The client may do so by throwing when an errored field is accessed (as is the case for [`graphql-toe`](https://github.com/graphile/graphql-toe)),
|
|
296
|
+
* or when a fragment containing an error is read (as is the case for Relay's `@throwOnFieldError` directive),
|
|
297
|
+
* or by preventing any data from being read if an error occurred (as with Apollo Client's `errorPolicy: "none"`).
|
|
298
|
+
*
|
|
299
|
+
* When using error handling clients, a semantic non-nullable field can never be `null`.
|
|
300
|
+
* If a semantic non-nullable field's value in the response is `null`, there must be a respective error.
|
|
301
|
+
* The error handling client will throw in this case, so the `null` value is never read.
|
|
302
|
+
*
|
|
303
|
+
* To enable this option, install `graphql-sock` peer dependency:
|
|
304
|
+
*
|
|
305
|
+
* ```sh npm2yarn
|
|
306
|
+
* npm install -D graphql-sock
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* Now, you can enable support for error handling clients:
|
|
310
|
+
*
|
|
311
|
+
* ```ts filename="codegen.ts"
|
|
312
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
313
|
+
*
|
|
314
|
+
* const config: CodegenConfig = {
|
|
315
|
+
* // ...
|
|
316
|
+
* generates: {
|
|
317
|
+
* 'path/to/file.ts': {
|
|
318
|
+
* plugins: ['typescript', 'typescript-operations'],
|
|
319
|
+
* config: {
|
|
320
|
+
* nullability: {
|
|
321
|
+
* errorHandlingClient: true
|
|
322
|
+
* }
|
|
323
|
+
* },
|
|
324
|
+
* },
|
|
325
|
+
* },
|
|
326
|
+
* };
|
|
327
|
+
* export default config;
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
nullability?: {
|
|
331
|
+
errorHandlingClient: boolean;
|
|
332
|
+
};
|
|
333
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { AvoidOptionalsConfig, RawDocumentsConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
+
/**
|
|
3
|
+
* @description This plugin generates TypeScript types based on your GraphQLSchema _and_ your GraphQL operations and fragments.
|
|
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
|
+
*/
|
|
8
|
+
export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
|
|
9
|
+
/**
|
|
10
|
+
* @description The [GraphQL spec](https://spec.graphql.org/draft/#sel-FAHjBJFCAACE_Gh7d)
|
|
11
|
+
* allows arrays and a single primitive value for list input. This allows to
|
|
12
|
+
* deactivate that behavior to only accept arrays instead of single values. If
|
|
13
|
+
* set to `false`, the definition: `query foo(bar: [Int!]!): Foo` will output
|
|
14
|
+
* `bar: Array<Int>` instead of `bar: Array<Int> | Int` for the variable part.
|
|
15
|
+
* @default true
|
|
16
|
+
*
|
|
17
|
+
* @exampleMarkdown
|
|
18
|
+
* ```ts filename="codegen.ts"
|
|
19
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
20
|
+
*
|
|
21
|
+
* const config: CodegenConfig = {
|
|
22
|
+
* // ...
|
|
23
|
+
* generates: {
|
|
24
|
+
* 'path/to/file.ts': {
|
|
25
|
+
* plugins: ['typescript'],
|
|
26
|
+
* config: {
|
|
27
|
+
* arrayInputCoercion: false
|
|
28
|
+
* },
|
|
29
|
+
* },
|
|
30
|
+
* },
|
|
31
|
+
* };
|
|
32
|
+
* export default config;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
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
|
+
/**
|
|
88
|
+
* @description Generates immutable types by adding `readonly` to properties and uses `ReadonlyArray`.
|
|
89
|
+
* @default false
|
|
90
|
+
*
|
|
91
|
+
* @exampleMarkdown
|
|
92
|
+
* ```ts filename="codegen.ts"
|
|
93
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
94
|
+
*
|
|
95
|
+
* const config: CodegenConfig = {
|
|
96
|
+
* // ...
|
|
97
|
+
* generates: {
|
|
98
|
+
* 'path/to/file.ts': {
|
|
99
|
+
* plugins: ['typescript'],
|
|
100
|
+
* config: {
|
|
101
|
+
* immutableTypes: true
|
|
102
|
+
* },
|
|
103
|
+
* },
|
|
104
|
+
* },
|
|
105
|
+
* };
|
|
106
|
+
* export default config;
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
immutableTypes?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* @description Flatten fragment spread and inline fragments into a simple selection set before generating.
|
|
112
|
+
* @default false
|
|
113
|
+
*
|
|
114
|
+
* @exampleMarkdown
|
|
115
|
+
* ```ts filename="codegen.ts"
|
|
116
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
117
|
+
*
|
|
118
|
+
* const config: CodegenConfig = {
|
|
119
|
+
* // ...
|
|
120
|
+
* generates: {
|
|
121
|
+
* 'path/to/file.ts': {
|
|
122
|
+
* plugins: ['typescript', 'typescript-operations'],
|
|
123
|
+
* config: {
|
|
124
|
+
* flattenGeneratedTypes: true
|
|
125
|
+
* },
|
|
126
|
+
* },
|
|
127
|
+
* },
|
|
128
|
+
* };
|
|
129
|
+
* export default config;
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
flattenGeneratedTypes?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* @description Include all fragments types when flattenGeneratedTypes is enabled.
|
|
135
|
+
* @default false
|
|
136
|
+
*
|
|
137
|
+
* @exampleMarkdown
|
|
138
|
+
* ```ts filename="codegen.ts"
|
|
139
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
140
|
+
*
|
|
141
|
+
* const config: CodegenConfig = {
|
|
142
|
+
* // ...
|
|
143
|
+
* generates: {
|
|
144
|
+
* 'path/to/file.ts': {
|
|
145
|
+
* plugins: ['typescript', 'typescript-operations'],
|
|
146
|
+
* config: {
|
|
147
|
+
* flattenGeneratedTypes: true,
|
|
148
|
+
* flattenGeneratedTypesIncludeFragments: true
|
|
149
|
+
* },
|
|
150
|
+
* },
|
|
151
|
+
* },
|
|
152
|
+
* };
|
|
153
|
+
* export default config;
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
flattenGeneratedTypesIncludeFragments?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* @description Set to `true` in order to generate output without `export` modifier.
|
|
159
|
+
* This is useful if you are generating `.d.ts` file and want it to be globally available.
|
|
160
|
+
* @default false
|
|
161
|
+
*
|
|
162
|
+
* @exampleMarkdown
|
|
163
|
+
* ```ts filename="codegen.ts"
|
|
164
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
165
|
+
*
|
|
166
|
+
* const config: CodegenConfig = {
|
|
167
|
+
* // ...
|
|
168
|
+
* generates: {
|
|
169
|
+
* 'path/to/file.ts': {
|
|
170
|
+
* plugins: ['typescript'],
|
|
171
|
+
* config: {
|
|
172
|
+
* noExport: true
|
|
173
|
+
* },
|
|
174
|
+
* },
|
|
175
|
+
* },
|
|
176
|
+
* };
|
|
177
|
+
* export default config;
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
noExport?: boolean;
|
|
181
|
+
globalNamespace?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* @name addOperationExport
|
|
184
|
+
* @type boolean
|
|
185
|
+
* @description Add const export of the operation name to output file. Pay attention that the file should be `d.ts`.
|
|
186
|
+
* You can combine it with `near-operation-file preset` and therefore the types will be generated along with graphql file. Then you need to set extension in `presetConfig` to be `.gql.d.ts` and by that you can import `gql` file in `ts` files.
|
|
187
|
+
* It will allow you to get everything with one import:
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* import { GetClient, GetClientQuery, GetClientQueryVariables } from './GetClient.gql.js'
|
|
191
|
+
* ```
|
|
192
|
+
* @default false
|
|
193
|
+
* @see https://github.com/dotansimha/graphql-code-generator/issues/3949
|
|
194
|
+
*
|
|
195
|
+
* @exampleMarkdown
|
|
196
|
+
* ```ts filename="codegen.ts"
|
|
197
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
198
|
+
*
|
|
199
|
+
* const config: CodegenConfig = {
|
|
200
|
+
* // ...
|
|
201
|
+
* generates: {
|
|
202
|
+
* "./typings/api.ts": {
|
|
203
|
+
* "plugins": [
|
|
204
|
+
* "typescript"
|
|
205
|
+
* ]
|
|
206
|
+
* },
|
|
207
|
+
* "./": {
|
|
208
|
+
* "preset": "near-operation-file",
|
|
209
|
+
* "presetConfig": {
|
|
210
|
+
* "baseTypesPath": "./typings/api.ts",
|
|
211
|
+
* "extension": ".gql.d.ts"
|
|
212
|
+
* },
|
|
213
|
+
* "plugins": [
|
|
214
|
+
* "@graphql-codegen/typescript-operations"
|
|
215
|
+
* ],
|
|
216
|
+
* "config": {
|
|
217
|
+
* "addOperationExport": true
|
|
218
|
+
* }
|
|
219
|
+
* }
|
|
220
|
+
* };
|
|
221
|
+
* export default config;
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
addOperationExport?: boolean;
|
|
225
|
+
/**
|
|
226
|
+
* @description Allow to override the type value of `Maybe`.
|
|
227
|
+
* @default T | null
|
|
228
|
+
*
|
|
229
|
+
* @exampleMarkdown
|
|
230
|
+
* ## Allow undefined
|
|
231
|
+
* ```ts filename="codegen.ts"
|
|
232
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
233
|
+
*
|
|
234
|
+
* const config: CodegenConfig = {
|
|
235
|
+
* // ...
|
|
236
|
+
* generates: {
|
|
237
|
+
* 'path/to/file.ts': {
|
|
238
|
+
* plugins: ['typescript'],
|
|
239
|
+
* config: {
|
|
240
|
+
* maybeValue: 'T | null | undefined'
|
|
241
|
+
* },
|
|
242
|
+
* },
|
|
243
|
+
* },
|
|
244
|
+
* };
|
|
245
|
+
* export default config;
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
248
|
+
* ## Allow `null` in resolvers:
|
|
249
|
+
* ```ts filename="codegen.ts"
|
|
250
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
251
|
+
*
|
|
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;
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
maybeValue?: string;
|
|
267
|
+
/**
|
|
268
|
+
* @description Adds undefined as a possible type for query variables
|
|
269
|
+
* @default false
|
|
270
|
+
*
|
|
271
|
+
* @exampleMarkdown
|
|
272
|
+
* ```ts filename="codegen.ts"
|
|
273
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
274
|
+
*
|
|
275
|
+
* const config: CodegenConfig = {
|
|
276
|
+
* // ...
|
|
277
|
+
* generates: {
|
|
278
|
+
* 'path/to/file.ts': {
|
|
279
|
+
* plugins: ['typescript'],
|
|
280
|
+
* config: {
|
|
281
|
+
* allowUndefinedQueryVariables: true
|
|
282
|
+
* },
|
|
283
|
+
* },
|
|
284
|
+
* },
|
|
285
|
+
* };
|
|
286
|
+
* export default config;
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
allowUndefinedQueryVariables?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* @description Options related to handling nullability
|
|
292
|
+
* @exampleMarkdown
|
|
293
|
+
* ## `errorHandlingClient`
|
|
294
|
+
* An error handling client is a client which prevents the user from reading a `null` used as a placeholder for an error in a GraphQL response.
|
|
295
|
+
* The client may do so by throwing when an errored field is accessed (as is the case for [`graphql-toe`](https://github.com/graphile/graphql-toe)),
|
|
296
|
+
* or when a fragment containing an error is read (as is the case for Relay's `@throwOnFieldError` directive),
|
|
297
|
+
* or by preventing any data from being read if an error occurred (as with Apollo Client's `errorPolicy: "none"`).
|
|
298
|
+
*
|
|
299
|
+
* When using error handling clients, a semantic non-nullable field can never be `null`.
|
|
300
|
+
* If a semantic non-nullable field's value in the response is `null`, there must be a respective error.
|
|
301
|
+
* The error handling client will throw in this case, so the `null` value is never read.
|
|
302
|
+
*
|
|
303
|
+
* To enable this option, install `graphql-sock` peer dependency:
|
|
304
|
+
*
|
|
305
|
+
* ```sh npm2yarn
|
|
306
|
+
* npm install -D graphql-sock
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* Now, you can enable support for error handling clients:
|
|
310
|
+
*
|
|
311
|
+
* ```ts filename="codegen.ts"
|
|
312
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
313
|
+
*
|
|
314
|
+
* const config: CodegenConfig = {
|
|
315
|
+
* // ...
|
|
316
|
+
* generates: {
|
|
317
|
+
* 'path/to/file.ts': {
|
|
318
|
+
* plugins: ['typescript', 'typescript-operations'],
|
|
319
|
+
* config: {
|
|
320
|
+
* nullability: {
|
|
321
|
+
* errorHandlingClient: true
|
|
322
|
+
* }
|
|
323
|
+
* },
|
|
324
|
+
* },
|
|
325
|
+
* },
|
|
326
|
+
* };
|
|
327
|
+
* export default config;
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
nullability?: {
|
|
331
|
+
errorHandlingClient: boolean;
|
|
332
|
+
};
|
|
333
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PluginFunction, Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { TypeScriptDocumentsPluginConfig } from './config.cjs';
|
|
3
|
+
import { TypeScriptDocumentsVisitor } from './visitor.cjs';
|
|
4
|
+
export { TypeScriptDocumentsPluginConfig } from './config.cjs';
|
|
5
|
+
export declare const plugin: PluginFunction<TypeScriptDocumentsPluginConfig, Types.ComplexPluginOutput>;
|
|
6
|
+
export { TypeScriptDocumentsVisitor };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PluginFunction, Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { TypeScriptDocumentsPluginConfig } from './config.js';
|
|
3
|
+
import { TypeScriptDocumentsVisitor } from './visitor.js';
|
|
4
|
+
export { TypeScriptDocumentsPluginConfig } from './config.js';
|
|
5
|
+
export declare const plugin: PluginFunction<TypeScriptDocumentsPluginConfig, Types.ComplexPluginOutput>;
|
|
6
|
+
export { TypeScriptDocumentsVisitor };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TypeScriptOperationVariablesToObject as TSOperationVariablesToObject } from '@graphql-codegen/typescript';
|
|
2
|
+
export declare class TypeScriptOperationVariablesToObject extends TSOperationVariablesToObject {
|
|
3
|
+
protected formatTypeString(fieldType: string, _isNonNullType: boolean, _hasDefaultValue: boolean): string;
|
|
4
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TypeScriptOperationVariablesToObject as TSOperationVariablesToObject } from '@graphql-codegen/typescript';
|
|
2
|
+
export declare class TypeScriptOperationVariablesToObject extends TSOperationVariablesToObject {
|
|
3
|
+
protected formatTypeString(fieldType: string, _isNonNullType: boolean, _hasDefaultValue: boolean): string;
|
|
4
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseSelectionSetProcessor, LinkField, PrimitiveAliasedFields, PrimitiveField, ProcessResult, SelectionSetProcessorConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
+
import { GraphQLInterfaceType, GraphQLObjectType } from 'graphql';
|
|
3
|
+
export declare class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor<SelectionSetProcessorConfig> {
|
|
4
|
+
transformPrimitiveFields(schemaType: GraphQLObjectType | GraphQLInterfaceType, fields: PrimitiveField[], unsetTypes?: boolean): ProcessResult;
|
|
5
|
+
transformTypenameField(type: string, name: string): ProcessResult;
|
|
6
|
+
transformAliasesPrimitiveFields(schemaType: GraphQLObjectType | GraphQLInterfaceType, fields: PrimitiveAliasedFields[]): ProcessResult;
|
|
7
|
+
transformLinkFields(fields: LinkField[]): ProcessResult;
|
|
8
|
+
}
|