From e74836dc5e12821bc934e041e5b1668673a9b87f Mon Sep 17 00:00:00 2001 From: Chris Dilley Date: Tue, 15 Aug 2023 15:49:21 -0400 Subject: [PATCH] Add get_context() to prepare a context object --- channels_graphql_ws/graphql_ws_consumer.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/channels_graphql_ws/graphql_ws_consumer.py b/channels_graphql_ws/graphql_ws_consumer.py index 9af6c83..bed1a82 100644 --- a/channels_graphql_ws/graphql_ws_consumer.py +++ b/channels_graphql_ws/graphql_ws_consumer.py @@ -540,6 +540,7 @@ async def _on_gql_start(self, op_id, payload): context.channel_name = self.channel_name context.graphql_operation_name = op_name context.graphql_operation_id = op_id + context = self.get_context(context) # Process the request with Graphene and GraphQL-core. doc_ast, op_ast, errors = await self._on_gql_start__parse_query( @@ -1230,6 +1231,12 @@ def _spawn_background_task(self, awaitable): self._background_tasks.add(background_task) return background_task + def get_context(self, context): + """ + Prepare the context object to use during GraphQL execution. + """ + return context + @property def _channel_layer(self): """Channel layer."""