Skip to content

Commit 0759b8d

Browse files
andimarekbbakerman
authored andcommitted
add errors to all ERN
1 parent 10376ba commit 0759b8d

File tree

7 files changed

+56
-33
lines changed

7 files changed

+56
-33
lines changed

src/main/java/graphql/execution/nextgen/result/ExecutionResultNode.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package graphql.execution.nextgen.result;
22

33
import graphql.Assert;
4+
import graphql.GraphQLError;
45
import graphql.Internal;
56
import graphql.execution.MergedField;
67
import graphql.execution.NonNullableFieldWasNullException;
@@ -18,16 +19,22 @@ public abstract class ExecutionResultNode {
1819
private final FetchedValueAnalysis fetchedValueAnalysis;
1920
private final NonNullableFieldWasNullException nonNullableFieldWasNullException;
2021
private final List<ExecutionResultNode> children;
22+
private final List<GraphQLError> errors;
2123

2224
protected ExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
2325
NonNullableFieldWasNullException nonNullableFieldWasNullException,
24-
List<ExecutionResultNode> children) {
26+
List<ExecutionResultNode> children,
27+
List<GraphQLError> errors) {
2528
this.fetchedValueAnalysis = fetchedValueAnalysis;
2629
this.nonNullableFieldWasNullException = nonNullableFieldWasNullException;
2730
this.children = assertNotNull(children);
2831
children.forEach(Assert::assertNotNull);
32+
this.errors = new ArrayList<>(errors);
2933
}
3034

35+
public List<GraphQLError> getErrors() {
36+
return new ArrayList<>(errors);
37+
}
3138

