Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 24 additions & 37 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,19 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
return optionsWithDefault.inputValueDeprecation ? str : '';
}
const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
function ofType(level: number, indent: string): string {
if (level <= 0) {
return '';
}
if (level > 100) {
throw new Error("Please set typeDepth to a reasonable value; the default is 9.");
}
return `
${indent}ofType {
${indent} name
${indent} kind${ofType(level - 1, indent + " ")}
${indent}}`;
}

return `
query IntrospectionQuery {
Expand Down Expand Up @@ -139,43 +162,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
}
}
}
}
}
}
}
}
}
name${ofType(optionsWithDefault.typeDepth ?? 9, " ")}
}
`;
}
Expand Down