graphql-python / graphene

GraphQL framework for Python
http://graphene-python.org/
MIT License
8.09k stars 827 forks source link

Request-level middleware #1117

Open melvinkcx opened 4 years ago

melvinkcx commented 4 years ago

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:

  1. Move auth checking into a Django middleware, but that means any exception raised will not be serialized into GraphQLResponse.
  2. Add a flag is_authenticated into info.context object, if the value of info.context.is_authenticated is True, skip the middleware by calling next()
melvinkcx commented 4 years ago

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.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

erikwrede commented 2 years ago

Looks interesting, I will have a deeper look into this soon