Skip to content

Commit 4cd3ba9

Browse files
authored
Merge pull request #280 from Code-Hex/fix/union-generation
fixed to supress union type generation when withObjectType is false
2 parents 58c511d + b866b1c commit 4cd3ba9

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ jobs:
3636
with:
3737
commit_message: Apply auto lint-fix changes
3838
branch: ${{ github.head_ref }}
39-
- name: eslint
40-
if: steps.auto-commit-action.outputs.changes_detected == 'false'
41-
uses: reviewdog/action-eslint@v1
42-
with:
43-
level: warning
44-
reporter: github-pr-review
39+
# See: https://github.com/reviewdog/action-eslint/issues/152
40+
# - name: eslint
41+
# if: steps.auto-commit-action.outputs.changes_detected == 'false'
42+
# uses: reviewdog/action-eslint@v1
43+
# with:
44+
# github_token: ${{ secrets.GITHUB_TOKEN }}
45+
# level: warning
46+
# reporter: github-pr-review

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@types/jest": "29.2.5",
5454
"@typescript-eslint/eslint-plugin": "5.46.1",
5555
"@typescript-eslint/parser": "5.46.1",
56-
"eslint": "8.31.0",
56+
"eslint": "8.32.0",
5757
"jest": "29.3.1",
5858
"myzod": "1.8.8",
5959
"npm-run-all": "4.1.5",

src/myzod/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const MyZodSchemaVisitor = (schema: GraphQLSchema, config: ValidationSche
9191
.withContent(`myzod.enum(${enumname})`).string;
9292
},
9393
UnionTypeDefinition: (node: UnionTypeDefinitionNode) => {
94-
if (!node.types) return;
94+
if (!node.types || !config.withObjectType) return;
9595

9696
const unionName = tsVisitor.convertName(node.name.value);
9797
const unionElements = node.types?.map(t => `${tsVisitor.convertName(t.name.value)}Schema()`).join(', ');

src/yup/index.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
2929
}
3030
return [importYup];
3131
},
32-
initialEmit: (): string =>
33-
'\n' +
34-
new DeclarationBlock({})
35-
.asKind('function')
36-
.withName('union<T>(...schemas: ReadonlyArray<yup.SchemaOf<T>>): yup.BaseSchema<T>')
37-
.withBlock(
38-
[
39-
indent('return yup.mixed().test({'),
40-
indent('test: (value) => schemas.some((schema) => schema.isValidSync(value))', 2),
41-
indent('})'),
42-
].join('\n')
43-
).string,
32+
initialEmit: (): string => {
33+
if (!config.withObjectType) return '';
34+
return (
35+
'\n' +
36+
new DeclarationBlock({})
37+
.asKind('function')
38+
.withName('union<T>(...schemas: ReadonlyArray<yup.SchemaOf<T>>): yup.BaseSchema<T>')
39+
.withBlock(
40+
[
41+
indent('return yup.mixed().test({'),
42+
indent('test: (value) => schemas.some((schema) => schema.isValidSync(value))', 2),
43+
indent('})'),
44+
].join('\n')
45+
).string
46+
);
47+
},
4448
InputObjectTypeDefinition: (node: InputObjectTypeDefinitionNode) => {
4549
const name = tsVisitor.convertName(node.name.value);
4650
importTypes.push(name);
@@ -102,7 +106,7 @@ export const YupSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
102106
.withContent(`yup.mixed().oneOf([${values}])`).string;
103107
},
104108
UnionTypeDefinition: (node: UnionTypeDefinitionNode) => {
105-
if (!node.types) return;
109+
if (!node.types || !config.withObjectType) return;
106110

107111
const unionName = tsVisitor.convertName(node.name.value);
108112
importTypes.push(unionName);

src/zod/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const ZodSchemaVisitor = (schema: GraphQLSchema, config: ValidationSchema
102102
.withContent(`z.nativeEnum(${enumname})`).string;
103103
},
104104
UnionTypeDefinition: (node: UnionTypeDefinitionNode) => {
105-
if (!node.types) return;
105+
if (!node.types || !config.withObjectType) return;
106106

107107
const unionName = tsVisitor.convertName(node.name.value);
108108
const unionElements = node.types.map(t => `${tsVisitor.convertName(t.name.value)}Schema()`).join(', ');

yarn.lock

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,11 +2054,16 @@ acorn-walk@^8.1.1:
20542054
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1"
20552055
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==
20562056

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

2062+
acorn@^8.8.0:
2063+
version "8.8.1"
2064+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.1.tgz#0a3f9cbecc4ec3bea6f0a80b66ae8dd2da250b73"
2065+
integrity sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==
2066+
20622067
agent-base@6:
20632068
version "6.0.2"
20642069
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
@@ -2751,14 +2756,14 @@ debounce@^1.2.0:
27512756
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5"
27522757
integrity sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==
27532758

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

2761-
debug@^4.3.4:
2766+
debug@^4.3.2, debug@^4.3.4:
27622767
version "4.3.4"
27632768
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
27642769
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
@@ -2988,10 +2993,10 @@ eslint-visitor-keys@^3.3.0:
29882993
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
29892994
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==
29902995

2991-
eslint@8.31.0:
2992-
version "8.31.0"
2993-
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.31.0.tgz#75028e77cbcff102a9feae1d718135931532d524"
2994-
integrity sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA==
2996+
eslint@8.32.0:
2997+
version "8.32.0"
2998+
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.32.0.tgz#d9690056bb6f1a302bd991e7090f5b68fbaea861"
2999+
integrity sha512-nETVXpnthqKPFyuY2FNjz/bEd6nbosRgKbkgS/y1C7LJop96gYHWpiguLecMHQ2XCPxn77DS0P+68WzG6vkZSQ==
29953000
dependencies:
29963001
"@eslint/eslintrc" "^1.4.1"
29973002
"@humanwhocodes/config-array" "^0.11.8"
@@ -3034,9 +3039,9 @@ [email protected]:
30343039
text-table "^0.2.0"
30353040

30363041
espree@^9.4.0:
3037-
version "9.4.0"
3038-
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.0.tgz#cd4bc3d6e9336c433265fc0aa016fc1aaf182f8a"
3039-
integrity sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==
3042+
version "9.4.1"
3043+
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd"
3044+
integrity sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==
30403045
dependencies:
30413046
acorn "^8.8.0"
30423047
acorn-jsx "^5.3.2"
@@ -4276,9 +4281,9 @@ [email protected]:
42764281
jest-cli "^29.3.1"
42774282

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

42834288
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
42844289
version "4.0.0"

0 commit comments

Comments
 (0)