Skip to content
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

Middlewares are executing in reverse order #1499

Open
tbhaxor opened this issue Dec 12, 2023 · 1 comment
Open

Middlewares are executing in reverse order #1499

tbhaxor opened this issue Dec 12, 2023 · 1 comment

Comments

@tbhaxor
Copy link

tbhaxor commented Dec 12, 2023

  • What is the current behavior?

I am integrating it with the Django and middleware list is not obeying the ascending order of the list. I have to add [::-1] to make it coherent.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    a github repo, https://repl.it or similar.

Create two middleware and add print statements in it. 1st indexed middleware will execute first and then followed by 0th index middleware

GRAPHENE = {
    "SCHEMA": "backend.graphql.schema",
    "MIDDLEWARE": [
        "backend.graphql.DebugMiddleware",
        "backend.graphql.RequestAuthInjectorMiddleware",
    ],
}

These two middlewares are defined as following

class RequestAuthInjectorMiddleware:
    def resolve(self, next, root, info, **kwargs):
        print("Request Auth Injector")
        return next(root, info, **kwargs)


class DebugMiddleware(DjangoDebugMiddleware):
    def resolve(self, next, root, info, *args, **kwargs):
        print("Debug Middleware")
        return super().resolve(next, root, info, **kwargs)

Output

Request Auth Injector
Debug Middleware
  • What is the expected behavior?

It should run the middleware in same order as provided in the list. For example, here is the hotfix

GRAPHENE = {
    "SCHEMA": "viewgur_backend.graphql.schema",
    "MIDDLEWARE": [
        "viewgur_backend.graphql.DebugMiddleware",
        "viewgur_backend.graphql.RequestAuthInjectorMiddleware",
-    ],
+    ][::-1],
}

And now the output will be accurate

Debug Middleware
Request Auth Injector
  • What is the motivation / use case for changing the behavior?

It is confusing to anyone newbie (like I was just few mins ago) to find out the apparent nature

  • Please tell us about your environment:

    • Version: v3.3
    • Platform: Linux
@gencurrent
Copy link

@tbhaxor
Perhaps the issue is referred to graphene-django, isn't it?

@erikwrede erikwrede transferred this issue from graphql-python/graphene Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants