use of org.springframework.data.querydsl.binding.QuerydslBinderCustomizer in project spring-data-commons by spring-projects.
the class QuerydslPredicateArgumentResolverSupport method getPredicate.
Predicate getPredicate(MethodParameter parameter, MultiValueMap<String, String> queryParameters) {
MergedAnnotations annotations = MergedAnnotations.from(parameter.getParameter());
MergedAnnotation<QuerydslPredicate> predicateAnnotation = annotations.get(QuerydslPredicate.class);
TypeInformation<?> domainType = extractTypeInfo(parameter, predicateAnnotation).getRequiredActualType();
Optional<Class<? extends QuerydslBinderCustomizer<?>>> bindingsAnnotation = //
predicateAnnotation.getValue("bindings").map(CastUtils::cast);
QuerydslBindings bindings = //
bindingsAnnotation.map(//
it -> bindingsFactory.createBindingsFor(domainType, it)).orElseGet(() -> bindingsFactory.createBindingsFor(domainType));
return predicateBuilder.getPredicate(domainType, queryParameters, bindings);
}
use of org.springframework.data.querydsl.binding.QuerydslBinderCustomizer in project spring-graphql by spring-projects.
the class QuerydslDataFetcherTests method shouldApplyCustomizerViaBuilder.
@Test
void shouldApplyCustomizerViaBuilder() {
MockRepository mockRepository = mock(MockRepository.class);
DataFetcher<Iterable<Book>> fetcher = QuerydslDataFetcher.builder(mockRepository).customizer((QuerydslBinderCustomizer<QBook>) (bindings, book) -> bindings.bind(book.name).firstOptional((path, value) -> value.map(path::startsWith))).many();
graphQlSetup("books", fetcher).toWebGraphQlHandler().handleRequest(input("{ books(name: \"H\", author: \"Doug\") {name}}")).block();
ArgumentCaptor<Predicate> predicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mockRepository).findBy(predicateCaptor.capture(), any());
Predicate predicate = predicateCaptor.getValue();
assertThat(predicate).isEqualTo(QBook.book.name.startsWith("H").and(QBook.book.author.eq("Doug")));
}
Aggregations