Skip to content

Commit 366de1f

Browse files
Nols1000benjie
andauthored
Update template function to handle formatting
Co-authored-by: Benjie <[email protected]>
1 parent 388d405 commit 366de1f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/utilities/getIntrospectionQuery.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,18 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
8080
return optionsWithDefault.inputValueDeprecation ? str : '';
8181
}
8282
const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
83-
function ofType(level = 9): string {
83+
function ofType(level: number, indent: string): string {
8484
if (level <= 0) {
8585
return '';
8686
}
87+
if (level > 100) {
88+
throw new Error("Please set typeDepth to a reasonable value; the default is 9.");
89+
}
8790
return `
88-
ofType {
89-
name
90-
kind
91-
${ofType(level - 1)}
92-
}`;
91+
${indent}ofType {
92+
${indent} name
93+
${indent} kind${ofType(level - 1, indent + " ")}
94+
${indent}}`;
9395
}
9496

9597
return `
@@ -160,8 +162,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
160162
161163
fragment TypeRef on __Type {
162164
kind
163-
name
164-
${ofType(optionsWithDefault.typeDepth)}
165+
name${ofType(optionsWithDefault.typeDepth ?? 9, " ")}
165166
}
166167
`;
167168
}

0 commit comments

Comments
 (0)