Search in sources :

Example 1 with PreparsedDocumentEntry

use of graphql.execution.preparsed.PreparsedDocumentEntry in project graphql-java by graphql-java.

the class GraphQL method parseAndValidate.

private PreparsedDocumentEntry parseAndValidate(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
    log.debug("Parsing query: '{}'...", executionInput.getQuery());
    ParseResult parseResult = parse(executionInput, graphQLSchema, instrumentationState);
    if (parseResult.isFailure()) {
        log.warn("Query failed to parse : '{}'", executionInput.getQuery());
        return new PreparsedDocumentEntry(toInvalidSyntaxError(parseResult.getException()));
    } else {
        final Document document = parseResult.getDocument();
        log.debug("Validating query: '{}'", executionInput.getQuery());
        final List<ValidationError> errors = validate(executionInput, document, graphQLSchema, instrumentationState);
        if (!errors.isEmpty()) {
            log.warn("Query failed to validate : '{}'", executionInput.getQuery());
            return new PreparsedDocumentEntry(errors);
        }
        return new PreparsedDocumentEntry(document);
    }
}
Also used : PreparsedDocumentEntry(graphql.execution.preparsed.PreparsedDocumentEntry) ValidationError(graphql.validation.ValidationError) Document(graphql.language.Document)

Example 2 with PreparsedDocumentEntry

use of graphql.execution.preparsed.PreparsedDocumentEntry 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);
}
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) PreparsedDocumentEntry(graphql.execution.preparsed.PreparsedDocumentEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

PreparsedDocumentEntry (graphql.execution.preparsed.PreparsedDocumentEntry)2 Document (graphql.language.Document)2 ValidationError (graphql.validation.ValidationError)2 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