Search in sources :

Example 1 with FetchedValue

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;
}
Also used : FetchedValue(graphql.execution.FetchedValue) ArrayList(java.util.ArrayList) GraphQLError(graphql.GraphQLError) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with FetchedValue

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);
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) Internal(graphql.Internal) FetchedValue(graphql.execution.FetchedValue) ValuesResolver(graphql.execution.ValuesResolver) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionContext(graphql.execution.ExecutionContext) ExecutableNormalizedField(graphql.normalized.ExecutableNormalizedField) Supplier(java.util.function.Supplier) DefaultValueUnboxer(graphql.execution.DefaultValueUnboxer) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ImmutableKit(graphql.collect.ImmutableKit) ExecutionId(graphql.execution.ExecutionId) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) ImmutableList(com.google.common.collect.ImmutableList) GraphQLError(graphql.GraphQLError) Map(java.util.Map) DataFetcher(graphql.schema.DataFetcher) GraphQLTypeUtil(graphql.schema.GraphQLTypeUtil) DataFetcherResult(graphql.execution.DataFetcherResult) Assert(graphql.Assert) LogKit(graphql.util.LogKit) Async(graphql.execution.Async) Logger(org.slf4j.Logger) ExceptionWhileDataFetching(graphql.ExceptionWhileDataFetching) MergedField(graphql.execution.MergedField) GraphQLOutputType(graphql.schema.GraphQLOutputType) ResultPath(graphql.execution.ResultPath) Field(graphql.language.Field) DataFetchingFieldSelectionSetImpl(graphql.schema.DataFetchingFieldSelectionSetImpl) ExecutableNormalizedOperation(graphql.normalized.ExecutableNormalizedOperation) List(java.util.List) QueryDirectivesImpl(graphql.execution.directives.QueryDirectivesImpl) CompletionStage(java.util.concurrent.CompletionStage) DataFetchingFieldSelectionSet(graphql.schema.DataFetchingFieldSelectionSet) FpKit(graphql.util.FpKit) DataFetchingEnvironmentImpl.newDataFetchingEnvironment(graphql.schema.DataFetchingEnvironmentImpl.newDataFetchingEnvironment) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) Collections(java.util.Collections) DataFetchingFieldSelectionSet(graphql.schema.DataFetchingFieldSelectionSet) ExecutableNormalizedOperation(graphql.normalized.ExecutableNormalizedOperation) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) DataFetchingEnvironmentImpl.newDataFetchingEnvironment(graphql.schema.DataFetchingEnvironmentImpl.newDataFetchingEnvironment) ExecutableNormalizedField(graphql.normalized.ExecutableNormalizedField) MergedField(graphql.execution.MergedField) Field(graphql.language.Field) GraphQLOutputType(graphql.schema.GraphQLOutputType) ExecutableNormalizedField(graphql.normalized.ExecutableNormalizedField) ResultPath(graphql.execution.ResultPath) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) QueryDirectivesImpl(graphql.execution.directives.QueryDirectivesImpl) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) Map(java.util.Map) ExecutionId(graphql.execution.ExecutionId)

Example 3 with FetchedValue

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;
}
Also used : FetchedValue(graphql.execution.FetchedValue) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) ArrayList(java.util.ArrayList)

Aggregations

FetchedValue (graphql.execution.FetchedValue)3 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 GraphQLError (graphql.GraphQLError)2 ExecutionStepInfo (graphql.execution.ExecutionStepInfo)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Assert (graphql.Assert)1 ExceptionWhileDataFetching (graphql.ExceptionWhileDataFetching)1 Internal (graphql.Internal)1 ImmutableKit (graphql.collect.ImmutableKit)1 Async (graphql.execution.Async)1 DataFetcherResult (graphql.execution.DataFetcherResult)1 DefaultValueUnboxer (graphql.execution.DefaultValueUnboxer)1 ExecutionContext (graphql.execution.ExecutionContext)1 ExecutionId (graphql.execution.ExecutionId)1 MergedField (graphql.execution.MergedField)1 ResultPath (graphql.execution.ResultPath)1 ValuesResolver (graphql.execution.ValuesResolver)1 QueryDirectivesImpl (graphql.execution.directives.QueryDirectivesImpl)1