File tree Expand file tree Collapse file tree
main/java/graphql/execution/nextgen/result
test/groovy/graphql/execution/nextgen Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232@ Internal
3333public 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
Original file line number Diff line number Diff line change 11package graphql .execution .nextgen .result ;
22
3+ import graphql .GraphQLError ;
34import graphql .execution .nextgen .FetchedValueAnalysis ;
45
6+ import java .util .ArrayList ;
7+ import java .util .Collections ;
58import java .util .List ;
69
710public 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}
Original file line number Diff line number Diff line change @@ -14,6 +14,31 @@ import static graphql.execution.DataFetcherResult.newResult
1414
1515class 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" () {
You can’t perform that action at this time.
0 commit comments