use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QueryByExampleDataFetcherJpaTests method shouldFetchSingleItemsWithInterfaceProjection.
@Test
void shouldFetchSingleItemsWithInterfaceProjection() {
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(BookProjection.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("Hitchhiker's Guide to the Galaxy by Douglas Adams");
}
use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QueryByExampleDataFetcherReactiveMongoDbTests method shouldFetchSingleItemsReactivelyWithDtoProjection.
@Test
void shouldFetchSingleItemsReactivelyWithDtoProjection() {
Book book = new Book("42", "Hitchhiker's Guide to the Galaxy", new Author("0", "Douglas", "Adams"));
repository.save(book).block();
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");
}
use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldFetchSingleItemsWithInterfaceProjection.
@Test
void shouldFetchSingleItemsWithInterfaceProjection() {
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(BookProjection.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("Hitchhiker's Guide to the Galaxy by Douglas Adams");
}
use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldReactivelyFetchMultipleItems.
@Test
void shouldReactivelyFetchMultipleItems() {
ReactiveMockRepository mockRepository = mock(ReactiveMockRepository.class);
Book book1 = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
Book book2 = new Book(53L, "Breaking Bad", new Author(0L, "", "Heisenberg"));
when(mockRepository.findBy(any(), any())).thenReturn(Flux.just(book1, book2));
Consumer<GraphQlSetup> tester = setup -> {
Mono<WebOutput> outputMono = setup.toWebGraphQlHandler().handleRequest(input("{ books {name}}"));
List<String> names = GraphQlResponse.from(outputMono).toList("books", Book.class).stream().map(Book::getName).collect(Collectors.toList());
assertThat(names).containsExactlyInAnyOrder("Breaking Bad", "Hitchhiker's Guide to the Galaxy");
};
// explicit wiring
tester.accept(graphQlSetup("books", QuerydslDataFetcher.builder(mockRepository).many()));
// auto registration
tester.accept(graphQlSetup(mockRepository));
}
use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QueryByExampleDataFetcherMongoDbTests method shouldFetchSingleItemsWithInterfaceProjection.
@Test
void shouldFetchSingleItemsWithInterfaceProjection() {
Book book = new Book("42", "Hitchhiker's Guide to the Galaxy", new Author("0", "Douglas", "Adams"));
repository.save(book);
DataFetcher<?> fetcher = QueryByExampleDataFetcher.builder(repository).projectAs(BookProjection.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("Hitchhiker's Guide to the Galaxy by Douglas Adams");
}
Aggregations