Skip to content

Commit b963595

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

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

channels_graphql_ws/graphql_ws_consumer.py

Lines changed: 11 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,16 @@ def _spawn_background_task(self, awaitable):
12301228
self._background_tasks.add(background_task)
12311229
return background_task
12321230

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

0 commit comments

Comments
 (0)