Skip to content

Commit a35079e

Browse files
andimarekbbakerman
authored andcommitted
add errors to the root ERN
1 parent cdd0cbc commit a35079e

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@
3232
@Internal
3333
public class ResultNodesUtil {
3434

35-
public static ExecutionResult toExecutionResult(ExecutionResultNode root) {
35+
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());
3740
return ExecutionResultImpl.newExecutionResult()
3841
.data(executionResultData.data)
39-
.errors(executionResultData.errors)
42+
.errors(allErrors)
4043
.build();
4144
}
4245

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
package graphql.execution.nextgen.result;
22

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

6+
import java.util.ArrayList;
7+
import java.util.Collections;
58
import java.util.List;
69

710
public class RootExecutionResultNode extends ObjectExecutionResultNode {
811

12+
private final List<GraphQLError> errors;
13+
14+
public RootExecutionResultNode(List<ExecutionResultNode> children, List<GraphQLError> errors) {
15+
super(null, children);
16+
this.errors = new ArrayList<>(errors);
17+
}
18+
919
public RootExecutionResultNode(List<ExecutionResultNode> children) {
1020
super(null, children);
21+
this.errors = Collections.emptyList();
1122
}
1223

1324
@Override
@@ -19,4 +30,8 @@ public FetchedValueAnalysis getFetchedValueAnalysis() {
1930
public ObjectExecutionResultNode withNewChildren(List<ExecutionResultNode> children) {
2031
return new RootExecutionResultNode(children);
2132
}
33+
34+
public List<GraphQLError> getErrors() {
35+
return new ArrayList<>(errors);
36+
}
2237
}

src/test/groovy/graphql/execution/nextgen/DefaultExecutionStrategyTest.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@ import static graphql.execution.DataFetcherResult.newResult
1414

1515
class DefaultExecutionStrategyTest extends Specification {
1616

17+
def "test simple execution with one scalar field"() {
18+
def fooData = "hello"
19+
def dataFetchers = [
20+
Query: [foo: { env -> fooData } as DataFetcher]
21+
]
22+
def schema = schema("""
23+
type Query {
24+
foo: String
25+
}
26+
""", dataFetchers)
27+
28+
29+
def query = """
30+
{foo}
31+
"""
32+
33+
34+
when:
35+
def graphQL = GraphQL.newGraphQL(schema).executionStrategy(new DefaultExecutionStrategy()).build()
36+
def result = graphQL.execute(newExecutionInput().query(query))
37+
38+
then:
39+
result.getData() == [foo: fooData]
40+
41+
}
1742

1843
def "test simple execution"() {
1944
def fooData = [id: "fooId", bar: [id: "barId", name: "someBar"]]
@@ -376,6 +401,7 @@ class DefaultExecutionStrategyTest extends Specification {
376401

377402
then:
378403
result.getData() == null
404+
result.getErrors().size() > 0
379405
}
380406

381407
def "test list"() {

0 commit comments

Comments
 (0)