use of org.springframework.graphql.GraphQlSetup in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldReactivelyFetchSingleItems.
@Test
void shouldReactivelyFetchSingleItems() {
ReactiveMockRepository mockRepository = mock(ReactiveMockRepository.class);
Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
when(mockRepository.findBy(any(), any())).thenReturn(Mono.just(book));
Consumer<GraphQlSetup> tester = setup -> {
Mono<WebOutput> outputMono = setup.toWebGraphQlHandler().handleRequest(input("{ bookById(id: 1) {name}}"));
Book actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo(book.getName());
};
// explicit wiring
tester.accept(graphQlSetup("bookById", QuerydslDataFetcher.builder(mockRepository).single()));
// auto registration
tester.accept(graphQlSetup(mockRepository));
}
Aggregations