Search in sources :

Example 1 with AbortExecutionException

use of graphql.execution.AbortExecutionException in project graphql-java by graphql-java.

the class GraphQL method executeAsync.

/**
 * Executes the graphql query using the provided input object
 * <p>
 * This will return a promise (aka {@link CompletableFuture}) to provide a {@link ExecutionResult}
 * which is the result of executing the provided query.
 *
 * @param executionInput {@link ExecutionInput}
 *
 * @return a promise to an {@link ExecutionResult} which can include errors
 */
public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionInput) {
    try {
        log.debug("Executing request. operation name: '{}'. query: '{}'. variables '{}'", executionInput.getOperationName(), executionInput.getQuery(), executionInput.getVariables());
        InstrumentationState instrumentationState = instrumentation.createState();
        InstrumentationExecutionParameters inputInstrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState);
        executionInput = instrumentation.instrumentExecutionInput(executionInput, inputInstrumentationParameters);
        InstrumentationExecutionParameters instrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState);
        InstrumentationContext<ExecutionResult> executionInstrumentation = instrumentation.beginExecution(instrumentationParameters);
        GraphQLSchema graphQLSchema = instrumentation.instrumentSchema(this.graphQLSchema, instrumentationParameters);
        CompletableFuture<ExecutionResult> executionResult = parseValidateAndExecute(executionInput, graphQLSchema, instrumentationState);
        // 
        // finish up instrumentation
        executionResult = executionResult.whenComplete(executionInstrumentation::onCompleted);
        // 
        // allow instrumentation to tweak the result
        executionResult = executionResult.thenCompose(result -> instrumentation.instrumentExecutionResult(result, instrumentationParameters));
        return executionResult;
    } catch (AbortExecutionException abortException) {
        ExecutionResultImpl executionResult = new ExecutionResultImpl(abortException);
        if (!abortException.getUnderlyingErrors().isEmpty()) {
            executionResult = new ExecutionResultImpl(abortException.getUnderlyingErrors());
        }
        return CompletableFuture.completedFuture(executionResult);
    }
}
Also used : Execution(graphql.execution.Execution) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) AbortExecutionException(graphql.execution.AbortExecutionException) ExecutionStrategy(graphql.execution.ExecutionStrategy) InstrumentationExecutionParameters(graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) UnaryOperator(java.util.function.UnaryOperator) InstrumentationState(graphql.execution.instrumentation.InstrumentationState) PreparsedDocumentEntry(graphql.execution.preparsed.PreparsedDocumentEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutionId(graphql.execution.ExecutionId) Parser(graphql.parser.Parser) SubscriptionExecutionStrategy(graphql.execution.SubscriptionExecutionStrategy) Map(java.util.Map) AsyncExecutionStrategy(graphql.execution.AsyncExecutionStrategy) GraphQLSchema(graphql.schema.GraphQLSchema) NoOpPreparsedDocumentProvider(graphql.execution.preparsed.NoOpPreparsedDocumentProvider) Logger(org.slf4j.Logger) PreparsedDocumentProvider(graphql.execution.preparsed.PreparsedDocumentProvider) CompletionException(java.util.concurrent.CompletionException) InvalidSyntaxError.toInvalidSyntaxError(graphql.InvalidSyntaxError.toInvalidSyntaxError) ExecutionIdProvider(graphql.execution.ExecutionIdProvider) InstrumentationContext(graphql.execution.instrumentation.InstrumentationContext) Consumer(java.util.function.Consumer) InstrumentationValidationParameters(graphql.execution.instrumentation.parameters.InstrumentationValidationParameters) Document(graphql.language.Document) ValidationError(graphql.validation.ValidationError) List(java.util.List) Instrumentation(graphql.execution.instrumentation.Instrumentation) Assert.assertNotNull(graphql.Assert.assertNotNull) SimpleInstrumentation(graphql.execution.instrumentation.SimpleInstrumentation) AsyncSerialExecutionStrategy(graphql.execution.AsyncSerialExecutionStrategy) Validator(graphql.validation.Validator) InstrumentationState(graphql.execution.instrumentation.InstrumentationState) InstrumentationExecutionParameters(graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters) AbortExecutionException(graphql.execution.AbortExecutionException) GraphQLSchema(graphql.schema.GraphQLSchema)

Aggregations

Assert.assertNotNull (graphql.Assert.assertNotNull)1 InvalidSyntaxError.toInvalidSyntaxError (graphql.InvalidSyntaxError.toInvalidSyntaxError)1 AbortExecutionException (graphql.execution.AbortExecutionException)1 AsyncExecutionStrategy (graphql.execution.AsyncExecutionStrategy)1 AsyncSerialExecutionStrategy (graphql.execution.AsyncSerialExecutionStrategy)1 Execution (graphql.execution.Execution)1 ExecutionId (graphql.execution.ExecutionId)1 ExecutionIdProvider (graphql.execution.ExecutionIdProvider)1 ExecutionStrategy (graphql.execution.ExecutionStrategy)1 SubscriptionExecutionStrategy (graphql.execution.SubscriptionExecutionStrategy)1 Instrumentation (graphql.execution.instrumentation.Instrumentation)1 InstrumentationContext (graphql.execution.instrumentation.InstrumentationContext)1 InstrumentationState (graphql.execution.instrumentation.InstrumentationState)1 SimpleInstrumentation (graphql.execution.instrumentation.SimpleInstrumentation)1 InstrumentationExecutionParameters (graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters)1 InstrumentationValidationParameters (graphql.execution.instrumentation.parameters.InstrumentationValidationParameters)1 NoOpPreparsedDocumentProvider (graphql.execution.preparsed.NoOpPreparsedDocumentProvider)1 PreparsedDocumentEntry (graphql.execution.preparsed.PreparsedDocumentEntry)1 PreparsedDocumentProvider (graphql.execution.preparsed.PreparsedDocumentProvider)1 Document (graphql.language.Document)1