Skip to content

Commit 0d9be6a

Browse files
committed
chore: more setup
1 parent f77107d commit 0d9be6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2777
-2038
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/renovate.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/issues.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/validate.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Validate
2+
3+
on:
4+
push:
5+
branches: ['**']
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
validate:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup pnpm
18+
uses: pnpm/action-setup@v4
19+
with:
20+
version: 10.11.1
21+
22+
- name: Setup Node.js 20.19.0
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20.19.0
26+
cache: 'pnpm'
27+
28+
- name: Install dependencies
29+
run: pnpm install --frozen-lockfile
30+
31+
- name: Type check
32+
run: pnpm type-check
33+
34+
- name: Type check examples
35+
run: |
36+
pnpm type-check:yup
37+
pnpm type-check:zod
38+
pnpm type-check:myzod
39+
pnpm type-check:valibot
40+
41+
- name: Lint
42+
run: pnpm lint
43+
44+
- name: Build
45+
run: pnpm build
46+
47+
- name: Test
48+
run: pnpm test
49+
50+
- name: Generate schemas
51+
run: pnpm generate

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm exec lint-staged

.prettierignore

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
**
1+
# Dependencies
2+
node_modules/
3+
pnpm-lock.yaml
4+
5+
# Build outputs
6+
dist/
7+
build/
8+
*.tsbuildinfo
9+
10+
# Generated files
11+
coverage/
12+
.nyc_output/
13+
14+
# OS files
15+
.DS_Store
16+
Thumbs.db
17+
18+
# IDE files
19+
.vscode/
20+
.idea/
21+
22+
# Logs
23+
*.log
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"arrowParens": "always",
3+
"printWidth": 100,
4+
"singleQuote": true,
5+
"trailingComma": "none",
6+
"plugins": ["prettier-plugin-package"]
7+
}

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ generates:
8282
Then the generator generates code with import statement like below.
8383

8484
```ts
85-
import { GeneratedInput } from './graphql'
85+
import { GeneratedInput } from './graphql';
8686
8787
/* generates validation schema here */
8888
```
@@ -110,7 +110,7 @@ generates:
110110
Then the generator generates code with import statement like below.
111111

112112
```ts
113-
import * as types from './graphql'
113+
import * as types from './graphql';
114114
115115
/* generates validation schema here */
116116
```
@@ -145,7 +145,7 @@ generates:
145145
Then the generator generates code with import statement like below.
146146

147147
```ts
148-
import { IGeneratedInput } from './graphql'
148+
import { IGeneratedInput } from './graphql';
149149
150150
/* generates validation schema here */
151151
```
@@ -172,7 +172,7 @@ generates:
172172
Then the generator generates code with import statement like below.
173173

174174
```ts
175-
import { GeneratedInputI } from './graphql'
175+
import { GeneratedInputI } from './graphql';
176176
177177
/* generates validation schema here */
178178
```
@@ -222,13 +222,15 @@ type: `string`
222222
Fallback scalar type for undefined scalar types in the schema not found in `scalarSchemas`.
223223

224224
#### yup schema
225+
225226
```yml
226227
config:
227228
schema: yup
228229
defaultScalarSchema: yup.unknown()
229230
```
230231

231232
#### zod schema
233+
232234
```yml
233235
config:
234236
schema: zod
@@ -297,14 +299,17 @@ query Editor_StoryQuery($storyId: UUID!) {
297299
It will generate:
298300

299301
```typescript
300-
export function Editor_StoryQueryVariableSchema(): z.ZodObject<Properties<Editor_StoryQueryQueryVariables>> {
302+
export function Editor_StoryQueryVariableSchema(): z.ZodObject<
303+
Properties<Editor_StoryQueryQueryVariables>
304+
> {
301305
return z.object({
302306
storyId: z.string()
303307
});
304308
}
305309
```
306310

307311
The generated schemas properly handle:
312+
308313
- Required vs optional variables
309314
- Default values
310315
- References to existing input type schemas
@@ -382,8 +387,11 @@ Then generates yup validation schema like below.
382387
export function ExampleInputSchema(): yup.SchemaOf<ExampleInput> {
383388
return yup.object({
384389
email: yup.string().defined().required('Hello, World!').min(50).email(),
385-
message: yup.string().defined().matches(/^Hello/)
386-
})
390+
message: yup
391+
.string()
392+
.defined()
393+
.matches(/^Hello/)
394+
});
387395
}
388396
```
389397

@@ -423,7 +431,7 @@ export function ExampleInputSchema(): z.ZodSchema<ExampleInput> {
423431
return z.object({
424432
email: z.string().min(50).email(),
425433
message: z.string().regex(/^Hello/, 'message')
426-
})
434+
});
427435
}
428436
```
429437

@@ -478,6 +486,7 @@ mutation CreatePost($input: CreatePostInput!) {
478486
The plugin will generate validation schemas like:
479487

480488
#### Zod
489+
481490
```typescript
482491
export function GetUserVariableSchema(): z.ZodObject<Properties<GetUserQueryVariables>> {
483492
return z.object({
@@ -494,6 +503,7 @@ export function CreatePostVariableSchema(): z.ZodObject<Properties<CreatePostMut
494503
```
495504

496505
#### Yup
506+
497507
```typescript
498508
export function GetUserVariableSchema(): yup.SchemaOf<GetUserQueryVariables> {
499509
return yup.object({

example/myzod/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
Basically, I think [it does not support overwrite schema](https://github.com/davidmdm/myzod/issues/51) in myzod. However, [`and`](https://github.com/davidmdm/myzod#typeand) and [`or`](https://github.com/davidmdm/myzod#typeor) may helps you.
66

7-
See also: https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/issues/25#issuecomment-1086532098
7+
See also: https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/issues/25#issuecomment-1086532098

0 commit comments

Comments
 (0)