In Graphene Python, how should one go about setting cookies in the schema.py
when there is no access to the HttpResponse
object to set the cookie on?
My current implementation is to set the cookie by overriding the GraphQLView's dispatch method by catching the data.operationName
. This involves hard-coding of the operation names / mutations that I need cookies to be set on.
In views.py:
class PrivateGraphQLView(GraphQLView):
data = self.parse_body(request)
operation_name = data.get('operationName')
# hard-coding === not pretty.
if operation_name in ['loginUser', 'createUser']:
...
response.set_cookie(...)
return response
Is there a cleaner way of setting cookies for specific Graphene Python mutations?