-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support returning list of entities from @EntityMapping
methods
#922
Comments
@srdjan-bestic-ananas, thanks for taking a look at our milestone and for the feedback. At the moment, I've scheduled this to make that change, but do let me know if this is what you had in mind? |
@EntityMapping
methods
I should mention, it should be possible still get access to |
Thanks for the response @rstoyanchev I'm aware of accessing DataLoader through DataFetchingEnviornement, as well as using it as an argument, since we used that exact approach when custom mapping _entities query to one of the controller methods. The 'issue' with that approach is it leaves room for improvements as you still need to register custom data loaders and load data into them, approach which amounts to boilerplate code that BatchMapping annotation was designed to mitigate. And that leads to the actual question, do you see an easy way and a need to mix BatchMapping and EntityMapping logic, such that registering data loaders and loading them manually can be avoided? From my point of view and with limited time in studying spring-graphql code (1.3 milestone), it might prove difficult to add batch loading of entities elegantly at a later phase. |
I experimented, see this test with a Basically, the support for nested fields is the same. It doesn't matter if the parent was fetched through a |
My concern is regarding the root fields, not nested fields. From the example in the test, imagine that book entity is retrieved through IO, e.g. database call. You have an N+1 problem that can be solved only by manually registering batch data loader that is then invoked/loaded through method annotated with EntityMapping. The original question is essentially, have you accounted for maybe allowing List to be passed as a parameter to EntityMapping method, instead of a single id? |
That is a more clear description. I think batch mapping is maybe not be the best fit. In regular queries, data loading applies to nested fields, and it's not necessary at the top where the query simply returns a list. The use of the data loader library is also driven by GraphQL Java, while here we would need to do that ourselves. I'm not sure this is worth it. We could consider allowing an @EntityMapping
public List<Book> book(@Argument List<Integer> id) {
// ..
} We'd have to group representations by type, and remember their position in the original list, so when results are ready, we can put them back in their original place on the list. |
That seems reasonable. My mind automatically shifts to batch loading logic due to, as you say a need to reorder, which is a problem solved in mapped vs non mapped batch loading, but it makes sense to skip the data loading all together as this is a root query essentially that expects a list back. I'd even argue that |
@EntityMapping
methods@EntityMapping
methods
This is now available in 1.3.0-SNAPSHOT and we're releasing 1.3.0.-RC1 tomorrow. See the documentation update in 31f5075. Overall it worked out as discussed already. If you'd like to give it a try, and have further feedback, that would be great! |
Looks good! The only thing that comes to mind as a potential improvement point is enriching the doc to specify the obvious, which is the necessity to match order between input ids list and returned objects list. |
Thanks for the feedback. I've updated the reference docs based on your suggestion. |
@rstoyanchev I started working with a new Federated application and I was wondering if we could have a way to provide a way for the @EntityMapping in "Batch" execution also to support Flux as a return type. @EntityMapping
public List<Book> book(@Argument List<Integer> id) {
// ..
} NonBlocking mode @EntityMapping
public Flux<Book> book(@Argument List<Integer> id) {
// ..
} Also thanks for building this great framework |
@gianielsevier yes that makes sense. Could you create a new issue? |
In the mean time I would expect this to work: @EntityMapping
public Mono<List<Book>> book(@Argument List<Integer> id) {
// ..
return flux.collectList();
} |
Thanks for the suggestion @gianielsevier. I've created #991. |
Hi there, let me start by saying thank you for providing spring-graphql in the first place, and especially for delving into federation support as of recently. In the company I work for, we have recently adapted spring-graphql and the biggest missing piece was exactly that, no out of the box federation support that we had to implement on our own.
During the process, we came to discover that __referenceResolver queries can be fairly pricey if left to deal with singular entities. This is something that apollo team seems to warn about as can be seen in the note of the paragraph here https://www.apollographql.com/docs/federation/entities/#2-define-a-reference-resolver
For us, due to custom implementation, we have easily adapted to the advice.
I am curious to know your thoughts on the topic of mixing batch mapping with entities fetching and if there is a plan to support this in spring-graphql in the near future?
The text was updated successfully, but these errors were encountered: