Skip to content

Commit

Permalink
Update getIntrospectionQuery.ts to allow configuration of the type qu…
Browse files Browse the repository at this point in the history
…ery depth

This allows for a better configuration in case the server restricts the maximum query depth.
  • Loading branch information
Nols1000 committed Dec 31, 2024
1 parent 48afd37 commit 388d405
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions src/utilities/getIntrospectionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export interface IntrospectionOptions {
* Default: false
*/
oneOf?: boolean;

/**
* How deep to recurse into nested types. Larger values will result in more
* accurate results, but have a higher load. Some servers might restrict the
* maximum query depth. If thats the case, try decreasing this value.
*
* Default: 9
*/
typeDepth?: number;
}

/**
Expand All @@ -52,6 +61,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
schemaDescription: false,
inputValueDeprecation: false,
oneOf: false,
typeDepth: 9,
...options,
};

Expand All @@ -70,6 +80,17 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
return optionsWithDefault.inputValueDeprecation ? str : '';
}
const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
function ofType(level = 9): string {
if (level <= 0) {
return '';
}
return `
ofType {
name
kind
${ofType(level - 1)}
}`;
}

return `
query IntrospectionQuery {
Expand Down Expand Up @@ -140,42 +161,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
}
${ofType(optionsWithDefault.typeDepth)}
}
`;
}
Expand Down

0 comments on commit 388d405

Please sign in to comment.