use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class SchemaMappingPrincipalMethodArgumentResolverTests method executeAsync.
private Mono<RequestOutput> executeAsync(String schema, String document, Function<Context, Context> contextWriter) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.registerBean(GreetingController.class, () -> greetingController);
context.refresh();
ExecutionGraphQlService graphQlService = GraphQlSetup.schemaContent(schema).runtimeWiringForAnnotatedControllers(context).toGraphQlService();
return Mono.delay(Duration.ofMillis(10)).flatMap(aLong -> graphQlService.execute(TestRequestInput.forDocument(document))).contextWrite(contextWriter);
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class BatchLoadingTests method batchLoader.
@Test
void batchLoader() {
String document = "{ " + " booksByCriteria(criteria: {author:\"Orwell\"}) { " + " author {" + " firstName, " + " lastName " + " }" + " }" + "}";
this.registry.forTypePair(Long.class, Author.class).registerBatchLoader((ids, env) -> Flux.fromIterable(ids).map(BookSource::getAuthor));
GraphQlService service = GraphQlSetup.schemaResource(BookSource.schema).queryFetcher("booksByCriteria", env -> {
Map<String, Object> criteria = env.getArgument("criteria");
String authorName = (String) criteria.get("author");
return BookSource.findBooksByAuthor(authorName).stream().map(book -> new Book(book.getId(), book.getName(), book.getAuthorId())).collect(Collectors.toList());
}).dataFetcher("Book", "author", env -> {
Book book = env.getSource();
DataLoader<Long, Author> dataLoader = env.getDataLoader(Author.class.getName());
return dataLoader.load(book.getAuthorId());
}).dataLoaders(this.registry).toGraphQlService();
Mono<RequestOutput> resultMono = service.execute(TestRequestInput.forDocument(document));
List<Book> books = GraphQlResponse.from(resultMono).toList("booksByCriteria", Book.class);
assertThat(books).hasSize(2);
Author author = books.get(0).getAuthor();
assertThat(author).isNotNull();
assertThat(author.getFirstName()).isEqualTo("George");
assertThat(author.getLastName()).isEqualTo("Orwell");
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class GraphQlClientTestSupport method setMockResponse.
private void setMockResponse(Consumer<ExecutionResultImpl.Builder> consumer) {
ExecutionResultImpl.Builder builder = new ExecutionResultImpl.Builder();
consumer.accept(builder);
ExecutionInput executionInput = ExecutionInput.newExecutionInput("{}").build();
ExecutionResult result = builder.build();
when(this.transport.execute(this.requestCaptor.capture())).thenReturn(Mono.just(new RequestOutput(executionInput, result)));
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class ExecutionGraphQlService method execute.
@Override
public final Mono<RequestOutput> execute(RequestInput requestInput) {
return Mono.deferContextual((contextView) -> {
if (!this.isDefaultExecutionIdProvider && requestInput.getExecutionId() == null) {
requestInput.configureExecutionInput(RESET_EXECUTION_ID_CONFIGURER);
}
ExecutionInput executionInput = requestInput.toExecutionInput();
ReactorContextManager.setReactorContext(contextView, executionInput);
ExecutionInput updatedExecutionInput = registerDataLoaders(executionInput);
return Mono.fromFuture(this.graphQlSource.graphQl().executeAsync(updatedExecutionInput)).map(result -> new RequestOutput(updatedExecutionInput, result));
});
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class GraphQlTesterTestSupport method setMockResponse.
private void setMockResponse(Consumer<ExecutionResultImpl.Builder> consumer) {
ExecutionResultImpl.Builder builder = new ExecutionResultImpl.Builder();
consumer.accept(builder);
ExecutionInput executionInput = ExecutionInput.newExecutionInput("{}").build();
ExecutionResult result = builder.build();
given(this.graphQlService.execute(this.inputCaptor.capture())).willReturn(Mono.just(new RequestOutput(executionInput, result)));
}
Aggregations