use of graphql.execution.instrumentation.InstrumentationState in project graphql-java by graphql-java.
the class GraphQL method parseValidateAndExecute.
private CompletableFuture<ExecutionResult> parseValidateAndExecute(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
AtomicReference<ExecutionInput> executionInputRef = new AtomicReference<>(executionInput);
PreparsedDocumentEntry preparsedDoc = preparsedDocumentProvider.get(executionInput.getQuery(), transformedQuery -> {
// if they change the original query in the pre-parser, then we want to see it downstream from then on
executionInputRef.set(executionInput.transform(bldr -> bldr.query(transformedQuery)));
return parseAndValidate(executionInputRef.get(), graphQLSchema, instrumentationState);
});
if (preparsedDoc.hasErrors()) {
return CompletableFuture.completedFuture(new ExecutionResultImpl(preparsedDoc.getErrors()));
}
return execute(executionInputRef.get(), preparsedDoc.getDocument(), graphQLSchema, instrumentationState);
}
use of graphql.execution.instrumentation.InstrumentationState 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);
}
}
Aggregations