Skip to content

Commit 25c8232

Browse files
waschebbakerman
authored andcommitted
1 parent 55f1989 commit 25c8232

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/main/java/graphql/execution/ExecutionContext.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import graphql.schema.GraphQLSchema;
1313

1414
import java.util.Collections;
15+
import java.util.HashSet;
1516
import java.util.List;
1617
import java.util.Map;
18+
import java.util.Set;
1719
import java.util.concurrent.CopyOnWriteArrayList;
1820
import java.util.function.Consumer;
1921

@@ -35,6 +37,7 @@ public class ExecutionContext {
3537
private final Object context;
3638
private final Instrumentation instrumentation;
3739
private final List<GraphQLError> errors = new CopyOnWriteArrayList<>();
40+
private final Set<ExecutionPath> errorPaths = new HashSet<>();
3841
private final DeferSupport deferSupport = new DeferSupport();
3942

4043
public ExecutionContext(Instrumentation instrumentation, ExecutionId executionId, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionStrategy subscriptionStrategy, Map<String, FragmentDefinition> fragmentsByName, Document document, OperationDefinition operationDefinition, Map<String, Object> variables, Object context, Object root) {
@@ -116,13 +119,8 @@ public void addError(GraphQLError error, ExecutionPath fieldPath) {
116119
// field errors should be handled - ie only once per field if its already there for nullability
117120
// but unclear if its not that error path
118121
//
119-
for (GraphQLError graphQLError : errors) {
120-
List<Object> path = graphQLError.getPath();
121-
if (path != null) {
122-
if (fieldPath.equals(ExecutionPath.fromList(path))) {
123-
return;
124-
}
125-
}
122+
if (!errorPaths.add(fieldPath)) {
123+
return;
126124
}
127125
this.errors.add(error);
128126
}
@@ -137,6 +135,9 @@ public void addError(GraphQLError error) {
137135
// see https://github.com/graphql-java/graphql-java/issues/888 on how the spec is unclear
138136
// on how exactly multiple errors should be handled - ie only once per field or not outside the nullability
139137
// aspect.
138+
if (error.getPath() != null) {
139+
this.errorPaths.add(ExecutionPath.fromList(error.getPath()));
140+
}
140141
this.errors.add(error);
141142
}
142143

0 commit comments

Comments
 (0)