-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
368 lines (363 loc) · 9.93 KB
/
config.ts
File metadata and controls
368 lines (363 loc) · 9.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
import type { TypeScriptPluginConfig } from '@graphql-codegen/typescript';
import type { NamingConventionMap } from '@graphql-codegen/visitor-plugin-common';
export type ValidationSchema = 'yup' | 'zod' | 'zodv4' | 'myzod' | 'valibot';
export type ValidationSchemaExportType = 'function' | 'const';
export interface DirectiveConfig {
[directive: string]: {
[argument: string]: string | string[] | DirectiveObjectArguments
}
}
export interface DirectiveObjectArguments {
[matched: string]: string | string[]
}
interface ScalarSchemas {
[name: string]: string
}
export interface ValidationSchemaPluginConfig extends TypeScriptPluginConfig {
/**
* @description Specifies a custom import path for the zod package. This is useful when you want to use a specific
* version or subpath of zod, such as the v3 compatibility layer in zod v4 ('zod/v3').
* Only applies when schema is set to 'zod'.
* @default 'zod'
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/schemas.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* schema: zod
* # Use zod v3 compatibility layer when using zod v4
* zodImportPath: zod/v3
* ```
*/
zodImportPath?: string
/**
* @description specify generate schema
* @default yup
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - typescript
* - graphql-codegen-validation-schema
* config:
* schema: yup
* ```
*/
schema?: ValidationSchema
/**
* @description import types from generated typescript type path
* if not given, omit import statement.
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/types.ts:
* plugins:
* - typescript
* path/to/schemas.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* schema: yup
* importFrom: ./path/to/types
* ```
*/
importFrom?: string
/**
* @description If defined, will use named imports from the specified module (defined in `importFrom`)
* rather than individual imports for each type.
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/types.ts:
* plugins:
* - typescript
* path/to/schemas.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* schema: yup
* importFrom: ./path/to/types
* schemaNamespacedImportName: types
* ```
*/
schemaNamespacedImportName?: string
/**
* @description Will use `import type {}` rather than `import {}` when importing generated typescript types.
* This gives compatibility with TypeScript's "importsNotUsedAsValues": "error" option
* Should used in conjunction with `importFrom` option.
* @default false
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/types.ts:
* plugins:
* - typescript
* path/to/schemas.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* schema: yup
* importFrom: ./path/to/types
* useTypeImports: true
* ```
*/
useTypeImports?: boolean
/**
* @description Prefixes all import types from generated typescript type.
* @default ""
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/types.ts:
* plugins:
* - typescript
* path/to/schemas.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* typesPrefix: I
* importFrom: ./path/to/types
* ```
*/
typesPrefix?: string
/**
* @description Suffixes all import types from generated typescript type.
* @default ""
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/types.ts:
* plugins:
* - typescript
* path/to/schemas.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* typesSuffix: I
* importFrom: ./path/to/types
* ```
*/
typesSuffix?: string
/**
* @description Generates validation schema for enum as TypeScript `type`
* @default false
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* enumsAsTypes: true
* ```
*
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - typescript
* - graphql-codegen-validation-schema
* config:
* enumsAsTypes: true
* ```
*/
enumsAsTypes?: boolean
/**
* @description Generates validation string schema as do not allow empty characters by default.
* @default false
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* notAllowEmptyString: true
* ```
*/
notAllowEmptyString?: boolean
/**
* @description Extends or overrides validation schema for the built-in scalars and custom GraphQL scalars.
*
* @exampleMarkdown
* ```yml
* config:
* schema: yup
* scalarSchemas:
* Date: yup.date()
* Email: yup.string().email()
* ```
*
* @exampleMarkdown
* ```yml
* config:
* schema: zod
* scalarSchemas:
* Date: z.date()
* Email: z.string().email()
* ```
*/
scalarSchemas?: ScalarSchemas
/**
* @description Fallback scalar type for undefined scalar types in the schema not found in `scalarSchemas`.
*
* @exampleMarkdown
* ```yml
* config:
* schema: yup
* defaultScalarSchema: yup.unknown()
* ```
*
* @exampleMarkdown
* ```yml
* config:
* schema: zod
* defaultScalarSchema: z.unknown()
* ```
*/
defaultScalarTypeSchema?: string
/**
* @description Generates validation schema with GraphQL type objects.
* but excludes "Query", "Mutation", "Subscription" objects.
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/types.ts:
* plugins:
* - typescript
* path/to/schemas.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* schema: yup
* withObjectType: true
* ```
*/
withObjectType?: boolean
/**
* @description Specify validation schema export type.
* @default function
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - typescript
* - graphql-codegen-validation-schema
* config:
* validationSchemaExportType: const
* ```
*/
validationSchemaExportType?: ValidationSchemaExportType
/**
* @description Uses the full path of the enum type as the default value instead of the stringified value.
* @default false
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - typescript
* - graphql-codegen-validation-schema
* config:
* useEnumTypeAsDefaultValue: true
* ```
*/
useEnumTypeAsDefaultValue?: boolean
/**
* @description Uses the full path of the enum type as the default value instead of the stringified value.
* @default { enumValues: "change-case-all#pascalCase" }
* @link https://the-guild.dev/graphql/codegen/docs/config-reference/naming-convention
*
* Note: This option has not been tested with `namingConvention.transformUnderscore` and `namingConvention.typeNames` options,
* and may not work as expected.
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - typescript
* - graphql-codegen-validation-schema
* config:
* namingConvention:
* enumValues: change-case-all#pascalCase
* ```
*/
namingConvention?: NamingConventionMap
/**
* @description Generates `.describe()` calls on Zod schemas using GraphQL descriptions.
* When enabled, any GraphQL type or field that has a description comment will have
* `.describe('...')` appended to its generated Zod schema.
* Only applies when schema is set to 'zod' or 'zodv4'.
* @default false
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* schema: zod
* withDescriptions: true
* ```
*/
withDescriptions?: boolean
/**
* @description Generates validation schema with more API based on directive schema.
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - graphql-codegen-validation-schema
* config:
* schema: yup
* directives:
* required:
* msg: required
* # This is example using constraint directive.
* # see: https://github.com/confuser/graphql-constraint-directive
* constraint:
* minLength: min # same as ['min', '$1']
* maxLength: max
* startsWith: ["matches", "/^$1/"]
* endsWith: ["matches", "/$1$/"]
* contains: ["matches", "/$1/"]
* notContains: ["matches", "/^((?!$1).)*$/"]
* pattern: ["matches", "/$1/"]
* format:
* # For example, `@constraint(format: "uri")`. this case $1 will be "uri".
* # Therefore the generator generates yup schema `.url()` followed by `uri: 'url'`
* # If $1 does not match anywhere, the generator will ignore.
* uri: url
* email: email
* uuid: uuid
* # yup does not have `ipv4` API. If you want to add this,
* # you need to add the logic using `yup.addMethod`.
* # see: https://github.com/jquense/yup#addmethodschematype-schema-name-string-method--schema-void
* ipv4: ipv4
* min: ["min", "$1 - 1"]
* max: ["max", "$1 + 1"]
* exclusiveMin: min
* exclusiveMax: max
* ```
*/
directives?: DirectiveConfig
}