Skip to content

Commit 1c96ff4

Browse files
committed
Add get_context() to prepare a context object
1 parent 09a2ffd commit 1c96ff4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

channels_graphql_ws/graphql_ws_consumer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,7 @@ async def _on_gql_start(self, op_id, payload):
535535
variables = payload.get("variables", {})
536536

537537
# Prepare a context object.
538-
context = DictAsObject({})
539-
context.channels_scope = self.scope
540-
context.channel_name = self.channel_name
538+
context = self.get_context()
541539
context.graphql_operation_name = op_name
542540
context.graphql_operation_id = op_id
543541

@@ -1230,6 +1228,14 @@ def _spawn_background_task(self, awaitable):
12301228
self._background_tasks.add(background_task)
12311229
return background_task
12321230

1231+
def get_context(self):
1232+
"""Prepare the context object to use during GraphQL execution."""
1233+
context = DictAsObject({})
1234+
context.channels_scope = self.scope
1235+
context.channel_name = self.channel_name
1236+
return context
1237+
1238+
12331239
@property
12341240
def _channel_layer(self):
12351241
"""Channel layer."""

0 commit comments

Comments
 (0)