Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/graphql/execution/FetchedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public FetchedValue transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public String toString() {
return "FetchedValue{" +
"fetchedValue=" + fetchedValue +
", rawFetchedValue=" + rawFetchedValue +
", localContext=" + localContext +
", errors=" + errors +
'}';
}

public static Builder newFetchedValue() {
return new Builder();
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/graphql/execution/nextgen/FetchedValueAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ public String getResultKey() {
return executionStepInfo.getResultKey();
}

@Override
public String toString() {
return "{" +
"valueType=" + valueType +
", completedValue=" + completedValue +
", errors=" + errors +
", children=" + children +
", stepInfo=" + executionStepInfo +
", nullValue=" + nullValue +
", resolvedType=" + resolvedType +
", fetchedValue=" + fetchedValue +
'}';
}

public static final class Builder {
private FetchedValueType valueType;
private final List<GraphQLError> errors = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,15 @@ public Optional<NonNullableFieldWasNullException> getChildNonNullableException()
* @return a new ExecutionResultNode with the new errors
*/
public abstract ExecutionResultNode withNewErrors(List<GraphQLError> errors);


@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"fva=" + fetchedValueAnalysis +
", children=" + children +
", errors=" + errors +
", nonNullableEx=" + nonNullableFieldWasNullException +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package graphql.execution.nextgen.result;

import graphql.Assert;
import graphql.PublicApi;
import graphql.util.NodeAdapter;
import graphql.util.NodeLocation;
Expand All @@ -9,6 +8,9 @@
import java.util.List;
import java.util.Map;

import static graphql.Assert.assertNotNull;
import static graphql.Assert.assertTrue;

@PublicApi
public class ResultNodeAdapter implements NodeAdapter<ExecutionResultNode> {

Expand All @@ -19,22 +21,26 @@ private ResultNodeAdapter() {
}

@Override
public Map<String, List<ExecutionResultNode>> getNamedChildren(ExecutionResultNode node) {
public Map<String, List<ExecutionResultNode>> getNamedChildren(ExecutionResultNode parentNode) {
Map<String, List<ExecutionResultNode>> result = new LinkedHashMap<>();
result.put(null, node.getChildren());
result.put(null, parentNode.getChildren());
return result;
}

@Override
public ExecutionResultNode withNewChildren(ExecutionResultNode node, Map<String, List<ExecutionResultNode>> newChildren) {
Assert.assertTrue(newChildren.size() == 1);
public ExecutionResultNode withNewChildren(ExecutionResultNode parentNode, Map<String, List<ExecutionResultNode>> newChildren) {
assertTrue(newChildren.size() == 1);
List<ExecutionResultNode> childrenList = newChildren.get(null);
Assert.assertNotNull(childrenList);
return node.withNewChildren(childrenList);
assertNotNull(childrenList);
return parentNode.withNewChildren(childrenList);
}

@Override
public ExecutionResultNode removeChild(ExecutionResultNode node, NodeLocation location) {
throw new UnsupportedOperationException();
public ExecutionResultNode removeChild(ExecutionResultNode parentNode, NodeLocation location) {
int index = location.getIndex();
List<ExecutionResultNode> childrenList = parentNode.getChildren();
assertTrue(index >= 0 && index < childrenList.size(), "The remove index MUST be within the range of the children");
childrenList.remove(index);
return parentNode.withNewChildren(childrenList);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
package graphql.execution.nextgen.result

import graphql.Scalars
import graphql.execution.nextgen.FetchedValueAnalysis

import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import static graphql.GraphqlErrorBuilder.newError
import static graphql.execution.ExecutionStepInfo.newExecutionStepInfo
import static graphql.execution.FetchedValue.newFetchedValue
import static graphql.execution.nextgen.FetchedValueAnalysis.FetchedValueType.SCALAR
import static graphql.execution.nextgen.FetchedValueAnalysis.newFetchedValueAnalysis
import static graphql.execution.nextgen.result.ExecutionResultNodeTestUtils.fvaForValue

class ExecutionResultNodeTest extends Specification {

@Shared
def startingErrors = [newError().message("Starting").build()]

@Shared
def startingFetchValueAnalysis = fetchedValueAnalysis("Starting")
def startingFetchValueAnalysis = fvaForValue("Starting")

@Shared
def startingChildren = [new LeafExecutionResultNode(startingFetchValueAnalysis, null)]

static FetchedValueAnalysis fetchedValueAnalysis(String value) {
def executionStepInfo = newExecutionStepInfo().type(Scalars.GraphQLString).build()
def fetchedValue = newFetchedValue()
.fetchedValue(value)
.rawFetchedValue(value).build()
newFetchedValueAnalysis()
.executionStepInfo(executionStepInfo)
.valueType(SCALAR)
.fetchedValue(fetchedValue)
.completedValue(value)
.build()
}

@Unroll
def "construction of objects with new errors works"() {

Expand All @@ -61,7 +44,7 @@ class ExecutionResultNodeTest extends Specification {
def "construction of objects with new fetched value analysis works"() {

given:
def newFetchValueAnalysis = fetchedValueAnalysis("hi")
def newFetchValueAnalysis = fvaForValue("hi")

expect:
ExecutionResultNode nodeUnderTest = node
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package graphql.execution.nextgen.result

import graphql.Scalars
import graphql.execution.nextgen.FetchedValueAnalysis

import static graphql.execution.ExecutionStepInfo.newExecutionStepInfo
import static graphql.execution.FetchedValue.newFetchedValue
import static graphql.execution.nextgen.FetchedValueAnalysis.FetchedValueType.SCALAR
import static graphql.execution.nextgen.FetchedValueAnalysis.newFetchedValueAnalysis

class ExecutionResultNodeTestUtils {

static FetchedValueAnalysis fvaForValue(Object value) {
def executionStepInfo = newExecutionStepInfo().type(Scalars.GraphQLString).build()
def fetchedValue = newFetchedValue()
.fetchedValue(value)
.rawFetchedValue(value).build()
newFetchedValueAnalysis()
.executionStepInfo(executionStepInfo)
.valueType(SCALAR)
.fetchedValue(fetchedValue)
.completedValue(value)
.build()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package graphql.execution.nextgen.result

import graphql.AssertException
import graphql.util.NodeLocation
import spock.lang.Specification

import static graphql.execution.nextgen.result.ExecutionResultNodeTestUtils.fvaForValue

class ResultNodeAdapterTest extends Specification {

def parentNode = new ObjectExecutionResultNode(null, [
new LeafExecutionResultNode(fvaForValue("v1"), null),
new LeafExecutionResultNode(fvaForValue("v2"), null),
new LeafExecutionResultNode(fvaForValue("v3"), null),
])

def "can remove a child from a node"() {
when:
ResultNodeAdapter.RESULT_NODE_ADAPTER.removeChild(parentNode, new NodeLocation(null, -1))
then:
thrown(AssertException)

when:
ResultNodeAdapter.RESULT_NODE_ADAPTER.removeChild(parentNode, new NodeLocation(null, -3))
then:
thrown(AssertException)

when:
def newNode = ResultNodeAdapter.RESULT_NODE_ADAPTER.removeChild(parentNode, new NodeLocation(null, 1))
then:
newNode.children.size() == 2
newNode.children[0].getFetchedValueAnalysis().getCompletedValue() == "v1"
newNode.children[1].getFetchedValueAnalysis().getCompletedValue() == "v3"
}
}