use of org.springframework.graphql.web.WebOutput in project spring-graphql by spring-projects.
the class QueryByExampleDataFetcherReactiveMongoDbTests method shouldFetchSingleItemsReactivelyWithInterfaceProjection.
@Test
void shouldFetchSingleItemsReactivelyWithInterfaceProjection() {
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(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 QueryByExampleDataFetcherMongoDbTests method shouldFetchSingleItemsWithDtoProjection.
@Test
void shouldFetchSingleItemsWithDtoProjection() {
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(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 QueryByExampleDataFetcherMongoDbTests method shouldFavorExplicitWiring.
@Test
void shouldFavorExplicitWiring() {
BookMongoRepository mockRepository = mock(BookMongoRepository.class);
Book book = new Book("42", "Hitchhiker's Guide to the Galaxy", new Author("0", "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("53", "Breaking Bad", new Author("0", "", "Heisenberg"))).toWebGraphQlHandler();
outputMono = handler.handleRequest(input("{ bookById(id: 1) {name}}"));
actualBook = GraphQlResponse.from(outputMono).toEntity("bookById", Book.class);
assertThat(actualBook.getName()).isEqualTo("Breaking Bad");
}
Aggregations