From 625e82ba9ba8449639fff4bf8b2293eb01eb9791 Mon Sep 17 00:00:00 2001 From: Chris Beaven Date: Thu, 16 Dec 2021 16:47:15 +1300 Subject: [PATCH] Add middleware to the graphql params from the graphene django settings --- graphql_ws/django/subscriptions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/graphql_ws/django/subscriptions.py b/graphql_ws/django/subscriptions.py index 086445f..372360f 100644 --- a/graphql_ws/django/subscriptions.py +++ b/graphql_ws/django/subscriptions.py @@ -7,7 +7,7 @@ class ChannelsConnectionContext(BaseAsyncConnectionContext): def __init__(self, *args, **kwargs): - super(ChannelsConnectionContext, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.socket_closed = False async def send(self, data): @@ -35,5 +35,11 @@ async def handle(self, ws, request_context=None): await self.on_open(connection_context) return connection_context + def get_graphql_params(self, connection_context, payload): + params = super().get_graphql_params(connection_context, payload) + if graphene_settings.MIDDLEWARE: + params["middleware"] = graphene_settings.MIDDLEWARE + return params + subscription_server = ChannelsSubscriptionServer(schema=graphene_settings.SCHEMA)