use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldFetchSingleItemsWithDtoProjection.
@Test
void shouldFetchSingleItemsWithDtoProjection() {
Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
mockRepository.save(book);
DataFetcher<?> fetcher = QuerydslDataFetcher.builder(mockRepository).projectAs(BookDto.class).single();
WebGraphQlHandler handler = graphQlSetup("bookById", fetcher).toWebGraphQlHandler();
Mono<WebOutput> outputMono = handler.handleRequest(input("{ bookById(id: 42) {name}}"));
Book actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo("The book is: Hitchhiker's Guide to the Galaxy");
}
use of org.springframework.graphql.web.WebOutput 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));
}
use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldFavorExplicitWiring.
@Test
void shouldFavorExplicitWiring() {
MockRepository mockRepository = mock(MockRepository.class);
Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
when(mockRepository.findBy(any(), any())).thenReturn(Optional.of(book));
// 1) Automatic registration only
WebGraphQlHandler handler = graphQlSetup(mockRepository).toWebGraphQlHandler();
Mono<WebOutput> outputMono = handler.handleRequest(input("{ bookById(id: 1) {name}}"));
Book actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo("Hitchhiker's Guide to the Galaxy");
// 2) Automatic registration and explicit wiring
handler = graphQlSetup(mockRepository).queryFetcher("bookById", env -> new Book(53L, "Breaking Bad", new Author(0L, "", "Heisenberg"))).toWebGraphQlHandler();
outputMono = handler.handleRequest(input("{ bookById(id: 1) {name}}"));
actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo("Breaking Bad");
}
use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QueryByExampleDataFetcherJpaTests method shouldFavorExplicitWiring.
@Test
void shouldFavorExplicitWiring() {
BookJpaRepository mockRepository = mock(BookJpaRepository.class);
Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
when(mockRepository.findBy(any(), any())).thenReturn(Optional.of(book));
// 1) Automatic registration only
WebGraphQlHandler handler = graphQlSetup(mockRepository).toWebGraphQlHandler();
Mono<WebOutput> outputMono = handler.handleRequest(input("{ bookById(id: 1) {name}}"));
Book actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo("Hitchhiker's Guide to the Galaxy");
// 2) Automatic registration and explicit wiring
handler = graphQlSetup(mockRepository).queryFetcher("bookById", env -> new Book(53L, "Breaking Bad", new Author(0L, "", "Heisenberg"))).toWebGraphQlHandler();
outputMono = handler.handleRequest(input("{ bookById(id: 1) {name}}"));
actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo("Breaking Bad");
}
use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QueryByExampleDataFetcherJpaTests method shouldFetchSingleItemsWithDtoProjection.
@Disabled("Pending https://github.com/spring-projects/spring-data-jpa/issues/2327")
@Test
void shouldFetchSingleItemsWithDtoProjection() {
Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
repository.save(book);
DataFetcher<?> fetcher = QueryByExampleDataFetcher.builder(repository).projectAs(BookDto.class).single();
WebGraphQlHandler handler = graphQlSetup("bookById", fetcher).toWebGraphQlHandler();
Mono<WebOutput> outputMono = handler.handleRequest(input("{ bookById(id: 42) {name}}"));
Book actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo("The book is: Hitchhiker's Guide to the Galaxy");
}
Aggregations