Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 8 additions & 7 deletions src/main/java/graphql/execution/ExecutionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import org.dataloader.DataLoaderRegistry;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

Expand All @@ -38,6 +40,7 @@ public class ExecutionContext {
private final Object context;
private final Instrumentation instrumentation;
private final List<GraphQLError> errors = new CopyOnWriteArrayList<>();
private final Set<ExecutionPath> errorPaths = new HashSet<>();
private final DataLoaderRegistry dataLoaderRegistry;
private final CacheControl cacheControl;
private final DeferSupport deferSupport = new DeferSupport();
Expand Down Expand Up @@ -128,13 +131,8 @@ public void addError(GraphQLError error, ExecutionPath fieldPath) {
// field errors should be handled - ie only once per field if its already there for nullability
// but unclear if its not that error path
//
for (GraphQLError graphQLError : errors) {
List<Object> path = graphQLError.getPath();
if (path != null) {
if (fieldPath.equals(ExecutionPath.fromList(path))) {
return;
}
}
if (!errorPaths.add(fieldPath)) {
return;
}
this.errors.add(error);
}
Expand All @@ -149,6 +147,9 @@ public void addError(GraphQLError error) {
// see https://github.com/graphql-java/graphql-java/issues/888 on how the spec is unclear
// on how exactly multiple errors should be handled - ie only once per field or not outside the nullability
// aspect.
if (error.getPath() != null) {
this.errorPaths.add(ExecutionPath.fromList(error.getPath()));
}
this.errors.add(error);
}

Expand Down
38 changes: 38 additions & 0 deletions src/test/java/benchmark/AddError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package benchmark;

import graphql.execution.ExecutionContext;
import graphql.execution.ExecutionContextBuilder;
import graphql.execution.ExecutionId;
import graphql.execution.ExecutionPath;
import graphql.schema.idl.errors.SchemaMissingError;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;

import java.util.Collections;

@State(Scope.Benchmark)
public class AddError {

private ExecutionContext context = new ExecutionContextBuilder()
.executionId(ExecutionId.generate())
.build();

private volatile int x = 0;

@Benchmark
@BenchmarkMode(Mode.SingleShotTime)
@Warmup(iterations = 1, batchSize = 50000)
@Measurement(iterations = 1, batchSize = 5000)
public ExecutionContext benchMarkAddError() {
context.addError(
new SchemaMissingError(),
ExecutionPath.fromList(Collections.singletonList(x++))
);
return context;
}
}