Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ jobs:
with:
commit_message: Apply auto lint-fix changes
branch: ${{ github.head_ref }}
- name: eslint
if: steps.auto-commit-action.outputs.changes_detected == 'false'
uses: reviewdog/action-eslint@v1
with:
level: warning
reporter: github-pr-review
# 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@types/jest": "29.2.5",
"@typescript-eslint/eslint-plugin": "5.46.1",
"@typescript-eslint/parser": "5.46.1",
"eslint": "8.31.0",
"eslint": "8.32.0",
"jest": "29.3.1",
"myzod": "1.8.8",
"npm-run-all": "4.1.5",
Expand Down
2 changes: 1 addition & 1 deletion src/myzod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const MyZodSchemaVisitor = (schema: GraphQLSchema, config: ValidationSche
.withContent(`myzod.enum(${enumname})`).string;
},
UnionTypeDefinition: (node: UnionTypeDefinitionNode) => {
if (!node.types) return;
if (!node.types || !config.withObjectType) return;

const unionName = tsVisitor.convertName(node.name.value);
const unionElements = node.types?.map(t => `${tsVisitor.convertName(t.name.value)}Schema()`).join(', ');
Expand Down
30 changes: 17 additions & 13 deletions src/yup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
}
return [importYup];
},
initialEmit: (): string =>
'\n' +
new DeclarationBlock({})
.asKind('function')
.withName('union<T>(...schemas: ReadonlyArray<yup.SchemaOf<T>>): yup.BaseSchema<T>')
.withBlock(
[
indent('return yup.mixed().test({'),
indent('test: (value) => schemas.some((schema) => schema.isValidSync(value))', 2),
indent('})'),
].join('\n')
).string,
initialEmit: (): string => {
if (!config.withObjectType) return '';
return (
'\n' +
new DeclarationBlock({})
.asKind('function')
.withName('union<T>(...schemas: ReadonlyArray<yup.SchemaOf<T>>): yup.BaseSchema<T>')
.withBlock(
[
indent('return yup.mixed().test({'),
indent('test: (value) => schemas.some((schema) => schema.isValidSync(value))', 2),
indent('})'),
].join('\n')
).string
);
},
InputObjectTypeDefinition: (node: InputObjectTypeDefinitionNode) => {
const name = tsVisitor.convertName(node.name.value);
importTypes.push(name);
Expand Down Expand Up @@ -102,7 +106,7 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
.withContent(`yup.mixed().oneOf([${values}])`).string;
},
UnionTypeDefinition: (node: UnionTypeDefinitionNode) => {
if (!node.types) return;
if (!node.types || !config.withObjectType) return;

const unionName = tsVisitor.convertName(node.name.value);
importTypes.push(unionName);
Expand Down
2 changes: 1 addition & 1 deletion src/zod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const ZodSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
.withContent(`z.nativeEnum(${enumname})`).string;
},
UnionTypeDefinition: (node: UnionTypeDefinitionNode) => {
if (!node.types) return;
if (!node.types || !config.withObjectType) return;

const unionName = tsVisitor.convertName(node.name.value);
const unionElements = node.types.map(t => `${tsVisitor.convertName(t.name.value)}Schema()`).join(', ');
Expand Down
31 changes: 18 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2054,11 +2054,16 @@ acorn-walk@^8.1.1:
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1"
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==

acorn@^8.4.1, acorn@^8.8.0:
acorn@^8.4.1:
version "8.8.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8"
integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==

acorn@^8.8.0:
version "8.8.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.1.tgz#0a3f9cbecc4ec3bea6f0a80b66ae8dd2da250b73"
integrity sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==

agent-base@6:
version "6.0.2"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
Expand Down Expand Up @@ -2751,14 +2756,14 @@ debounce@^1.2.0:
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5"
integrity sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==

debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2:
debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1:
version "4.3.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
dependencies:
ms "2.1.2"

debug@^4.3.4:
debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
Expand Down Expand Up @@ -2988,10 +2993,10 @@ eslint-visitor-keys@^3.3.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==

eslint@8.31.0:
version "8.31.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.31.0.tgz#75028e77cbcff102a9feae1d718135931532d524"
integrity sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA==
eslint@8.32.0:
version "8.32.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.32.0.tgz#d9690056bb6f1a302bd991e7090f5b68fbaea861"
integrity sha512-nETVXpnthqKPFyuY2FNjz/bEd6nbosRgKbkgS/y1C7LJop96gYHWpiguLecMHQ2XCPxn77DS0P+68WzG6vkZSQ==
dependencies:
"@eslint/eslintrc" "^1.4.1"
"@humanwhocodes/config-array" "^0.11.8"
Expand Down Expand Up @@ -3034,9 +3039,9 @@ [email protected]:
text-table "^0.2.0"

espree@^9.4.0:
version "9.4.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.0.tgz#cd4bc3d6e9336c433265fc0aa016fc1aaf182f8a"
integrity sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==
version "9.4.1"
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd"
integrity sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==
dependencies:
acorn "^8.8.0"
acorn-jsx "^5.3.2"
Expand Down Expand Up @@ -4276,9 +4281,9 @@ [email protected]:
jest-cli "^29.3.1"

js-sdsl@^4.1.4:
version "4.1.4"
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.1.4.tgz#78793c90f80e8430b7d8dc94515b6c77d98a26a6"
integrity sha512-Y2/yD55y5jteOAmY50JbUZYwk3CP3wnLPEZnlR1w9oKhITrBEtAxwuWKebFf8hMrPMgbYwFoWK/lH2sBkErELw==
version "4.2.0"
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.2.0.tgz#278e98b7bea589b8baaf048c20aeb19eb7ad09d0"
integrity sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==

"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0"
Expand Down