-
Notifications
You must be signed in to change notification settings - Fork 320
How to access @BatchMapping filter arguments? #417
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
Comments
This is a duplicate of #232. Please, see the discussion there. At present, there is no easy way to do this and ensure it works in all cases. We can add something to the documentation on that, but that's about it. |
By following #232 and digging deeper into the topic I understood that I can build something like:
and
Based on this, I meanhwile implemented a minimal working solution for filtered batch loading, which does not suffer from the N+1 problem. Thanks @rstoyanchev. |
I think this issue is worth reconsidering. It would be elegant to pull in arguments that are sent in the current field regardless of batch mapping or schema mapping. It didn't occur immediately to me why
Compare this code:
with the workaround above. Workaround is much longer and more boilerplate code (about 20 extra lines in my implementation now). Edit - Is there an example that returns a list of objects in the batch? I tried using @aboger's workaround but stuck on this type issue with
If I try I was able to resolve this type issue using https://techdozo.dev/spring-for-graphql-how-to-solve-the-n1-problem/ Basically we'll lose the type with this approach:
|
@aboger what does
|
Thanks for Spring GraphQL. Integrating it is a joy, everything works just fine out-of-the-box. I just found this little spot:
During integration of Spring GraphQL into an existing application, I implemented
@BatchMapping
in order to solve the N+1 problem when loading related types. I then figured that methods annotated with@BatchMapping
do not provide access toinput
objects using the@Argument
annotation. Intuitively, I hoped for something like this to work:I read though the documentation, and support for
@Argument
with@BatchMapping
seems absent.I briefly debugged the code and couldn't spot support in
org.springframework.graphql.data.method.annotation.support.BatchLoaderHandlerMethod#resolveArgument
.Apparently, I can currently only implement filtering suffering from N+1 using
@SchemaMapping
like this:Did I misunderstand something? If so, kindly asking for support on this :-)
If not, is a work-around possible to access the filter object, e.g. using an interceptor?
Should support for this already be planned, could you already estimate when it would be released?
Issue 411 could be related.
The text was updated successfully, but these errors were encountered: