graphql.execution.nextgen.result.ResultNodesUtil Maven / Gradle / Ivy
package graphql.execution.nextgen.result;
import graphql.Assert;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.GraphQLError;
import graphql.Internal;
import graphql.execution.ExecutionStepInfo;
import graphql.execution.NonNullableFieldWasNullError;
import graphql.execution.NonNullableFieldWasNullException;
import graphql.util.NodeLocation;
import graphql.util.NodeMultiZipper;
import graphql.util.NodeZipper;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;
import graphql.util.TraverserVisitorStub;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static graphql.collect.ImmutableKit.map;
import static graphql.execution.nextgen.result.ResultNodeAdapter.RESULT_NODE_ADAPTER;
import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
/**
* @deprecated Jan 2022 - We have decided to deprecate the NextGen engine, and it will be removed in a future release.
*/
@Deprecated
@Internal
public class ResultNodesUtil {
public static ExecutionResult toExecutionResult(RootExecutionResultNode root) {
ExecutionResultData executionResultData = toDataImpl(root);
return ExecutionResultImpl.newExecutionResult()
.data(executionResultData.data)
.errors(executionResultData.errors)
.build();
}
private static class ExecutionResultData {
Object data;
List errors;
public ExecutionResultData(Object data, List errors) {
this.data = data;
this.errors = errors;
}
}
private static ExecutionResultData data(Object data, ExecutionResultNode executionResultNode) {
List allErrors = new ArrayList<>();
allErrors.addAll(executionResultNode.getResolvedValue().getErrors());
allErrors.addAll(executionResultNode.getErrors());
return new ExecutionResultData(data, allErrors);
}
private static ExecutionResultData data(Object data, List errors) {
return new ExecutionResultData(data, errors);
}
private static ExecutionResultData data(Object data, NonNullableFieldWasNullException exception) {
return new ExecutionResultData(data, Arrays.asList(new NonNullableFieldWasNullError(exception)));
}
private static ExecutionResultData toDataImpl(ExecutionResultNode root) {
if (root instanceof LeafExecutionResultNode) {
return root.getResolvedValue().isNullValue() ? data(null, root) : data(((LeafExecutionResultNode) root).getValue(), root);
}
if (root instanceof ListExecutionResultNode) {
Optional childNonNullableException = root.getChildNonNullableException();
if (childNonNullableException.isPresent()) {
return data(null, childNonNullableException.get());
}
List errors = new ArrayList<>();
List