Skip to content

Commit 8d16f2b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into improve-zod-test
2 parents b820268 + aae68ab commit 8d16f2b

File tree

13 files changed

+2047
-608
lines changed

13 files changed

+2047
-608
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v3
12-
- uses: pnpm/action-setup@v2
12+
- uses: pnpm/action-setup@v3
1313
with:
14-
version: 8
14+
package_json_file: ./package.json
1515
- name: Setup Node
1616
uses: actions/setup-node@v3
1717
with:
@@ -25,9 +25,9 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v3
28-
- uses: pnpm/action-setup@v2
28+
- uses: pnpm/action-setup@v3
2929
with:
30-
version: 8
30+
package_json_file: ./package.json
3131
- name: Setup Node
3232
uses: actions/setup-node@v3
3333
with:

codegen.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,26 @@ generates:
8181
email: email
8282
scalars:
8383
ID: string
84+
example/valibot/schemas.ts:
85+
plugins:
86+
- ./dist/main/index.js:
87+
schema: valibot
88+
importFrom: ../types
89+
withObjectType: true
90+
directives:
91+
# Write directives like
92+
#
93+
# directive:
94+
# arg1: schemaApi
95+
# arg2: ["schemaApi2", "Hello $1"]
96+
#
97+
# See more examples in `./tests/directive.spec.ts`
98+
# https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/blob/main/tests/directive.spec.ts
99+
constraint:
100+
minLength: minLength
101+
# Replace $1 with specified `startsWith` argument value of the constraint directive
102+
startsWith: [regex, /^$1/, message]
103+
format:
104+
email: email
105+
scalars:
106+
ID: string

eslint.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ export default antfu({
1212
'README.md',
1313
],
1414
}, {
15-
rules: { 'style/semi': 'off' },
15+
rules: {
16+
'style/semi': 'off',
17+
'regexp/no-unused-capturing-group': 'off',
18+
},
1619
})

example/valibot/schemas.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import * as v from 'valibot'
2+
import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, Namer, PageInput, PageType, User } from '../types'
3+
4+
export const ButtonComponentTypeSchema = v.enum_(ButtonComponentType);
5+
6+
export const EventOptionTypeSchema = v.enum_(EventOptionType);
7+
8+
export const HttpMethodSchema = v.enum_(HttpMethod);
9+
10+
export const PageTypeSchema = v.enum_(PageType);
11+
12+
export function AdminSchema(): v.GenericSchema<Admin> {
13+
return v.object({
14+
__typename: v.optional(v.literal('Admin')),
15+
lastModifiedAt: v.nullish(v.any())
16+
})
17+
}
18+
19+
export function AttributeInputSchema(): v.GenericSchema<AttributeInput> {
20+
return v.object({
21+
key: v.nullish(v.string()),
22+
val: v.nullish(v.string())
23+
})
24+
}
25+
26+
export function ComponentInputSchema(): v.GenericSchema<ComponentInput> {
27+
return v.object({
28+
child: v.lazy(() => v.nullish(ComponentInputSchema())),
29+
childrens: v.nullish(v.array(v.lazy(() => v.nullable(ComponentInputSchema())))),
30+
event: v.lazy(() => v.nullish(EventInputSchema())),
31+
name: v.string(),
32+
type: ButtonComponentTypeSchema
33+
})
34+
}
35+
36+
export function DropDownComponentInputSchema(): v.GenericSchema<DropDownComponentInput> {
37+
return v.object({
38+
dropdownComponent: v.lazy(() => v.nullish(ComponentInputSchema())),
39+
getEvent: v.lazy(() => EventInputSchema())
40+
})
41+
}
42+
43+
export function EventArgumentInputSchema(): v.GenericSchema<EventArgumentInput> {
44+
return v.object({
45+
name: v.pipe(v.string(), v.minLength(5)),
46+
value: v.pipe(v.string(), v.regex(/^foo/, "message"))
47+
})
48+
}
49+
50+
export function EventInputSchema(): v.GenericSchema<EventInput> {
51+
return v.object({
52+
arguments: v.array(v.lazy(() => EventArgumentInputSchema())),
53+
options: v.nullish(v.array(EventOptionTypeSchema))
54+
})
55+
}
56+
57+
export function GuestSchema(): v.GenericSchema<Guest> {
58+
return v.object({
59+
__typename: v.optional(v.literal('Guest')),
60+
lastLoggedIn: v.nullish(v.any())
61+
})
62+
}
63+
64+
export function HttpInputSchema(): v.GenericSchema<HttpInput> {
65+
return v.object({
66+
method: v.nullish(HttpMethodSchema),
67+
url: v.any()
68+
})
69+
}
70+
71+
export function LayoutInputSchema(): v.GenericSchema<LayoutInput> {
72+
return v.object({
73+
dropdown: v.lazy(() => v.nullish(DropDownComponentInputSchema()))
74+
})
75+
}
76+
77+
export function MyTypeSchema(): v.GenericSchema<MyType> {
78+
return v.object({
79+
__typename: v.optional(v.literal('MyType')),
80+
foo: v.nullish(v.string())
81+
})
82+
}
83+
84+
export function MyTypeFooArgsSchema(): v.GenericSchema<MyTypeFooArgs> {
85+
return v.object({
86+
a: v.nullish(v.string()),
87+
b: v.number(),
88+
c: v.nullish(v.boolean()),
89+
d: v.number()
90+
})
91+
}
92+
93+
export function NamerSchema(): v.GenericSchema<Namer> {
94+
return v.object({
95+
name: v.nullish(v.string())
96+
})
97+
}
98+
99+
export function PageInputSchema(): v.GenericSchema<PageInput> {
100+
return v.object({
101+
attributes: v.nullish(v.array(v.lazy(() => AttributeInputSchema()))),
102+
date: v.nullish(v.any()),
103+
height: v.number(),
104+
id: v.string(),
105+
layout: v.lazy(() => LayoutInputSchema()),
106+
pageType: PageTypeSchema,
107+
postIDs: v.nullish(v.array(v.string())),
108+
show: v.boolean(),
109+
tags: v.nullish(v.array(v.nullable(v.string()))),
110+
title: v.string(),
111+
width: v.number()
112+
})
113+
}
114+
115+
export function UserSchema(): v.GenericSchema<User> {
116+
return v.object({
117+
__typename: v.optional(v.literal('User')),
118+
createdAt: v.nullish(v.any()),
119+
email: v.nullish(v.string()),
120+
id: v.nullish(v.string()),
121+
kind: v.nullish(UserKindSchema()),
122+
name: v.nullish(v.string()),
123+
password: v.nullish(v.string()),
124+
updatedAt: v.nullish(v.any())
125+
})
126+
}
127+
128+
export function UserKindSchema() {
129+
return v.union([AdminSchema(), GuestSchema()])
130+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "graphql-codegen-typescript-validation-schema",
33
"version": "0.14.1",
4+
"packageManager": "[email protected]",
45
"description": "GraphQL Code Generator plugin to generate form validation schema from your GraphQL schema",
56
"respository": {
67
"type": "git",
@@ -46,6 +47,7 @@
4647
"type-check:yup": "tsc --strict --skipLibCheck --noEmit example/yup/schemas.ts",
4748
"type-check:zod": "tsc --strict --skipLibCheck --noEmit example/zod/schemas.ts",
4849
"type-check:myzod": "tsc --strict --skipLibCheck --noEmit example/myzod/schemas.ts",
50+
"type-check:valibot": "tsc --strict --skipLibCheck --noEmit example/valibot/schemas.ts",
4951
"test": "vitest run",
5052
"build": "run-p build:*",
5153
"build:main": "tsc -p tsconfig.main.json",
@@ -74,13 +76,14 @@
7476
"@tsconfig/recommended": "1.0.6",
7577
"@types/graphlib": "^2.1.8",
7678
"@types/node": "^20.0.0",
77-
"eslint": "9.3.0",
79+
"eslint": "9.4.0",
7880
"jest": "29.7.0",
7981
"myzod": "1.11.0",
8082
"npm-run-all2": "6.2.0",
8183
"ts-dedent": "^2.2.0",
82-
"ts-jest": "29.1.3",
84+
"ts-jest": "29.1.4",
8385
"typescript": "5.4.5",
86+
"valibot": "0.31.0-rc.12",
8487
"vitest": "^1.0.0",
8588
"yup": "1.4.0",
8689
"zod": "3.23.8"

0 commit comments

Comments
 (0)