From 2354116f4c0b0cec1abe0aa2b0a5dbfa2895eeda Mon Sep 17 00:00:00 2001 From: Wil Asche Date: Tue, 14 May 2019 00:56:23 -0400 Subject: [PATCH] fixes #1524 (#1525) * fixes #1524 * fixes #1524 --- .../java/graphql/execution/ExecutionContext.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/graphql/execution/ExecutionContext.java b/src/main/java/graphql/execution/ExecutionContext.java index 0d04038f8e..ec6d00ebfb 100644 --- a/src/main/java/graphql/execution/ExecutionContext.java +++ b/src/main/java/graphql/execution/ExecutionContext.java @@ -12,8 +12,10 @@ import graphql.schema.GraphQLSchema; 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; @@ -35,6 +37,7 @@ public class ExecutionContext { private final Object context; private final Instrumentation instrumentation; private final List errors = new CopyOnWriteArrayList<>(); + private final Set errorPaths = new HashSet<>(); private final DeferSupport deferSupport = new DeferSupport(); public ExecutionContext(Instrumentation instrumentation, ExecutionId executionId, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionStrategy subscriptionStrategy, Map fragmentsByName, Document document, OperationDefinition operationDefinition, Map variables, Object context, Object root) { @@ -116,13 +119,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 path = graphQLError.getPath(); - if (path != null) { - if (fieldPath.equals(ExecutionPath.fromList(path))) { - return; - } - } + if (!errorPaths.add(fieldPath)) { + return; } this.errors.add(error); } @@ -137,6 +135,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); }