graphql.execution.nextgen.ResultNodesCreator Maven / Gradle / Ivy
package graphql.execution.nextgen;
import graphql.Internal;
import graphql.execution.ExecutionStepInfo;
import graphql.execution.NonNullableFieldWasNullException;
import graphql.execution.nextgen.result.ExecutionResultNode;
import graphql.execution.nextgen.result.LeafExecutionResultNode;
import graphql.execution.nextgen.result.ListExecutionResultNode;
import graphql.execution.nextgen.result.ResolvedValue;
import graphql.execution.nextgen.result.UnresolvedObjectResultNode;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import static graphql.collect.ImmutableKit.map;
/**
* @deprecated Jan 2022 - We have decided to deprecate the NextGen engine, and it will be removed in a future release.
*/
@Deprecated
@Internal
public class ResultNodesCreator {
public ExecutionResultNode createResultNode(FetchedValueAnalysis fetchedValueAnalysis) {
ResolvedValue resolvedValue = createResolvedValue(fetchedValueAnalysis);
ExecutionStepInfo executionStepInfo = fetchedValueAnalysis.getExecutionStepInfo();
if (fetchedValueAnalysis.isNullValue() && executionStepInfo.isNonNullType()) {
NonNullableFieldWasNullException nonNullableFieldWasNullException = new NonNullableFieldWasNullException(executionStepInfo, executionStepInfo.getPath());
return new LeafExecutionResultNode(executionStepInfo, resolvedValue, nonNullableFieldWasNullException);
}
if (fetchedValueAnalysis.isNullValue()) {
return new LeafExecutionResultNode(executionStepInfo, resolvedValue, null);
}
if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.OBJECT) {
return createUnresolvedNode(fetchedValueAnalysis);
}
if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.LIST) {
return createListResultNode(fetchedValueAnalysis);
}
return new LeafExecutionResultNode(executionStepInfo, resolvedValue, null);
}
private ExecutionResultNode createUnresolvedNode(FetchedValueAnalysis fetchedValueAnalysis) {
return new UnresolvedObjectResultNode(fetchedValueAnalysis.getExecutionStepInfo(), createResolvedValue(fetchedValueAnalysis));
}
private ResolvedValue createResolvedValue(FetchedValueAnalysis fetchedValueAnalysis) {
return ResolvedValue.newResolvedValue()
.completedValue(fetchedValueAnalysis.getCompletedValue())
.localContext(fetchedValueAnalysis.getFetchedValue().getLocalContext())
.nullValue(fetchedValueAnalysis.isNullValue())
.errors(fetchedValueAnalysis.getErrors())
.build();
}
private Optional getFirstNonNullableException(Collection collection) {
return collection.stream()
.filter(executionResultNode -> executionResultNode.getNonNullableFieldWasNullException() != null)
.map(ExecutionResultNode::getNonNullableFieldWasNullException)
.findFirst();
}
private ExecutionResultNode createListResultNode(FetchedValueAnalysis fetchedValueAnalysis) {
List executionResultNodes = map(fetchedValueAnalysis.getChildren(), this::createResultNode);
return new ListExecutionResultNode(fetchedValueAnalysis.getExecutionStepInfo(), createResolvedValue(fetchedValueAnalysis), executionResultNodes);
}
}