3239
/*
3340
* can be null for the RootExecutionResultNode

src/main/java/graphql/execution/nextgen/result/LeafExecutionResultNode.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package graphql.execution.nextgen.result;
22

33
import graphql.Assert;
4+
import graphql.GraphQLError;
45
import graphql.Internal;
56
import graphql.execution.NonNullableFieldWasNullException;
67
import graphql.execution.nextgen.FetchedValueAnalysis;
@@ -13,7 +14,13 @@ public class LeafExecutionResultNode extends ExecutionResultNode {
1314

1415
public LeafExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
1516
NonNullableFieldWasNullException nonNullableFieldWasNullException) {
16-
super(fetchedValueAnalysis, nonNullableFieldWasNullException, Collections.emptyList());
17+
this(fetchedValueAnalysis, nonNullableFieldWasNullException, Collections.emptyList());
18+
}
19+
20+
public LeafExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
21+
NonNullableFieldWasNullException nonNullableFieldWasNullException,
22+
List<GraphQLError> errors) {
23+
super(fetchedValueAnalysis, nonNullableFieldWasNullException, Collections.emptyList(), errors);
1724
}
1825

1926

@@ -28,6 +35,6 @@ public ExecutionResultNode withNewChildren(List<ExecutionResultNode> children) {
2835

2936
@Override
3037
public ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis) {
31-
return new LeafExecutionResultNode(fetchedValueAnalysis, getNonNullableFieldWasNullException());
38+
return new LeafExecutionResultNode(fetchedValueAnalysis, getNonNullableFieldWasNullException(), getErrors());
3239
}
3340
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
package graphql.execution.nextgen.result;
22

3+
import graphql.GraphQLError;
34
import graphql.Internal;
45
import graphql.execution.nextgen.FetchedValueAnalysis;
56

7+
import java.util.Collections;
68
import java.util.List;
79

810
@Internal
911
public class ListExecutionResultNode extends ExecutionResultNode {
1012

11-
1213
public ListExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
1314
List<ExecutionResultNode> children) {
14-
super(fetchedValueAnalysis, ResultNodesUtil.newNullableException(fetchedValueAnalysis, children), children);
15+
this(fetchedValueAnalysis, children, Collections.emptyList());
16+
17+
}
18+
19+
public ListExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
20+
List<ExecutionResultNode> children,
21+
List<GraphQLError> errors) {
22+
super(fetchedValueAnalysis, ResultNodesUtil.newNullableException(fetchedValueAnalysis, children), children, errors);
1523
}
1624

1725
@Override
1826
public ExecutionResultNode withNewChildren(List<ExecutionResultNode> children) {
19-
return new ListExecutionResultNode(getFetchedValueAnalysis(), children);
27+
return new ListExecutionResultNode(getFetchedValueAnalysis(), children, getErrors());
2028
}
2129

2230
@Override
2331
public ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis) {
24-
return new ListExecutionResultNode(fetchedValueAnalysis, getChildren());
32+
return new ListExecutionResultNode(fetchedValueAnalysis, getChildren(), getErrors());
2533
}
2634
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package graphql.execution.nextgen.result;
22

3+
import graphql.GraphQLError;
34
import graphql.Internal;
45
import graphql.execution.nextgen.FetchedValueAnalysis;
56

7+
import java.util.Collections;
68
import java.util.List;
79

810
@Internal
@@ -11,17 +13,24 @@ public class ObjectExecutionResultNode extends ExecutionResultNode {
1113

1214
public ObjectExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
1315
List<ExecutionResultNode> children) {
14-
super(fetchedValueAnalysis, ResultNodesUtil.newNullableException(fetchedValueAnalysis, children), children);
16+
this(fetchedValueAnalysis, children, Collections.emptyList());
17+
18+
}
19+
20+
public ObjectExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
21+
List<ExecutionResultNode> children,
22+
List<GraphQLError> errors) {
23+
super(fetchedValueAnalysis, ResultNodesUtil.newNullableException(fetchedValueAnalysis, children), children, errors);
1524
}
1625

1726

1827
@Override
1928
public ObjectExecutionResultNode withNewChildren(List<ExecutionResultNode> children) {
20-
return new ObjectExecutionResultNode(getFetchedValueAnalysis(), children);
29+
return new ObjectExecutionResultNode(getFetchedValueAnalysis(), children, getErrors());
2130
}
2231

2332
@Override
2433
public ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis) {
25-
return new ObjectExecutionResultNode(fetchedValueAnalysis, getChildren());
34+
return new ObjectExecutionResultNode(fetchedValueAnalysis, getChildren(), getErrors());
2635
}
2736
}

src/main/java/graphql/execution/nextgen/result/ResultNodesUtil.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,17 @@ public class ResultNodesUtil {
3434

3535
public static ExecutionResult toExecutionResult(RootExecutionResultNode root) {
3636
ExecutionResultData executionResultData = toDataImpl(root);
37-
List<GraphQLError> allErrors = new ArrayList<>();
38-
allErrors.addAll(executionResultData.errors);
39-
allErrors.addAll(root.getErrors());
4037
return ExecutionResultImpl.newExecutionResult()
4138
.data(executionResultData.data)
42-
.errors(allErrors)
39+
.errors(executionResultData.errors)
4340
.build();
4441
}
4542

4643
private static class ExecutionResultData {
4744
Object data;
48-
List<GraphQLError> errors = new ArrayList<>();
45+
List<GraphQLError> errors;
4946

5047

51-
public ExecutionResultData(Object data) {
52-
this.data = data;
53-
}
54-
5548
public ExecutionResultData(Object data, List<GraphQLError> errors) {
5649
this.data = data;
5750
this.errors = errors;
@@ -60,7 +53,10 @@ public ExecutionResultData(Object data, List<GraphQLError> errors) {
6053

6154

6255
private static ExecutionResultData data(Object data, ExecutionResultNode executionResultNode) {
63-
return new ExecutionResultData(data, executionResultNode.getFetchedValueAnalysis().getErrors());
56+
List<GraphQLError> allErrors = new ArrayList<>();
57+
allErrors.addAll(executionResultNode.getFetchedValueAnalysis().getErrors());
58+
allErrors.addAll(executionResultNode.getErrors());
59+
return new ExecutionResultData(data, allErrors);
6460
}
6561

6662
private static ExecutionResultData data(Object data, List<GraphQLError> errors) {
@@ -76,14 +72,15 @@ private static ExecutionResultData toDataImpl(ExecutionResultNode root) {
7672
return root.getFetchedValueAnalysis().isNullValue() ? data(null, root) : data(((LeafExecutionResultNode) root).getValue(), root);
7773
}
7874
if (root instanceof ListExecutionResultNode) {
79-
Optional<NonNullableFieldWasNullException> childNonNullableException = ((ListExecutionResultNode) root).getChildNonNullableException();
75+
Optional<NonNullableFieldWasNullException> childNonNullableException = root.getChildNonNullableException();
8076
if (childNonNullableException.isPresent()) {
8177
return data(null, childNonNullableException.get());
8278
}
8379
List<ExecutionResultData> list = map(root.getChildren(), ResultNodesUtil::toDataImpl);
8480
List<Object> data = map(list, erd -> erd.data);
8581
List<GraphQLError> errors = new ArrayList<>();
8682
list.forEach(erd -> errors.addAll(erd.errors));
83+
errors.addAll(root.getErrors());
8784
return data(data, errors);
8885
}
8986

@@ -92,7 +89,7 @@ private static ExecutionResultData toDataImpl(ExecutionResultNode root) {
9289
return data("Not resolved : " + fetchedValueAnalysis.getExecutionStepInfo().getPath() + " with field " + fetchedValueAnalysis.getField(), emptyList());
9390
}
9491
if (root instanceof ObjectExecutionResultNode) {
95-
Optional<NonNullableFieldWasNullException> childrenNonNullableException = ((ObjectExecutionResultNode) root).getChildNonNullableException();
92+
Optional<NonNullableFieldWasNullException> childrenNonNullableException = root.getChildNonNullableException();
9693
if (childrenNonNullableException.isPresent()) {
9794
return data(null, childrenNonNullableException.get());
9895
}
@@ -103,6 +100,7 @@ private static ExecutionResultData toDataImpl(ExecutionResultNode root) {
103100
resultMap.put(child.getMergedField().getResultKey(), executionResultData.data);
104101
errors.addAll(executionResultData.errors);
105102
});
103+
errors.addAll(root.getErrors());
106104
return data(resultMap, errors);
107105
}
108106
throw new RuntimeException("Unexpected root " + root);

src/main/java/graphql/execution/nextgen/result/RootExecutionResultNode.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,31 @@
33
import graphql.GraphQLError;
44
import graphql.execution.nextgen.FetchedValueAnalysis;
55

6-
import java.util.ArrayList;
76
import java.util.Collections;
87
import java.util.List;
98

109
import static graphql.Assert.assertShouldNeverHappen;
1110

1211
public class RootExecutionResultNode extends ObjectExecutionResultNode {
1312

14-
private final List<GraphQLError> errors;
1513

1614
public RootExecutionResultNode(List<ExecutionResultNode> children, List<GraphQLError> errors) {
17-
super(null, children);
18-
this.errors = new ArrayList<>(errors);
15+
super(null, children, errors);
1916
}
2017

2118
public RootExecutionResultNode(List<ExecutionResultNode> children) {
22-
super(null, children);
23-
this.errors = Collections.emptyList();
19+
super(null, children, Collections.emptyList());
2420
}
2521

22+
2623
@Override
2724
public FetchedValueAnalysis getFetchedValueAnalysis() {
2825
return assertShouldNeverHappen("not supported at root node");
2926
}
3027

3128
@Override
3229
public RootExecutionResultNode withNewChildren(List<ExecutionResultNode> children) {
33-
return new RootExecutionResultNode(children, errors);
30+
return new RootExecutionResultNode(children, getErrors());
3431
}
3532

3633
@Override
@@ -39,7 +36,4 @@ public RootExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis
3936
}
4037

4138

42-
public List<GraphQLError> getErrors() {
43-
return new ArrayList<>(errors);
44-
}
4539
}

src/main/java/graphql/execution/nextgen/result/UnresolvedObjectResultNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class UnresolvedObjectResultNode extends ObjectExecutionResultNode {
88

99
public UnresolvedObjectResultNode(FetchedValueAnalysis fetchedValueAnalysis) {
10-
super(fetchedValueAnalysis, Collections.emptyList());
10+
super(fetchedValueAnalysis, Collections.emptyList(), Collections.emptyList());
1111
}
1212

1313
@Override

0 commit comments

Comments
 (0)