Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7dbeb87
add pnpm
wand2016 Oct 23, 2023
f64de69
migrate to yarn for yarn link
wand2016 Oct 23, 2023
bb1416e
drop zod and myzod for brevity
wand2016 Oct 26, 2023
8e7b623
Laravel仕様のdirectiveからyup validation schema生成まで
wand2016 Oct 26, 2023
c0e41aa
ignoreRules追加
wand2016 Oct 26, 2023
4ae60a9
コード分割・テスト追加
wand2016 Oct 26, 2023
921b909
fix tests
wand2016 Oct 26, 2023
9c551a7
fix example
wand2016 Oct 26, 2023
b94e48d
make required the arguments for type guards
wand2016 Oct 26, 2023
34fd7d1
return by directives (rules, rulesForArray, rulesForInput)
wand2016 Oct 26, 2023
ee1a063
for required
wand2016 Oct 26, 2023
0b293cc
配列対応
wand2016 Oct 26, 2023
877bf73
parameterize tests
wand2016 Oct 26, 2023
3be8f50
drop rulesForInput directive
wand2016 Oct 26, 2023
d1f9842
type Mutation も対象に
wand2016 Oct 26, 2023
b966da6
fix tests
wand2016 Oct 27, 2023
bca728e
fix name and version
wand2016 Oct 27, 2023
daf3510
ignore .idea
wand2016 Nov 2, 2023
8c73752
support regex literal
wand2016 Nov 2, 2023
0f2f476
bump minor
wand2016 Nov 2, 2023
e99fe70
fix testing import
wand2016 Nov 2, 2023
67f0eb5
opt-in yup.lazy
wand2016 Nov 9, 2023
6121ed3
implement sometimes generation
wand2016 Nov 14, 2023
3bd9d1e
eliminate defined()
wand2016 Nov 14, 2023
8d28536
strict for preserve unkeyed undefined
wand2016 Nov 14, 2023
db88e86
defined for nonNull
wand2016 Nov 14, 2023
4dcb1a9
update example output
wand2016 Nov 14, 2023
2e95fdd
pass sometimes fieldname
wand2016 Nov 14, 2023
794eb83
defiend for arrays
wand2016 Nov 14, 2023
1b38aaf
update example
wand2016 Nov 14, 2023
1e5dacf
defined for array elements and union
wand2016 Nov 14, 2023
0245190
リファクタリング (#1)
wand2016 Nov 19, 2023
45b8328
Refactoring2 (#2)
wand2016 Nov 20, 2023
3117893
E2RPRO-4471 validation 自動生成 -- ツールlazy対応 (#3)
wand2016 Nov 21, 2023
5ea9d3c
added CI (#4)
wand2016 Nov 21, 2023
1092504
release (#5)
wand2016 Nov 21, 2023
eb3ef52
リリーススクリプト整備 (#6)
wand2016 Nov 21, 2023
25f1738
fix repo url in package.json (#7)
wand2016 Nov 22, 2023
4c54b58
E2RPRO-4480 validation 自動生成 -- カスタムメソッド追加 (#8)
wand2016 Nov 27, 2023
9f2ee3a
E2RPRO-4505 pnpmへ移行 (#9)
wand2016 Dec 1, 2023
c35a2a7
union types (#10)
wand2016 Dec 5, 2023
7517f67
emit union as ObjectSchema<T> (#11)
wand2016 May 28, 2024
acf6915
ENT-904940 schema のコメント対応 (#12)
wand2016 Aug 16, 2024
789bd08
meta ではなく label 使う
wand2016 Aug 16, 2024
c2fe5ce
generate
wand2016 Aug 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

63 changes: 20 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,29 @@
name: Test
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: current
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test
- name: Setup asdf
uses: asdf-vm/actions/setup@v3
# 2回目以降エラーが出るが問題ない
continue-on-error: true
- name: asdf install
uses: asdf-vm/actions/install@v3
- name: Install dependencies
run: pnpm install
- name: lint
run: pnpm lint
- name: fmt
run: pnpm prettier:check
- name: test
run: pnpm test
env:
CI: true
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: current
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm lint-fix
- run: pnpm prettier
- name: Auto commit fixed code
id: auto-commit-action
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply auto lint-fix changes
branch: ${{ github.head_ref }}
# See: https://github.com/reviewdog/action-eslint/issues/152
# - name: eslint
# if: steps.auto-commit-action.outputs.changes_detected == 'false'
# uses: reviewdog/action-eslint@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# level: warning
# reporter: github-pr-review
- name: generate and type-check
run: |
pnpm generate
pnpm type-check
11 changes: 0 additions & 11 deletions .github/workflows/issues.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: release
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Setup asdf
uses: asdf-vm/actions/setup@v3
# 2回目以降エラーが出るが問題ない
continue-on-error: true
- name: asdf install
uses: asdf-vm/actions/install@v3
- name: Install dependencies
run: pnpm install
- name: generate and type-check
run: |
pnpm generate
pnpm type-check
- name: prepare release
run: |
sed .gitignore -i -e s/dist//g
VERSION=$(cat package.json | jq -r .version)
git config user.name "actions-user"
git config user.email "action@github.com"
git add .gitignore
git add dist
git commit -m "release ${VERSION}"
git tag -a "v${VERSION}" -m "release ${VERSION}"
git push origin --tags
136 changes: 130 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,131 @@
node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist
.npmignore
package-lock.json
.DS_Store
tsconfig.tsbuildinfo
yarn-error.log

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.idea
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 20.14.0
pnpm 9.7.1
72 changes: 2 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
[GraphQL code generator](https://github.com/dotansimha/graphql-code-generator) plugin to generate form validation schema from your GraphQL schema.

- [x] support [yup](https://github.com/jquense/yup)
- [x] support [zod](https://github.com/colinhacks/zod)
- [x] support [myzod](https://github.com/davidmdm/myzod)

## Quick Start

Expand All @@ -31,7 +29,6 @@ generates:
scalars:
ID: string
# You can also write the config for this plugin together
schema: yup # or zod
```

It is recommended to write `scalars` config for built-in type `ID`, as in the yaml example shown above. For more information: [#375](https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/pull/375)
Expand All @@ -42,24 +39,6 @@ The Q&A for each schema is written in the README in the respective example direc

## Config API Reference

### `schema`

type: `ValidationSchema` default: `'yup'`

Specify generete validation schema you want.

You can specify `yup` or `zod` or `myzod`.

```yml
generates:
path/to/graphql.ts:
plugins:
- typescript
- typescript-validation-schema
config:
schema: yup
```

### `importFrom`

type: `string`
Expand Down Expand Up @@ -176,16 +155,6 @@ config:
Email: yup.string().email()
```

#### zod schema

```yml
config:
schema: zod
scalarSchemas:
Date: z.date()
Email: z.string().email()
```

### `withObjectType`

type: `boolean` default: `false`
Expand Down Expand Up @@ -255,51 +224,14 @@ export function ExampleInputSchema(): yup.SchemaOf<ExampleInput> {
}
```

#### zod schema

```yml
generates:
path/to/graphql.ts:
plugins:
- typescript
- typescript-validation-schema
config:
schema: zod
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
```

Then generates zod validation schema like below.

```ts
export function ExampleInputSchema(): z.ZodSchema<ExampleInput> {
return z.object({
email: z.string().min(50).email(),
message: z.string().regex(/^Hello/, "message")
})
}
```

#### other schema

Please see [example](https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/tree/main/example) directory.

## Notes

Their is currently a compatibility issue with the client-preset. A workaround for this is to split the generation into two (one for client-preset and one for typescript-validation-schema).
There is currently a compatibility issue with the client-preset. A workaround for this is to split the generation into two (one for client-preset and one for typescript-validation-schema).

```yml
generates:
Expand All @@ -310,4 +242,4 @@ generates:
preset: 'client',
plugins:
...
```
```
Loading