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

Add get_context() to prepare a context object #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions channels_graphql_ws/graphql_ws_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,7 @@ async def _on_gql_start(self, op_id, payload):
variables = payload.get("variables", {})

# Prepare a context object.
context = DictAsObject({})
context.channels_scope = self.scope
context.channel_name = self.channel_name
context = self.get_context()
context.graphql_operation_name = op_name
context.graphql_operation_id = op_id

Expand Down Expand Up @@ -1230,6 +1228,14 @@ def _spawn_background_task(self, awaitable):
self._background_tasks.add(background_task)
return background_task

def get_context(self):
"""Prepare the context object to use during GraphQL execution."""
context = DictAsObject({})
context.channels_scope = self.scope
context.channel_name = self.channel_name
return context


@property
def _channel_layer(self):
"""Channel layer."""
Expand Down