spring-projects / spring-projects/spring-data-rest

When using QueryDsl developers should be able to provide their own implementation of EntityPathResolver [DATAREST-694]

Open
#1,066 5 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: enhancement
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Vladimir Tsanev opened DATAREST-694 and commented

Use case that we have, has following requirements:

  • Enable QueryDsl for rest repositories. So applications consuming the /\{repository\}/something endpoints can specify filters with ?property=value.
  • Currently only exporting JpaRepositories via rest.
  • Not actually using QueryDsl in application code that depends on repositories (it will be used only by client side applications, consuming the rest endpoints).
  • Do not want QueryDsl Query classes generated, some of the reasons:
    • Too much unused classes
    • Complicates the build
    • Not really concerned about performance of query dsl path creating (caching them is sufficient enough).

Spring Data defines a strategy interface for resolving QueryDsl entity paths - EntityPathResolver.
We want to provide our own implementation to be used by spring data jpa/rest, based on PathBuilder instead of the generated query classes.

However currently it is a painful experience to meet to above requirements. Here are some of the problems we met and some suggestions for improvements.

  1. EntityPathResolver provided by QuerydslBindingsFactory is not actually used when creating instances of QueryDslJpaRepository,
    but a hard-coded reference to SimpleEntityPathResolver.INSTANCE
    1. Currently this could be worked around by providing custom repositoryFactoryBeanClass
    2. it would be better if sharing the same resolver between JpaRepositoryFactory and QuerydslBindingsFactory was easier.
  2. QueryPredicateBuilder (wrongly?) assumes that Path instances returned by the resolver are instances of generated querydsl classes (see reifyPath).
    1. To workaround this we provide our custom implementation of QueryPredicateBuilder, but
      1. QueryPredicateBuilder is a class that and cannot be easily extended. We also want to be able to wrap it to provide alternative chained implementations.
      2. To provide custom QueryPredicateBuilder, one should extend RepositoryRestMvcConfiguration and override repoRequestArgumentResolver().
QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver is package private, and we need to copy paste it in order to instantiate it in our configuration!
Maybe having QuerydslPredicateBuilder as a bean like QuerydslBindingsFactory would be better, extending RepositoryRestMvcConfiguration is something that we want to avoid because it disables spring boot's auto configuration.

Affects: 2.4 GA (Gosling)

8 votes, 9 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.