graphql.execution2.result.ObjectExecutionResultNode Maven / Gradle / Ivy
package graphql.execution2.result;
import graphql.Internal;
import graphql.execution.NonNullableFieldWasNullException;
import graphql.execution2.FetchedValueAnalysis;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Internal
public class ObjectExecutionResultNode extends ExecutionResultNode {
private Map children;
public ObjectExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
Map children) {
super(fetchedValueAnalysis, ResultNodesUtil.newNullableException(fetchedValueAnalysis, children.values()));
this.children = children;
}
public ObjectExecutionResultNode(FetchedValueAnalysis fetchedValueAnalysis,
List children) {
super(fetchedValueAnalysis, ResultNodesUtil.newNullableException(fetchedValueAnalysis, children));
this.children = ResultNodesUtil.namedNodesToMap(children);
}
@Override
public List getChildren() {
return new ArrayList<>(children.values());
}
@Override
public ExecutionResultNode withChild(ExecutionResultNode child, ExecutionResultNodePosition position) {
LinkedHashMap newChildren = new LinkedHashMap<>(this.children);
newChildren.put(position.getKey(), child);
return new ObjectExecutionResultNode(getFetchedValueAnalysis(), newChildren);
}
@Override
public ExecutionResultNode withNewChildren(Map children) {
LinkedHashMap mergedChildren = new LinkedHashMap<>(this.children);
children.entrySet().stream().forEach(entry -> mergedChildren.put(entry.getKey().getKey(), entry.getValue()));
return new ObjectExecutionResultNode(getFetchedValueAnalysis(), mergedChildren);
}
public Map getChildrenMap() {
return new LinkedHashMap<>(children);
}
public Optional getChildrenNonNullableException() {
return children.values().stream()
.filter(executionResultNode -> executionResultNode.getNonNullableFieldWasNullException() != null)
.map(ExecutionResultNode::getNonNullableFieldWasNullException)
.findFirst();
}
public ObjectExecutionResultNode withChildren(Map children) {
return new ObjectExecutionResultNode(getFetchedValueAnalysis(), children);
}
public static class UnresolvedObjectResultNode extends ObjectExecutionResultNode {
public UnresolvedObjectResultNode(FetchedValueAnalysis fetchedValueAnalysis) {
super(fetchedValueAnalysis, Collections.emptyMap());
}
@Override
public String toString() {
return "UnresolvedObjectResultNode{" +
"fetchedValueAnalysis=" + getFetchedValueAnalysis() +
'}';
}
}
public static class RootExecutionResultNode extends ObjectExecutionResultNode {
public RootExecutionResultNode(Map children) {
super(null, children);
}
public RootExecutionResultNode(List children) {
super(null, children);
}
@Override
public FetchedValueAnalysis getFetchedValueAnalysis() {
throw new RuntimeException("Root node");
}
@Override
public ExecutionResultNode withNewChildren(Map children) {
LinkedHashMap mergedChildren = new LinkedHashMap<>(getChildrenMap());
children.entrySet().stream().forEach(entry -> mergedChildren.put(entry.getKey().getKey(), entry.getValue()));
return new ObjectExecutionResultNode.RootExecutionResultNode(mergedChildren);
}
@Override
public ExecutionResultNode withChild(ExecutionResultNode child, ExecutionResultNodePosition position) {
LinkedHashMap newChildren = new LinkedHashMap<>(getChildrenMap());
newChildren.put(position.getKey(), child);
return new ObjectExecutionResultNode.RootExecutionResultNode(newChildren);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy