Skip to content

Commit 8d7094d

Browse files
committed
fixed example for zod
1 parent 2f3d482 commit 8d7094d

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

codegen.yml

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,17 @@ generates:
4343
schema: zod
4444
importFrom: ../types
4545
directives:
46-
required:
47-
msg: required
48-
# This is example using constraint directive.
49-
# see: https://github.com/confuser/graphql-constraint-directive
46+
# Write directives like
47+
#
48+
# directive:
49+
# arg1: schemaApi
50+
# arg2: ["schemaApi2", "Hello $1"]
51+
#
52+
# See more examples in `./tests/directive.spec.ts`
53+
# https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/blob/main/tests/directive.spec.ts
5054
constraint:
51-
minLength: min # same as ['min', '$1']
52-
maxLength: max
53-
startsWith: ['regex', '/^$1/']
54-
endsWith: ['regex', '/$1$/']
55-
contains: ['regex', '/$1/']
56-
notContains: ['regex', '/^((?!$1).)*$/']
57-
pattern: ['regex', '/$1/']
55+
minLength: min
56+
# Replace $1 with specified `startsWith` argument value of the constraint directive
57+
startsWith: ["regex", "/^$1/", "message"]
5858
format:
59-
# For example, `@constraint(format: "uri")`. this case $1 will be "uri".
60-
# Therefore the generator generates yup schema `.url()` followed by `uri: 'url'`
61-
# If $1 does not match anywhere, the generator will ignore.
62-
uri: url
6359
email: email
64-
uuid: uuid
65-
# yup does not have `ipv4` API. If you want to add this,
66-
# you need to add the logic using `yup.addMethod`.
67-
# see: https://github.com/jquense/yup#addmethodschematype-schema-name-string-method--schema-void
68-
ipv4: ipv4
69-
min: ['min', '$1 - 1']
70-
max: ['max', '$1 + 1']
71-
exclusiveMin: min
72-
exclusiveMax: max

example/zod/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function DropDownComponentInputSchema(): z.ZodSchema<DropDownComponentInp
3636
export function EventArgumentInputSchema(): z.ZodSchema<EventArgumentInput> {
3737
return z.object({
3838
name: z.string().min(5),
39-
value: z.string().regex(/^foo/)
39+
value: z.string().regex(/^foo/, "message")
4040
})
4141
}
4242

0 commit comments

Comments
 (0)