Skip to content

Commit 4e0a75a

Browse files
committed
Fix fragment generation for big depths
1 parent 80b5b9a commit 4e0a75a

File tree

3 files changed

+261
-220
lines changed

3 files changed

+261
-220
lines changed

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-graphql-to-typescript",
3-
"version": "0.10.7",
3+
"version": "0.10.8",
44
"description": "Simple Typescript interface generator from GraphQL Schemas",
55
"main": "dist/index.js",
66
"typings": "types/index.d.ts",
@@ -63,30 +63,30 @@
6363
"graphql": "^15.3.0"
6464
},
6565
"devDependencies": {
66-
"@apollo/client": "^3.2.9",
66+
"@apollo/client": "^3.3.11",
6767
"@types/figlet": "^1.2.0",
6868
"@types/graphql": "^14.5.0",
6969
"@types/inquirer": "^7.3.1",
70-
"@types/jest": "^26.0.10",
70+
"@types/jest": "^26.0.20",
7171
"@types/mkdirp": "^1.0.1",
72-
"@types/node": "^14.14.10",
73-
"@types/node-fetch": "^2.5.7",
74-
"@types/prettier": "^2.0.2",
72+
"@types/node": "^14.14.30",
73+
"@types/node-fetch": "^2.5.8",
74+
"@types/prettier": "^2.2.1",
7575
"@types/querystringify": "^2.0.0",
76-
"@typescript-eslint/eslint-plugin": "^4.8.2",
77-
"@typescript-eslint/parser": "^4.8.2",
78-
"@vuepress/plugin-google-analytics": "^1.5.4",
76+
"@typescript-eslint/eslint-plugin": "^4.15.1",
77+
"@typescript-eslint/parser": "^4.15.1",
78+
"@vuepress/plugin-google-analytics": "^1.8.2",
7979
"@zerollup/ts-transform-paths": "^1.7.18",
80-
"eslint": "^7.16.0",
81-
"eslint-config-prettier": "^7.1.0",
82-
"eslint-plugin-prettier": "^3.1.4",
80+
"eslint": "^7.20.0",
81+
"eslint-config-prettier": "^7.2.0",
82+
"eslint-plugin-prettier": "^3.3.1",
8383
"inquirer": "^7.3.3",
8484
"jest": "^26.6.3",
8585
"lodash": "^4.17.20",
8686
"rimraf": "^3.0.2",
87-
"ts-jest": "^26.4.4",
87+
"ts-jest": "^26.5.1",
8888
"ttypescript": "^1.5.12",
89-
"vuepress": "^1.5.4",
89+
"vuepress": "^1.8.2",
9090
"vuepress-plugin-autometa": "^0.1.13"
9191
},
9292
"dependencies": {
@@ -95,12 +95,12 @@
9595
"custom-env": "^2.0.1",
9696
"dotenv": "^8.2.0",
9797
"figlet": "^1.5.0",
98-
"graphql": "^15.3.0",
98+
"graphql": "^15.5.0",
9999
"mkdirp": "^1.0.4",
100100
"node-fetch": "^2.6.1",
101-
"ora": "^5.1.0",
101+
"ora": "^5.3.0",
102102
"prettier": "^2.2.1",
103103
"querystringify": "^2.2.0",
104-
"typescript": "^4.1.2"
104+
"typescript": "^4.1.5"
105105
}
106106
}

src/generators/fragments.generator.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,34 @@ export function generateNormalFragment(type: Type, connection?: boolean): string
3838
if (!isScalar && !isEnum) {
3939
const type = SchemaStore.findType(typeName);
4040
if (level < THRESHOLD) {
41-
outputFragment += `${field.name} {`;
42-
type?.fields?.forEach((field) => createFragmentWithDeps(field, level + 1));
43-
outputFragment += `} `;
41+
const allChildrenFragmentable = type?.fields.some((s) => {
42+
if (level + 1 >= THRESHOLD) {
43+
const { isEnum, isScalar } = SchemaStore.getFieldProps(s);
44+
return isEnum || isScalar;
45+
} else {
46+
return true;
47+
}
48+
});
49+
if (allChildrenFragmentable) {
50+
outputFragment += `${field.name} {`;
51+
52+
type?.fields?.forEach((field) => createFragmentWithDeps(field, level + 1));
53+
outputFragment += `} `;
54+
}
4455
} else if (type?.fields && type.fields.length < 7) {
45-
outputFragment += `${field.name} {`;
46-
type?.fields?.forEach((field) => createFragmentNoDeps(field));
47-
outputFragment += `} `;
56+
const allChildrenFragmentable = type?.fields.some((s) => {
57+
if (level + 1 >= THRESHOLD) {
58+
const { isEnum, isScalar } = SchemaStore.getFieldProps(s);
59+
return isEnum || isScalar;
60+
} else {
61+
return true;
62+
}
63+
});
64+
if (allChildrenFragmentable) {
65+
outputFragment += `${field.name} {`;
66+
type?.fields?.forEach((field) => createFragmentNoDeps(field));
67+
outputFragment += `} `;
68+
}
4869
}
4970
} else {
5071
outputFragment += `${field.name} `;

0 commit comments

Comments
 (0)