Skip to content

Commit 1e411a3

Browse files
Nols1000benjie
authored andcommitted
Update template function to handle formatting
Co-authored-by: Benjie <benjie@jemjie.com>
1 parent 35621e4 commit 1e411a3

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/utilities/getIntrospectionQuery.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,18 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
9090
return optionsWithDefault.experimentalDirectiveDeprecation ? str : '';
9191
}
9292
const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
93-
function ofType(level = 9): string {
93+
function ofType(level: number, indent: string): string {
9494
if (level <= 0) {
9595
return '';
9696
}
97+
if (level > 100) {
98+
throw new Error("Please set typeDepth to a reasonable value; the default is 9.");
99+
}
97100
return `
98-
ofType {
99-
name
100-
kind
101-
${ofType(level - 1)}
102-
}`;
101+
${indent}ofType {
102+
${indent} name
103+
${indent} kind${ofType(level - 1, indent + " ")}
104+
${indent}}`;
103105
}
104106

105107
return `
@@ -174,8 +176,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
174176
175177
fragment TypeRef on __Type {
176178
kind
177-
name
178-
${ofType(optionsWithDefault.typeDepth)}
179+
name${ofType(optionsWithDefault.typeDepth ?? 9, " ")}
179180
}
180181
`;
181182
}

0 commit comments

Comments
 (0)