Skip to content

Commit 388d405

Browse files
committed
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 48afd37 commit 388d405

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

src/utilities/getIntrospectionQuery.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export interface IntrospectionOptions {
3838
* Default: false
3939
*/
4040
oneOf?: boolean;
41+
42+
/**
43+
* How deep to recurse into nested types. Larger values will result in more
44+
* accurate results, but have a higher load. Some servers might restrict the
45+
* maximum query depth. If thats the case, try decreasing this value.
46+
*
47+
* Default: 9
48+
*/
49+
typeDepth?: number;
4150
}
4251

4352
/**
@@ -52,6 +61,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
5261
schemaDescription: false,
5362
inputValueDeprecation: false,
5463
oneOf: false,
64+
typeDepth: 9,
5565
...options,
5666
};
5767

@@ -70,6 +80,17 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
7080
return optionsWithDefault.inputValueDeprecation ? str : '';
7181
}
7282
const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
83+
function ofType(level = 9): string {
84+
if (level <= 0) {
85+
return '';
86+
}
87+
return `
88+
ofType {
89+
name
90+
kind
91+
${ofType(level - 1)}
92+
}`;
93+
}
7394

7495
return `
7596
query IntrospectionQuery {
@@ -140,42 +161,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
140161
fragment TypeRef on __Type {
141162
kind
142163
name
143-
ofType {
144-
kind
145-
name
146-
ofType {
147-
kind
148-
name
149-
ofType {
150-
kind
151-
name
152-
ofType {
153-
kind
154-
name
155-
ofType {
156-
kind
157-
name
158-
ofType {
159-
kind
160-
name
161-
ofType {
162-
kind
163-
name
164-
ofType {
165-
kind
166-
name
167-
ofType {
168-
kind
169-
name
170-
}
171-
}
172-
}
173-
}
174-
}
175-
}
176-
}
177-
}
178-
}
164+
${ofType(optionsWithDefault.typeDepth)}
179165
}
180166
`;
181167
}

0 commit comments

Comments
 (0)