All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.execution.defer.DeferredCall Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.execution.defer;

import graphql.DeferredExecutionResult;
import graphql.DeferredExecutionResultImpl;
import graphql.ExecutionResult;
import graphql.GraphQLError;
import graphql.Internal;
import graphql.execution.ExecutionPath;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

/**
 * This represents a deferred call (aka @defer) to get an execution result sometime after
 * the initial query has returned
 */
@Internal
public class DeferredCall {
    private final ExecutionPath path;
    private final Supplier> call;
    private final DeferredErrorSupport errorSupport;

    public DeferredCall(ExecutionPath path, Supplier> call, DeferredErrorSupport deferredErrorSupport) {
        this.path = path;
        this.call = call;
        this.errorSupport = deferredErrorSupport;
    }

    CompletableFuture invoke() {
        CompletableFuture future = call.get();
        return future.thenApply(this::transformToDeferredResult);
    }

    private DeferredExecutionResult transformToDeferredResult(ExecutionResult executionResult) {
        List errorsEncountered = errorSupport.getErrors();
        DeferredExecutionResultImpl.Builder builder = DeferredExecutionResultImpl.newDeferredExecutionResult().from(executionResult);
        return builder
                .addErrors(errorsEncountered)
                .path(path)
                .build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy