Skip to content

Conversation

@dondonz
Copy link
Member

@dondonz dondonz commented Mar 18, 2024

See the original PR #3525 for more details. This backports a max result nodes limit

@dondonz dondonz marked this pull request as ready for review March 18, 2024 04:54
MergedField field = parameters.getField();
GraphQLObjectType parentType = (GraphQLObjectType) parameters.getExecutionStepInfo().getUnwrappedNonNullType();
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, field.getSingleField());
GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry();
Copy link
Member Author

Choose a reason for hiding this comment

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

This line is moved down in this PR

In latest master we added one extra method to break up the logic here. The code registry is used in the method being called here

private final CompletableFuture<ExecutionResult> fieldValue;
private final List<FieldValueInfo> fieldValueInfos;

private FieldValueInfo(CompleteValueType completeValueType, CompletableFuture<ExecutionResult> fieldValue, List<FieldValueInfo> fieldValueInfos) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This has default visibility on current master

private final Object localContext;
private final ImmutableList<GraphQLError> errors;

private FetchedValue(Object fetchedValue, Object rawFetchedValue, ImmutableList<GraphQLError> errors, Object localContext) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This has default visibility on current master

@dondonz dondonz changed the title WIP 21.x backport 3525 max result nodes 21.x backport 3525 max result nodes Mar 19, 2024
if ((maxNodes = executionContext.getGraphQLContext().get(MAX_RESULT_NODES)) != null) {
if (resultNodesCount > maxNodes) {
executionContext.getResultNodesInfo().maxResultNodesExceeded();
return new FieldValueInfo(NULL, completedFuture(ExecutionResult.newExecutionResult().build()), fieldValueInfos);
Copy link
Member Author

@dondonz dondonz Mar 19, 2024

Choose a reason for hiding this comment

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

In master this second argument is completedFuture(null). In this version it MUST be completedFuture(ExecutionResult.newExecutionResult().build())

This is because since 21.x was last released we have made a big change to remove unnecessary ExecutionResult objects. My test hung weirdly because in 21.x land, the engine never expects a null, it expects an ExecutionResult

return CompletableFuture.completedFuture(new FetchedValue(null, null, ImmutableKit.emptyList(), null));
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

The next two lines (variables field and parentType) are not part of max result backport. I have done this to make this method look as close as possible to master

.queryDirectives(queryDirectives)
.build();
});
GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry();
Copy link
Member Author

Choose a reason for hiding this comment

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

Here's where the codeRegistry line got moved to

if ((maxNodes = executionContext.getGraphQLContext().get(MAX_RESULT_NODES)) != null) {
if (resultNodesCount > maxNodes) {
executionContext.getResultNodesInfo().maxResultNodesExceeded();
return CompletableFuture.completedFuture(new FetchedValue(null, null, ImmutableKit.emptyList(), null));
Copy link
Member Author

@dondonz dondonz Mar 19, 2024

Choose a reason for hiding this comment

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

FetchedValue has a slightly different constructor in v21 (compared to master), however this line still means effectively the same thing (return early with null)

@dondonz dondonz added this to the 21.4 milestone Mar 19, 2024
@dondonz dondonz merged commit ddc53be into 21.x Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants