Skip to content

Commit 35621e4

Browse files
Nols1000yaacovCR
authored andcommitted
Update getIntrospectionQuery.ts to allow configuration of the type query depth
This allows for a better configuration in case the server restricts the maximum query depth.
1 parent ad9c519 commit 35621e4

1 file changed

Lines changed: 22 additions & 36 deletions

File tree

src/utilities/getIntrospectionQuery.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export interface IntrospectionOptions {
4444
* Default: false
4545
*/
4646
oneOf?: boolean;
47+
48+
/**
49+
* How deep to recurse into nested types. Larger values will result in more
50+
* accurate results, but have a higher load. Some servers might restrict the
51+
* maximum query depth. If thats the case, try decreasing this value.
52+
*
53+
* Default: 9
54+
*/
55+
typeDepth?: number;
4756
}
4857

4958
/**
@@ -59,6 +68,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
5968
inputValueDeprecation: false,
6069
experimentalDirectiveDeprecation: false,
6170
oneOf: false,
71+
typeDepth: 9,
6272
...options,
6373
};
6474

@@ -80,6 +90,17 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
8090
return optionsWithDefault.experimentalDirectiveDeprecation ? str : '';
8191
}
8292
const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
93+
function ofType(level = 9): string {
94+
if (level <= 0) {
95+
return '';
96+
}
97+
return `
98+
ofType {
99+
name
100+
kind
101+
${ofType(level - 1)}
102+
}`;
103+
}
83104

84105
return `
85106
query IntrospectionQuery {
@@ -154,42 +175,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
154175
fragment TypeRef on __Type {
155176
kind
156177
name
157-
ofType {
158-
kind
159-
name
160-
ofType {
161-
kind
162-
name
163-
ofType {
164-
kind
165-
name
166-
ofType {
167-
kind
168-
name
169-
ofType {
170-
kind
171-
name
172-
ofType {
173-
kind
174-
name
175-
ofType {
176-
kind
177-
name
178-
ofType {
179-
kind
180-
name
181-
ofType {
182-
kind
183-
name
184-
}
185-
}
186-
}
187-
}
188-
}
189-
}
190-
}
191-
}
192-
}
178+
${ofType(optionsWithDefault.typeDepth)}
193179
}
194180
`;
195181
}

0 commit comments

Comments
 (0)