-
Notifications
You must be signed in to change notification settings - Fork 769
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
Oneshot middleware #810
Comments
I'm running into this issue as well, I have a middleware that checks the auth of the user and it is being consistently called for each field. |
Graphene middleware is called at a field-level, each field resolution would trigger calls to all middleware. I'm not sure if graphene will support request-level middleware, I just created an issue: graphql-python/graphene#1117 For now, what I do is add an attribute into
|
It's the same problem i'm noticing in my case but as you can see the middleware, despite not executing the logic runs anyway without executing nothing and so we're wasting execution time. Any idea so that we just run the middleware once for a specific context of execution? |
I just released graphql-utilities including utilities to support operation-level only middleware. It targets graphql-core>=3.0 (or graphql-core-next), feel free to check it out. |
@melvinkcx Thank you for this package Just copied the it would be awesome if the |
I've tried also the decorator but turn out for me that the middleware run just once and at the first request only, then for the others isn't just executed @melvinkcx Can you confirm the behaviour? |
Only the decorated middleware would run once. Any other undecorated
middlewares should execute at field-level as usual.
…On Wed, Feb 5, 2020 at 7:57 AM MrFoxes ***@***.***> wrote:
@melvinkcx <https://github.com/melvinkcx> Thank you for this package
Just copied the run_only_once decorator into my own code because I don't
want to have another dependency for 10 lines of code :)
it would be awesome if the run_only_once decorator can be picked into
graphene_django
Whats your opinion @zbyte64 <https://github.com/zbyte64> ?
I've tried also the decorator but turn out for me that the middleware run
just once and at the first request only, then for the others isn't just
executed
@melvinkcx <https://github.com/melvinkcx> Can you confirm the behaviour?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#810?email_source=notifications&email_token=AEBBQ4INUPTI4P4N2HSFJ73RBHXGBA5CNFSM4JNJN722YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKZQDUQ#issuecomment-582156754>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEBBQ4OW46IKCRYPZHRFPKLRBHXGBANCNFSM4JNJN72Q>
.
|
I confirm this behaviour is also happening to me. I need my middleware to execute at request level but with |
@richin13 @mrfoxes This issue is fixed and is now available in graphql-utilities>=0.2.0. |
@melvinkcx if you could just tell how to use run_only_once decorator in my django-graphql project . it would be a great help. |
Hi!
Currently I'm trying to add some one-shot-middlewares to the graphene schema (e.g. version check, policy check). The problem is, that the middleware get's fired for each field instead for a single request.
I can't use the DjangoMiddlewares because the error doesn't get wrapped into the graphql response
error
fieldI found 2 solutions for this problem:
_skip=False
in the middleware which is toggled toTrue
before the firstnext(...)
call, e.g.:Well - that works but feels really odd.
GraphQLView.get_response
method like this:This feels also odd, but a way cleaner.
So - what's the best way to integrate a one-time middleware? It feels like the framework is missing this essential feature.
The text was updated successfully, but these errors were encountered: