How to merge results of multiple IQueryables into one resolver without loosing IQueryables filtering and sorting capabilities? #4885
Unanswered
jhpetersen
asked this question in
Q&A
Replies: 1 comment
-
Encountered the same problem. It's like the IResolverContext filter gets consumed when it's first used. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everybody,
first of all: i am thrilled about the possibilities and ease of use of HotChocolate 🎉 👍
but there is one thing i am trying to achieve, scratching my head since days without finding the right way to do, so now it's time to ask the community if this is possible at all, and if so how to implement.
First assume we have several data repositories (each providing a method
IQueryable<T> Query()
where T is a domain DTO) and a repository resolver to get a specific repository.The easy resolver method of one domain DTO type could look something like:
which is awesome because all filter clauses and sort definitions are passed through to the actual repository implementation, which evaluates the expression tree and do all the filtering and sorting on the database.
Now here comes the tricky part:
Assume there could be different repositories providing data for the same DomainDTO type.
Having multiple resolver methods for each repository (like GetEntities1, GetEntities2, ...) or slightly better having one resolver method with a repository id or index (like
GetEntites([Service] IRepositoryResolver repositoryResolver, string? repositoryId)
) seems fishy, as clients always have to query each repository and get one result array per repository, which have to be concatenated afterwards.Instead it would be best to combine or merge the results of all repositories'
IQueryable<T> Query()
methods into one without loosing the ability to delegate filtering and sorting to the database.I tried a combination of IResolverContext with manual calling
Data.Filters.Expressions
andData.Sorting.Expressions
Filter and Sorte methods and awaiting customIExecutable<DTOType>
implementations which feels like almost there - but although there is data returned without any error, filtering and sorting is only applied and piped to the first IQueryable 😞Not working as intended:
Maybe i am missing something and i am totally on the wrong track.
So i would be happy happy happy, if someone can give a hint how to achieve merging multiple queries with filter and sort on database ❤️ 😉
regards and thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions