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); }
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, graphQLSchema, instrumentationState); }); if (preparsedDoc.hasErrors()) { return CompletableFuture.completedFuture(new ExecutionResultImpl(preparsedDoc.getErrors())); } return execute(executionInputRef.get(), preparsedDoc.getDocument(), graphQLSchema, instrumentationState); }
private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) { ExecutionInput executionInput = executionInputRef.get(); String query = executionInput.getQuery(); log.debug("Parsing query: '{}'...", query); ParseResult parseResult = parse(executionInput, graphQLSchema, instrumentationState); if (parseResult.isFailure()) { log.warn("Query failed to parse : '{}'", executionInput.getQuery()); return new PreparsedDocumentEntry(parseResult.getException().toInvalidSyntaxError()); } else { final Document document = parseResult.getDocument(); // they may have changed the document and the variables via instrumentation so update the reference to it executionInput = executionInput.transform(builder -> builder.variables(parseResult.getVariables())); executionInputRef.set(executionInput); log.debug("Validating query: '{}'", query); final List<ValidationError> errors = validate(executionInput, document, graphQLSchema, instrumentationState); if (!errors.isEmpty()) { log.warn("Query failed to validate : '{}'", query); return new PreparsedDocumentEntry(errors); } return new PreparsedDocumentEntry(document); } }
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); }
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, graphQLSchema, instrumentationState); }); if (preparsedDoc.hasErrors()) { return CompletableFuture.completedFuture(new ExecutionResultImpl(preparsedDoc.getErrors())); } return execute(executionInputRef.get(), preparsedDoc.getDocument(), graphQLSchema, instrumentationState); }
@Override public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionInput) { return delegate.executeAsync(executionInput.transform(builder -> builder.context(new ContextWrapper(executionInput.getContext())))); }
private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) { ExecutionInput executionInput = executionInputRef.get(); String query = executionInput.getQuery(); log.debug("Parsing query: '{}'...", query); ParseResult parseResult = parse(executionInput, graphQLSchema, instrumentationState); if (parseResult.isFailure()) { log.warn("Query failed to parse : '{}'", executionInput.getQuery()); return new PreparsedDocumentEntry(parseResult.getException().toInvalidSyntaxError()); } else { final Document document = parseResult.getDocument(); // they may have changed the document and the variables via instrumentation so update the reference to it executionInput = executionInput.transform(builder -> builder.variables(parseResult.getVariables())); executionInputRef.set(executionInput); log.debug("Validating query: '{}'", query); final List<ValidationError> errors = validate(executionInput, document, graphQLSchema, instrumentationState); if (!errors.isEmpty()) { log.warn("Query failed to validate : '{}'", query); return new PreparsedDocumentEntry(errors); } return new PreparsedDocumentEntry(document); } }