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

add a default max nodes count for the ExecutableNormalizedFactory #3547

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import static graphql.util.FpKit.filterSet;
import static graphql.util.FpKit.groupingBy;
import static graphql.util.FpKit.intersection;
import static java.util.Collections.max;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toCollection;
Expand Down Expand Up @@ -102,7 +101,7 @@ public static Options defaultOptions() {
GraphQLContext.getDefault(),
Locale.getDefault(),
Integer.MAX_VALUE,
Integer.MAX_VALUE,
100_000,
Copy link
Member

Choose a reason for hiding this comment

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

We should have a JVM static way of getting / setting this default - like we do in other places

See graphql.parser.ParserOptions#MAX_WHITESPACE_TOKENS for inspiration

false);
}

Expand Down Expand Up @@ -470,7 +469,7 @@ private ExecutableNormalizedOperation createNormalizedQueryImpl() {
topLevel,
fieldAndAstParents,
1);
maxDepthSeen = Math.max(maxDepthSeen,depthSeen);
maxDepthSeen = Math.max(maxDepthSeen, depthSeen);
}
// getPossibleMergerList
for (PossibleMerger possibleMerger : possibleMergerList) {
Expand Down Expand Up @@ -498,8 +497,8 @@ private void captureMergedField(ExecutableNormalizedField enf, MergedField merge
}

private int buildFieldWithChildren(ExecutableNormalizedField executableNormalizedField,
ImmutableList<FieldAndAstParent> fieldAndAstParents,
int curLevel) {
ImmutableList<FieldAndAstParent> fieldAndAstParents,
int curLevel) {
checkMaxDepthExceeded(curLevel);

CollectNFResult nextLevel = collectFromMergedField(executableNormalizedField, fieldAndAstParents, curLevel + 1);
Expand All @@ -518,7 +517,7 @@ private int buildFieldWithChildren(ExecutableNormalizedField executableNormalize
int depthSeen = buildFieldWithChildren(childENF,
childFieldAndAstParents,
curLevel + 1);
maxDepthSeen = Math.max(maxDepthSeen,depthSeen);
maxDepthSeen = Math.max(maxDepthSeen, depthSeen);

checkMaxDepthExceeded(maxDepthSeen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3099,13 +3099,59 @@ fragment personName on Person {
document,
null,
RawVariables.emptyVariables()
)
)

then:
result.getOperationDepth() == 7
result.getOperationFieldCount() == 8
}

def "factory has a default max node count"() {
String schema = """
type Query {
foo: Foo
}
type Foo {
foo: Foo
name: String
}
"""

GraphQLSchema graphQLSchema = TestUtil.schema(schema)

String query = "{ foo { ...F1}} "
int fragmentCount = 12
for (int i = 1; i < fragmentCount; i++) {
query += """
fragment F$i on Foo {
foo { ...F${i + 1} }
a: foo{ ...F${i + 1} }
b: foo{ ...F${i + 1} }
}
"""
}
query += """
fragment F$fragmentCount on Foo{
name
}
"""

assertValidQuery(graphQLSchema, query)

Document document = TestUtil.parseQuery(query)

when:
def result = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperationWithRawVariables(
graphQLSchema,
document,
null,
RawVariables.emptyVariables()
)
then:
def e = thrown(AbortExecutionException)
e.message == "Maximum field count exceeded. 100001 > 100000"
}

private static ExecutableNormalizedOperation localCreateExecutableNormalizedOperation(
GraphQLSchema graphQLSchema,
Document document,
Expand Down