-
Notifications
You must be signed in to change notification settings - Fork 0
/
codegen.yml
74 lines (74 loc) · 2.75 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
overwrite: true
schema: './example/test.graphql'
generates:
example/types.ts:
plugins:
- typescript
example/yup/schemas.ts:
plugins:
- ./dist/main/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
example/zod/schemas.ts:
plugins:
- ./dist/main/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
example/myzod/schemas.ts:
plugins:
- ./dist/main/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