-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
codegen.yml
106 lines (106 loc) · 3.69 KB
/
codegen.yml
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
overwrite: true
schema: ./example/test.graphql
generates:
example/types.ts:
plugins:
- typescript
config:
scalars:
ID: string
example/yup/schemas.ts:
plugins:
- ./dist/cjs/index.js:
schema: yup
importFrom: ../types
withObjectType: true
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
scalars:
ID: string
example/zod/schemas.ts:
plugins:
- ./dist/cjs/index.js:
schema: zod
importFrom: ../types
withObjectType: true
directives:
# Write directives like
#
# directive:
# arg1: schemaApi
# arg2: ["schemaApi2", "Hello $1"]
#
# See more examples in `./tests/directive.spec.ts`
# https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/blob/main/tests/directive.spec.ts
constraint:
minLength: min
# Replace $1 with specified `startsWith` argument value of the constraint directive
startsWith: [regex, /^$1/, message]
format:
email: email
scalars:
ID: string
example/myzod/schemas.ts:
plugins:
- ./dist/cjs/index.js:
schema: myzod
importFrom: ../types
withObjectType: true
directives:
constraint:
minLength: min
# Replace $1 with specified `startsWith` argument value of the constraint directive
startsWith: [pattern, /^$1/]
format:
email: email
scalars:
ID: string
example/valibot/schemas.ts:
plugins:
- ./dist/cjs/index.js:
schema: valibot
importFrom: ../types
withObjectType: true
directives:
# Write directives like
#
# directive:
# arg1: schemaApi
# arg2: ["schemaApi2", "Hello $1"]
#
# See more examples in `./tests/directive.spec.ts`
# https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/blob/main/tests/directive.spec.ts
constraint:
minLength: minLength
# Replace $1 with specified `startsWith` argument value of the constraint directive
startsWith: [regex, /^$1/, message]
format:
email: email
scalars:
ID: string