Consider PageableDefaults and SortDefaults on query methods [DATACMNS-657]
Oliver Drotbohm opened DATACMNS-657 and commented
It would be cool if query methods on repositories would consider @PageableDefaults and @SortDefaults on Pageable and Sort parameters and expose them via the QueryMethod API.
The annotation configuration should be used when null is provided for the corresponding parameter
Affects: 1.9.2 (Evans SR2), 1.10 RC1 (Fowler)
2 votes, 3 watchers
Oliver Drotbohm commented
Three ways to skin the cat here:
- Introduce
QueryMethod.getDefaulted(Pageable pageable)and pipe thePageableobtained from theParameterAccessorthrough that method. - Introduce constructor in
ParametersParameterAccessorto take aQueryMethodand expose the defaults defined onQueryMethod. - Introduce
QueryMethodParameterAccessoras subtype ofParametersAccessorto take aQueryMethodinstead of aParametersinstance to overwritegetPageable()andgetSort()to consider the defaults declared on the method.
Thought about the conflict of both a Pageable and Sort declared, the latter defining a default and a value provided for the former containing a Sort.unsorted() which would raise the question of whether to apply the sorting default rules but it seems that QueryMethod currently does not allow both types do be declared in a single method.
Is it worth considering to allow @PageableDefault and @SortDefault on the type level so that it applies to all methods using Pageable and Sort as parameters?
Is it worth considering to allow
@PageableDefaultand@SortDefaulton the type level so that it applies to all methods usingPageableandSortas parameters?
We've a case for type level @SortDefault. In Spring for GraphQL, there is auto-registration of Querydsl and Query by Example repositories to perform GraphQL queries. For pagination and sorting support, https://github.com/spring-projects/spring-graphql/issues/597, for auto-registration cases it would be useful to specify sorting preferences on such an @GraphQlRepository.