datadvance / DjangoChannelsGraphqlWs

Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
MIT License
281 stars 84 forks source link

Add get_context() to prepare a context object #111

Open cpd67 opened 1 year ago

cpd67 commented 1 year ago

Hello! This PR refs #104. It adds a new get_context() method on the GraphqlWsClient which can be overridden to inject values into the context. Usage would be similar to how you add things to a Django view's context:

def get_context(self):
    context = super().get_context()
    context.user = self.scope.get('user')
    context.other_attr = 'test'
    return context