Skip to content

Commit 31d4cec

Browse files
committed
Added with new error support to result node
1 parent 0759b8d commit 31d4cec

5 files changed

Lines changed: 48 additions & 5 deletions

File tree

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,37 @@ public List<ExecutionResultNode> getChildren() {
5555
return new ArrayList<>(this.children);
5656
}
5757

58-
public abstract ExecutionResultNode withNewChildren(List<ExecutionResultNode> children);
59-
60-
public abstract ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis);
61-
6258
public Optional<NonNullableFieldWasNullException> getChildNonNullableException() {
6359
return children.stream()
6460
.filter(executionResultNode -> executionResultNode.getNonNullableFieldWasNullException() != null)
6561
.map(ExecutionResultNode::getNonNullableFieldWasNullException)
6662
.findFirst();
6763
}
6864

65+
/**
66+
* Creates a new ExecutionResultNode of the same specific type with the new set of result children
67+
*
68+
* @param children the new children for this result node
69+
*
70+
* @return a new ExecutionResultNode with the new result children
71+
*/
72+
public abstract ExecutionResultNode withNewChildren(List<ExecutionResultNode> children);
73+
74+
/**
75+
* Creates a new ExecutionResultNode of the same specific type with the new {@link graphql.execution.nextgen.FetchedValueAnalysis}
76+
*
77+
* @param fetchedValueAnalysis the {@link graphql.execution.nextgen.FetchedValueAnalysis} for this result node
78+
*
79+
* @return a new ExecutionResultNode with the new {@link graphql.execution.nextgen.FetchedValueAnalysis}
80+
*/
81+
public abstract ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis);
6982

83+
/**
84+
* Creates a new ExecutionResultNode of the same specific type with the new error collection
85+
*
86+
* @param errors the new errors for this result node
87+
*
88+
* @return a new ExecutionResultNode with the new errors
89+
*/
90+
public abstract ExecutionResultNode withNewErrors(List<GraphQLError> errors);
7091
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import graphql.execution.NonNullableFieldWasNullException;
77
import graphql.execution.nextgen.FetchedValueAnalysis;
88

9+
import java.util.ArrayList;
910
import java.util.Collections;
1011
import java.util.List;
1112

@@ -37,4 +38,9 @@ public ExecutionResultNode withNewChildren(List<ExecutionResultNode> children) {
3738
public ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis) {
3839
return new LeafExecutionResultNode(fetchedValueAnalysis, getNonNullableFieldWasNullException(), getErrors());
3940
}
41+
42+
@Override
43+
public ExecutionResultNode withNewErrors(List<GraphQLError> errors) {
44+
return new LeafExecutionResultNode(getFetchedValueAnalysis(), getNonNullableFieldWasNullException(), new ArrayList<>(errors));
45+
}
4046
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import graphql.Internal;
55
import graphql.execution.nextgen.FetchedValueAnalysis;
66

7+
import java.util.ArrayList;
78
import java.util.Collections;
89
import java.util.List;
910

@@ -31,4 +32,9 @@ public ExecutionResultNode withNewChildren(List<ExecutionResultNode> children) {
3132
public ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis) {
3233
return new ListExecutionResultNode(fetchedValueAnalysis, getChildren(), getErrors());
3334
}
35+
36+
@Override
37+
public ExecutionResultNode withNewErrors(List<GraphQLError> errors) {
38+
return new ListExecutionResultNode(getFetchedValueAnalysis(), getChildren(), new ArrayList<>(errors));
39+
}
3440
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import graphql.Internal;
55
import graphql.execution.nextgen.FetchedValueAnalysis;
66

7+
import java.util.ArrayList;
78
import java.util.Collections;
89
import java.util.List;
910

@@ -33,4 +34,9 @@ public ObjectExecutionResultNode withNewChildren(List<ExecutionResultNode> child
3334
public ExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis fetchedValueAnalysis) {
3435
return new ObjectExecutionResultNode(fetchedValueAnalysis, getChildren(), getErrors());
3536
}
37+
38+
@Override
39+
public ExecutionResultNode withNewErrors(List<GraphQLError> errors) {
40+
return new ObjectExecutionResultNode(getFetchedValueAnalysis(), getChildren(), new ArrayList<>(errors));
41+
}
3642
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import graphql.GraphQLError;
44
import graphql.execution.nextgen.FetchedValueAnalysis;
55

6+
import java.util.ArrayList;
67
import java.util.Collections;
78
import java.util.List;
89

@@ -35,5 +36,8 @@ public RootExecutionResultNode withNewFetchedValueAnalysis(FetchedValueAnalysis
3536
return assertShouldNeverHappen("not supported at root node");
3637
}
3738

38-
39+
@Override
40+
public ExecutionResultNode withNewErrors(List<GraphQLError> errors) {
41+
return new RootExecutionResultNode(getChildren(), new ArrayList<>(errors));
42+
}
3943
}

0 commit comments

Comments
 (0)