1212
1313import java .util .ArrayList ;
1414import java .util .Collections ;
15- import java .util .LinkedHashMap ;
1615import java .util .List ;
1716import java .util .Map ;
1817import java .util .function .Consumer ;
@@ -33,14 +32,13 @@ public class ExecutionContext {
3332 private final Object root ;
3433 private final Object context ;
3534 private final Instrumentation instrumentation ;
36- private final Map <String , GraphQLError > perFieldErrors = new LinkedHashMap <>();
37- private final List <GraphQLError > otherErrors = new ArrayList <>();
35+ private final List <GraphQLError > errors = new ArrayList <>();
3836
3937 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 ) {
40- this (instrumentation , executionId , graphQLSchema , instrumentationState , queryStrategy , mutationStrategy , subscriptionStrategy , fragmentsByName , document , operationDefinition , variables , context , root , Collections .emptyMap (), Collections . emptyList ());
38+ this (instrumentation , executionId , graphQLSchema , instrumentationState , queryStrategy , mutationStrategy , subscriptionStrategy , fragmentsByName , document , operationDefinition , variables , context , root , Collections .emptyList ());
4139 }
4240
43- 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 , Map < String , GraphQLError > startingFieldErrors , List <GraphQLError > startingErrors ) {
41+ 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 , List <GraphQLError > startingErrors ) {
4442 this .graphQLSchema = graphQLSchema ;
4543 this .executionId = executionId ;
4644 this .instrumentationState = instrumentationState ;
@@ -54,8 +52,7 @@ public ExecutionContext(Instrumentation instrumentation, ExecutionId executionId
5452 this .context = context ;
5553 this .root = root ;
5654 this .instrumentation = instrumentation ;
57- this .perFieldErrors .putAll (startingFieldErrors );
58- this .otherErrors .addAll (startingErrors );
55+ this .errors .addAll (startingErrors );
5956 }
6057
6158
@@ -111,13 +108,21 @@ public FragmentDefinition getFragment(String name) {
111108 * @param fieldPath the field path to put it under
112109 */
113110 public void addError (GraphQLError error , ExecutionPath fieldPath ) {
111+ //
114112 // see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability about how per
115- // field errors should be handled - ie only once per field
113+ // field errors should be handled - ie only once per field if its already there for nullability
114+ // but unclear if its not that error path
115+ //
116116 synchronized (this ) {
117- String key = fieldPath .toString ();
118- if (!perFieldErrors .containsKey (key )) {
119- this .perFieldErrors .put (key , error );
117+ for (GraphQLError graphQLError : errors ) {
118+ List <Object > path = graphQLError .getPath ();
119+ if (path != null ) {
120+ if (fieldPath .equals (ExecutionPath .fromList (path ))) {
121+ return ;
122+ }
123+ }
120124 }
125+ this .errors .add (error );
121126 }
122127 }
123128
@@ -129,36 +134,19 @@ public void addError(GraphQLError error, ExecutionPath fieldPath) {
129134 */
130135 public void addError (GraphQLError error ) {
131136 // see https://github.com/graphql-java/graphql-java/issues/888 on how the spec is unclear
132- // on how multiple errors should be handled - ie only once per field or not outside nullability
137+ // on how exactly multiple errors should be handled - ie only once per field or not outside the nullability
138+ // aspect.
133139 synchronized (this ) {
134- this .otherErrors .add (error );
140+ this .errors .add (error );
135141 }
136142 }
137143
138- // access for builder only
139- Map <String , GraphQLError > getPerFieldErrorMap () {
140- synchronized (this ) {
141- return perFieldErrors ;
142- }
143- }
144-
145- // access for builder only
146- List <GraphQLError > getOtherErrors () {
147- synchronized (this ) {
148- return otherErrors ;
149- }
150- }
151-
152-
153144 /**
154145 * @return the total list of errors for this execution context
155146 */
156147 public List <GraphQLError > getErrors () {
157148 synchronized (this ) {
158- ArrayList <GraphQLError > errList = new ArrayList <>();
159- errList .addAll (perFieldErrors .values ());
160- errList .addAll (otherErrors );
161- return errList ;
149+ return Collections .unmodifiableList (errors );
162150 }
163151 }
164152
0 commit comments