Request-level middleware
Author: melvinkcxCreated Dec 23, 2019Updated Apr 15, 2025
Labelswontfix
I'm using Graphene with Django, and I have a middleware that checks user auth token. I'm having an issue with the middleware being executed at the field-level. Each field resolution triggers a call to check user's token in my case.
Any suggestions to improve this? Any plans for supporting request-level middleware?
I have some idea:
- Move auth checking into a Django middleware, but that means any exception raised will not be serialized into GraphQLResponse.
- Add a flag
is_authenticatedintoinfo.contextobject, if the value ofinfo.context.is_authenticatedis True, skip the middleware by callingnext()
Source: graphql-python/graphene