Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of the ofType introspection depth #4317

Open
wants to merge 4 commits into
base: 16.x.x
Choose a base branch
from
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 @@
* 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.
Nols1000 marked this conversation as resolved.
Show resolved Hide resolved
*
* Default: 9
*/
typeDepth?: number;
}

/**
Expand All @@ -52,6 +61,7 @@
schemaDescription: false,
inputValueDeprecation: false,
oneOf: false,
typeDepth: 9,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this default is a breaking change. If we want this to land in v16 then we should do Infinity and in v17 we can restrict the limits.

Copy link
Author

@Nols1000 Nols1000 Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that a breaking change? The behaviour is exactly the same as before. Infinity would lead to an infinite recursive loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saihaj I think you may have misunderstood which depth this relates to - it's the ofType { ofType { ofType { ... } } } depth of the generated query. We couldn't set that to infinity.

...options,
};

Expand All @@ -70,6 +80,19 @@
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.");

Check failure on line 88 in src/utilities/getIntrospectionQuery.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Strings must use singlequote
Nols1000 marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 89 in src/utilities/getIntrospectionQuery.ts

View check run for this annotation

Codecov / codecov/patch

src/utilities/getIntrospectionQuery.ts#L88-L89

Added lines #L88 - L89 were not covered by tests
return `
${indent}ofType {
${indent} name
${indent} kind${ofType(level - 1, indent + " ")}

Check failure on line 93 in src/utilities/getIntrospectionQuery.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Strings must use singlequote
Nols1000 marked this conversation as resolved.
Show resolved Hide resolved
${indent}}`;
}

return `
query IntrospectionQuery {
Expand Down Expand Up @@ -139,43 +162,7 @@

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, " ")}

Check failure on line 165 in src/utilities/getIntrospectionQuery.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Strings must use singlequote
Nols1000 marked this conversation as resolved.
Show resolved Hide resolved
}
`;
}
Expand Down
Loading