use of org.springframework.graphql.Author in project spring-graphql by spring-projects.
the class SchemaMappingInvocationTests method mutation.
@Test
void mutation() {
String document = "mutation { " + " addAuthor(firstName:\"James\", lastName:\"Joyce\") { " + " id" + " firstName" + " lastName" + " }" + "}";
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
Author author = GraphQlResponse.from(resultMono).toEntity("addAuthor", Author.class);
assertThat(author.getId()).isEqualTo(99);
assertThat(author.getFirstName()).isEqualTo("James");
assertThat(author.getLastName()).isEqualTo("Joyce");
}
use of org.springframework.graphql.Author in project spring-graphql by spring-projects.
the class SchemaMappingInvocationTests method queryWithArgumentViaDataFetchingEnvironment.
@Test
void queryWithArgumentViaDataFetchingEnvironment() {
String document = "{ " + " authorById(id:\"101\") { " + " id" + " firstName" + " lastName" + " }" + "}";
AtomicReference<GraphQLContext> contextRef = new AtomicReference<>();
RequestInput requestInput = TestRequestInput.forDocument(document);
requestInput.configureExecutionInput((executionInput, builder) -> {
contextRef.set(executionInput.getGraphQLContext());
return executionInput;
});
Mono<RequestOutput> resultMono = graphQlService().execute(requestInput);
Author author = GraphQlResponse.from(resultMono).toEntity("authorById", Author.class);
assertThat(author.getId()).isEqualTo(101);
assertThat(author.getFirstName()).isEqualTo("George");
assertThat(author.getLastName()).isEqualTo("Orwell");
assertThat(contextRef.get().<String>get("key")).isEqualTo("value");
}
use of org.springframework.graphql.Author in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldFetchMultipleItemsWithListInput.
@Test
void shouldFetchMultipleItemsWithListInput() {
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"));
mockRepository.saveAll(Arrays.asList(book1, book2));
Mono<WebOutput> output = graphQlSetup(mockRepository).toWebGraphQlHandler().handleRequest(input("{ booksById(id: [42,53]) {name}}"));
List<String> names = GraphQlResponse.from(output).toList("booksById", Book.class).stream().map(Book::getName).collect(Collectors.toList());
assertThat(names).containsExactlyInAnyOrder(book1.getName(), book2.getName());
}
use of org.springframework.graphql.Author in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldFetchSingleItems.
@Test
void shouldFetchSingleItems() {
Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
mockRepository.save(book);
Consumer<GraphQlSetup> tester = setup -> {
Mono<WebOutput> output = setup.toWebGraphQlHandler().handleRequest(input("{ bookById(id: 42) {name}}"));
Book actualBook = GraphQlResponse.from(output).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.Author in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldFetchMultipleItems.
@Test
void shouldFetchMultipleItems() {
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"));
mockRepository.saveAll(Arrays.asList(book1, book2));
Consumer<GraphQlSetup> tester = graphQlSetup -> {
Mono<WebOutput> output = graphQlSetup.toWebGraphQlHandler().handleRequest(input("{ books {name}}"));
List<String> names = GraphQlResponse.from(output).toList("books", Book.class).stream().map(Book::getName).collect(Collectors.toList());
assertThat(names).containsExactlyInAnyOrder(book1.getName(), book2.getName());
};
// explicit wiring
tester.accept(graphQlSetup("books", QuerydslDataFetcher.builder(mockRepository).many()));
// auto registration
tester.accept(graphQlSetup(mockRepository));
}
Aggregations