django-ariadne-jwt icon indicating copy to clipboard operation
django-ariadne-jwt copied to clipboard

Expected context values

Open tswicegood opened this issue 5 years ago • 4 comments

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 a request key that is the request object
  • The request object is not always an HttpRequest-like object. I'm seeing starlette.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?

tswicegood avatar Oct 13 '19 20:10 tswicegood

Oh, the code is at in the branch fix/support-ariadne-requests if ya care to see. Here's the diff.

tswicegood avatar Oct 13 '19 20:10 tswicegood

Hey @tswicegood, I haven't found any other request type. What type of server are you using?

ghost avatar Oct 16 '19 23:10 ghost

@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.

tswicegood avatar Oct 18 '19 10:10 tswicegood

I run into the same issue with the Django v3.1.4 development server (python manage.py runserver).

abaumg avatar Jan 15 '21 23:01 abaumg