Support List arguments in QuerydslDataFetcher

Closes gh-281
This commit is contained in:
rstoyanchev
2022-02-17 12:24:42 +00:00
parent 4c6ec7df11
commit 937c265091
3 changed files with 19 additions and 1 deletions

View File

@@ -130,7 +130,9 @@ public abstract class QuerydslDataFetcher<T> {
this.customizer.customize(bindings, path);
for (Map.Entry<String, Object> entry : environment.getArguments().entrySet()) {
parameters.put(entry.getKey(), Collections.singletonList(entry.getValue()));
Object value = entry.getValue();
List<Object> values = (value instanceof List ? (List<Object>) value : Collections.singletonList(value));
parameters.put(entry.getKey(), values);
}
return BUILDER.getPredicate(this.domainType, (MultiValueMap) parameters, bindings);

View File

@@ -111,6 +111,21 @@ class QuerydslDataFetcherTests {
tester.accept(graphQlSetup(mockRepository));
}
@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());
}
@Test
void shouldApplyCustomizerInRepository() {
MockWithCustomizerRepository repository = repositoryFactory.getRepository(MockWithCustomizerRepository.class);

View File

@@ -1,5 +1,6 @@
type Query {
bookById(id: ID): Book
booksById(id: [ID]): [Book]
books(id: ID, name: String, author: String): [Book]
booksByCriteria(criteria:BookCriteria): [Book]
booksByProjectedArguments(name: String, author: String): [Book]