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);
}
}
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);
}
Aggregations