use of graphql.execution.FetchedValue in project graphql-java by graphql-java.
the class ValueFetcher method extractBatchedValues.
@SuppressWarnings("unchecked")
private List<FetchedValue> extractBatchedValues(FetchedValue fetchedValueContainingList, int expectedSize) {
List<Object> list = (List<Object>) fetchedValueContainingList.getFetchedValue();
Assert.assertTrue(list.size() == expectedSize, () -> "Unexpected result size");
List<FetchedValue> result = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
List<GraphQLError> errors;
if (i == 0) {
errors = fetchedValueContainingList.getErrors();
} else {
errors = Collections.emptyList();
}
FetchedValue fetchedValue = FetchedValue.newFetchedValue().fetchedValue(list.get(i)).rawFetchedValue(fetchedValueContainingList.getRawFetchedValue()).errors(errors).localContext(fetchedValueContainingList.getLocalContext()).build();
result.add(fetchedValue);
}
return result;
}
use of graphql.execution.FetchedValue in project graphql-java by graphql-java.
the class ValueFetcher method fetchValue.
public CompletableFuture<FetchedValue> fetchValue(ExecutionContext executionContext, Object source, Object localContext, MergedField sameFields, ExecutionStepInfo executionInfo) {
Field field = sameFields.getSingleField();
GraphQLFieldDefinition fieldDef = executionInfo.getFieldDefinition();
GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry();
GraphQLFieldsContainer parentType = getFieldsContainer(executionInfo);
Supplier<Map<String, Object>> argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldDef.getArguments(), field.getArguments(), executionContext.getVariables()));
QueryDirectivesImpl queryDirectives = new QueryDirectivesImpl(sameFields, executionContext.getGraphQLSchema(), executionContext.getVariables());
GraphQLOutputType fieldType = fieldDef.getType();
Supplier<ExecutableNormalizedOperation> normalizedQuery = executionContext.getNormalizedQueryTree();
Supplier<ExecutableNormalizedField> normalisedField = () -> normalizedQuery.get().getNormalizedField(sameFields, executionInfo.getObjectType(), executionInfo.getPath());
DataFetchingFieldSelectionSet selectionSet = DataFetchingFieldSelectionSetImpl.newCollector(executionContext.getGraphQLSchema(), fieldType, normalisedField);
DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext).source(source).localContext(localContext).arguments(argumentValues).fieldDefinition(fieldDef).mergedField(sameFields).fieldType(fieldType).executionStepInfo(executionInfo).parentType(parentType).selectionSet(selectionSet).queryDirectives(queryDirectives).build();
ExecutionId executionId = executionContext.getExecutionId();
ResultPath path = executionInfo.getPath();
return callDataFetcher(codeRegistry, parentType, fieldDef, environment, executionId, path).thenApply(rawFetchedValue -> FetchedValue.newFetchedValue().fetchedValue(rawFetchedValue).rawFetchedValue(rawFetchedValue).build()).exceptionally(exception -> handleExceptionWhileFetching(field, path, exception)).thenApply(result -> unboxPossibleDataFetcherResult(sameFields, path, result, localContext)).thenApply(this::unboxPossibleOptional);
}
use of graphql.execution.FetchedValue in project graphql-java by graphql-java.
the class BatchedExecutionStrategy method analyseValues.
private List<FetchedValueAnalysis> analyseValues(ExecutionContext executionContext, List<FetchedValue> fetchedValues, List<ExecutionStepInfo> executionInfos) {
List<FetchedValueAnalysis> result = new ArrayList<>();
for (int i = 0; i < fetchedValues.size(); i++) {
FetchedValue fetchedValue = fetchedValues.get(i);
ExecutionStepInfo executionStepInfo = executionInfos.get(i);
FetchedValueAnalysis fetchedValueAnalysis = fetchedValueAnalyzer.analyzeFetchedValue(executionContext, fetchedValue, executionStepInfo);
result.add(fetchedValueAnalysis);
}
return result;
}
Aggregations