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

GraphQlView: Do not 'instantiate_middleware' if middleware is already a MiddlewareManager #952

Merged
merged 1 commit into from
May 9, 2020

Conversation

msimon
Copy link
Contributor

@msimon msimon commented Apr 30, 2020

In graphq-core 2, the MiddlewareManager can have a wrap_in_promise boolean passed to activate/deactivate wrapping the middleware's result into a promise. This has a big performance impact on large requests.
https://github.com/graphql-python/graphql-core-legacy/blob/52e030bbc6001fd378515600f81ccea0e360131b/graphql/execution/middleware.py#L25

The executor is instantiating the middleware as a MiddlewareManager if it's anything else than already a MiddlewareManager:
https://github.com/graphql-python/graphql-core-legacy/blob/52e030bbc6001fd378515600f81ccea0e360131b/graphql/execution/executor.py#L102

So in graphene_django/views.py by always converting middleware into a list, it breaks the ability to passe the argument to the MiddlewareManager and always default to wrap_in_promise=True.

This PR simply checks if the middleware is already a MiddlewareManager and pass it without pre-processing, allowing the end-user to define it themselves.

Copy link
Member

@jkimbo jkimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @msimon

@jkimbo jkimbo merged commit 975f45e into graphql-python:master May 9, 2020
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

Successfully merging this pull request may close these issues.

2 participants