Skip to content

Instantly share code, notes, and snippets.


mvmocanu/ Secret

Created Aug 12, 2019
What would you like to do?
from django.utils.functional import cached_property
from gql.loaders import CommentsByArticleIdLoader
class GQLContext:
def __init__(self, request):
self.request = request
self.loaders = {
'comments_by_article_id_loader': CommentsByArticleIdLoader(),
def __call__(self):
for method_, instance in self.loaders.items():
setattr(self.request, method_, instance)
return self.request
from graphene_django.views import GraphQLView
from gql.context import GQLContext
class CustomGraphQLView(GraphQLView):
def get_context(self, request):
return GQLContext(request)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment