django-ariadne-jwt
django-ariadne-jwt copied to clipboard
Expected context values
I'm seeing an issue where the assumption in the codebase isn't mapping to what I'm seeing when using the code inside Django. Specifically, the JSONWebTokenMiddleware
makes the assumption that the provided info.context
will always equal a Django-like HttpRequest
object. In practice, I'm seeing two different behaviors:
-
info.context
is a dictionary with arequest
key that is the request object - The request object is not always an
HttpRequest
-like object. I'm seeingstarlette.requests.Request
coming from Ariadne.
I've got a branch of code off of #1 that contains fixes to the tests to account for these differences, but I wanted to check with you before opening another PR (or merging in to #1). Am I seeing different behavior than what you see / expect when you're using this code?
Oh, the code is at in the branch fix/support-ariadne-requests if ya care to see. Here's the diff.
Hey @tswicegood, I haven't found any other request type. What type of server are you using?
@marco-btree I'm using the base ariadne.asgi.GraphQL
(with the __call__
modification outlined in here: https://github.com/mirumee/ariadne/issues/210#issuecomment-508424149) and Django's runserver
configured with an ASGI app. From my reading of the code, the handle_http
method creates the request
object using starlette.requests.Request
here.
I've been using the code in that branch daily now this whole week with a configuration that looks like:
application = ProtocolTypeRouter(
{
"websocket": AuthMiddlewareStack(
URLRouter(
[
re_path(
r"graphql/?",
DjangoChannelsGraphQL(
schema, middleware=[JSONWebTokenMiddleware()], debug=True
),
)
]
)
),
"http": AuthMiddlewareStack(
URLRouter(
[
path(
"graphql/",
DjangoChannelsGraphQL(
schema, middleware=[JSONWebTokenMiddleware()], debug=True
),
),
re_path(r"", AsgiHandler),
]
)
),
}
)
Without the changes in that diff (which have expanded since opening this ticket), I can't get this running in an ASGI server.
I run into the same issue with the Django v3.1.4 development server (python manage.py runserver
).