Search in sources :

Example 1 with MergedSelectionSet

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;
}
Also used : MergedSelectionSet(graphql.execution.MergedSelectionSet) FieldCollectorParameters(graphql.execution.FieldCollectorParameters) ExecutionStepInfo.newExecutionStepInfo(graphql.execution.ExecutionStepInfo.newExecutionStepInfo) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) GraphQLObjectType(graphql.schema.GraphQLObjectType) OperationDefinition(graphql.language.OperationDefinition)

Example 2 with MergedSelectionSet

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);
}
Also used : MergedSelectionSet(graphql.execution.MergedSelectionSet) CompletableFuture(java.util.concurrent.CompletableFuture)

Example 3 with MergedSelectionSet

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();
}
Also used : MergedSelectionSet(graphql.execution.MergedSelectionSet) GraphQLOutputType(graphql.schema.GraphQLOutputType) FieldCollectorParameters(graphql.execution.FieldCollectorParameters) MergedField(graphql.execution.MergedField) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) GraphQLObjectType(graphql.schema.GraphQLObjectType)

Aggregations

MergedSelectionSet (graphql.execution.MergedSelectionSet)3 ExecutionStepInfo (graphql.execution.ExecutionStepInfo)2 FieldCollectorParameters (graphql.execution.FieldCollectorParameters)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2 ExecutionStepInfo.newExecutionStepInfo (graphql.execution.ExecutionStepInfo.newExecutionStepInfo)1 MergedField (graphql.execution.MergedField)1 OperationDefinition (graphql.language.OperationDefinition)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 CompletableFuture (java.util.concurrent.CompletableFuture)1