use of graphql.execution.MergedSelectionSet in project graphql-java by graphql-java.
the class ExecutionHelper method getFieldSubSelection.
public FieldSubSelection getFieldSubSelection(ExecutionContext executionContext) {
OperationDefinition operationDefinition = executionContext.getOperationDefinition();
GraphQLObjectType operationRootType = Common.getOperationRootType(executionContext.getGraphQLSchema(), operationDefinition);
FieldCollectorParameters collectorParameters = FieldCollectorParameters.newParameters().schema(executionContext.getGraphQLSchema()).objectType(operationRootType).fragments(executionContext.getFragmentsByName()).variables(executionContext.getVariables()).build();
MergedSelectionSet mergedSelectionSet = fieldCollector.collectFields(collectorParameters, operationDefinition.getSelectionSet());
ExecutionStepInfo executionInfo = newExecutionStepInfo().type(operationRootType).path(ResultPath.rootPath()).build();
FieldSubSelection fieldSubSelection = FieldSubSelection.newFieldSubSelection().source(executionContext.getRoot()).localContext(executionContext.getLocalContext()).mergedSelectionSet(mergedSelectionSet).executionInfo(executionInfo).build();
return fieldSubSelection;
}
use of graphql.execution.MergedSelectionSet in project graphql-java by graphql-java.
the class BatchedExecutionStrategy method fetchAndAnalyze.
private CompletableFuture<List<NodeZipper<ExecutionResultNode>>> fetchAndAnalyze(ExecutionContext executionContext, List<NodeZipper<ExecutionResultNode>> unresolvedNodes) {
assertTrue(unresolvedNodes.size() > 0, () -> "unresolvedNodes can't be empty");
List<FieldSubSelection> fieldSubSelections = map(unresolvedNodes, node -> util.createFieldSubSelection(executionContext, node.getCurNode().getExecutionStepInfo(), node.getCurNode().getResolvedValue()));
// constrain: all fieldSubSelections have the same mergedSelectionSet
MergedSelectionSet mergedSelectionSet = fieldSubSelections.get(0).getMergedSelectionSet();
List<CompletableFuture<List<FetchedValueAnalysis>>> fetchedValues = batchFetchForEachSubField(executionContext, fieldSubSelections, mergedSelectionSet);
return mapBatchedResultsBack(unresolvedNodes, fetchedValues);
}
use of graphql.execution.MergedSelectionSet in project graphql-java by graphql-java.
the class ExecutionStrategyUtil method createFieldSubSelection.
public FieldSubSelection createFieldSubSelection(ExecutionContext executionContext, ExecutionStepInfo executionInfo, ResolvedValue resolvedValue) {
MergedField field = executionInfo.getField();
Object source = resolvedValue.getCompletedValue();
Object localContext = resolvedValue.getLocalContext();
GraphQLOutputType sourceType = executionInfo.getUnwrappedNonNullType();
GraphQLObjectType resolvedObjectType = resolveType.resolveType(executionContext, field, source, executionInfo, sourceType, localContext);
FieldCollectorParameters collectorParameters = newParameters().schema(executionContext.getGraphQLSchema()).objectType(resolvedObjectType).fragments(executionContext.getFragmentsByName()).variables(executionContext.getVariables()).build();
MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, executionInfo.getField());
// it is not really a new step but rather a refinement
ExecutionStepInfo newExecutionStepInfoWithResolvedType = executionInfo.changeTypeWithPreservedNonNull(resolvedObjectType);
return FieldSubSelection.newFieldSubSelection().source(source).localContext(localContext).mergedSelectionSet(subFields).executionInfo(newExecutionStepInfoWithResolvedType).build();
}
Aggregations