-
Notifications
You must be signed in to change notification settings - Fork 139
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
[MIDDLEWARE] middleware executed many times #53
Comments
I have the same issue, but no solution. I did notice however, that the middleware gets called with different inputs. If you try something like this, you'll see what I mean (careful, this creates a LOT of output):
Any suggestions are welcome! |
Thanks! We'll check it. |
It appears to be expected behavior. The Django debug middleware is using it to gather all the promises and summarize them: https://github.com/graphql-python/graphene-django/blob/dc561c68c49d1a91637503f765857d819c36769a/graphene_django/debug/middleware.py However, I think it's still nice to have some kind of work-around. |
Did anyone find a workaround on this? Because I want to log only the root query, not the whole fields many times. |
I made a workaround for logout only, not for the query-per-field; the solution was:
|
You can check if root variable is null
|
checking for i am trying to use middleware for authorization of each graphql request. |
I'm having the same problem, check for It seems that every resolver function call the middleware execution In my case i'm using Django and I'm considering to move the authentication logic inside the default MIDDLEWARE section so that grapqhl stop executing the middleware for each resolver function |
Running into the same issue with graphene-django. Only want to execute middleware resolve funcitons once on request, not for every response field. |
Hi, Do you have some news about this topic? Thanks |
Hi @diegopaladini, for now to run that logic just one time in a middleware I'm doing the same as @maciejzukowski beacause the default graphql behaviour is to run that middelware logic for each resolver that is being called but in my case i don't need it
|
For those that are using this solution for authentication of requests - I think a better approach is to not have security in the middleware but instead use decorators on the resolvers themselves. |
I have the same problem and the middleware is running four time for any request and in two of them root is not None |
i have the same problem but i use a external service to auth and and a get a spam because launch 10 request 1 per second |
is a good solution and works for me, but @graphql-python have to solution |
Hi! graphene fastAPI user here. Currently facing the same challenge. It is very cumbersome to implement authorization since I have a complex schema and GraphQL middleware executes so many times. In the middleware, I need to execute JWT verification, which sends requests to Azure AD endpoints to get certificates, which is overwhelming the server and it becomes unresponsive :( I had to implement the authorization in the middleware of FastAPI, but this is not ideal either - since now when my user is not authorized and hits graphql endpoint, he only gets back 'Internal Server Error'.. Anyone though about a different workaround? Using a decorator with resolvers is not neat either since I want to authorize every single request, i.e. introspection queries. |
Same problem, I am using graphne and django for my graphql server. I have my external server where I just need to pass the jwt. So I am using the middleware system. it seems that the middleware always gets called multiple times. The root None solution works. But still this function is executing multiple times which I don't need, My middleware code
|
Hi there, I'm using flask-graphql in a project and got into a question/issue I don't have many clues. I'm using middlewares; this is the minimum example:
(The problem happens no matter the version; the problem also happens when launching the wsgi app with gunicorn).
If I query "hello()", the "DummyMiddleware" will appear twice. If I query a list of elements, the middleware is executed lots of time, twice per element it seems.
For a query this is just a problem of performance, but in a Logout() mutation what happens is:
Is there anything wrong in my approach to middlewares? I'm not sure which part is responsible (flask, graphql, my configuration...). Any hint would be appreciated.
The text was updated successfully, but these errors were encountered: