1515import org .dataloader .DataLoaderRegistry ;
1616
1717import java .util .Collections ;
18+ import java .util .HashSet ;
1819import java .util .List ;
1920import java .util .Map ;
21+ import java .util .Set ;
2022import java .util .concurrent .CopyOnWriteArrayList ;
2123import java .util .function .Consumer ;
2224
@@ -38,6 +40,7 @@ public class ExecutionContext {
3840 private final Object context ;
3941 private final Instrumentation instrumentation ;
4042 private final List <GraphQLError > errors = new CopyOnWriteArrayList <>();
43+ private final Set <ExecutionPath > errorPaths = new HashSet <>();
4144 private final DataLoaderRegistry dataLoaderRegistry ;
4245 private final CacheControl cacheControl ;
4346 private final DeferSupport deferSupport = new DeferSupport ();
@@ -128,13 +131,8 @@ public void addError(GraphQLError error, ExecutionPath fieldPath) {
128131 // field errors should be handled - ie only once per field if its already there for nullability
129132 // but unclear if its not that error path
130133 //
131- for (GraphQLError graphQLError : errors ) {
132- List <Object > path = graphQLError .getPath ();
133- if (path != null ) {
134- if (fieldPath .equals (ExecutionPath .fromList (path ))) {
135- return ;
136- }
137- }
134+ if (!errorPaths .add (fieldPath )) {
135+ return ;
138136 }
139137 this .errors .add (error );
140138 }
@@ -149,6 +147,9 @@ public void addError(GraphQLError error) {
149147 // see https://github.com/graphql-java/graphql-java/issues/888 on how the spec is unclear
150148 // on how exactly multiple errors should be handled - ie only once per field or not outside the nullability
151149 // aspect.
150+ if (error .getPath () != null ) {
151+ this .errorPaths .add (ExecutionPath .fromList (error .getPath ()));
152+ }
152153 this .errors .add (error );
153154 }
154155
0 commit comments