Closed adamcharnock closed 8 years ago
One way to do this is to subclass GraphQLView and override get_root_value to return request.user. Which would put it into info.root_value in your resolver.
I plan on making the entire request object available in info though. Should land later today.
class CurrentUserRootValueGraphQLView(GraphQLView):
def get_root_value(self, request):
return request.user
graphql_view = csrf_exempt(CurrentUserRootValueGraphQLView.as_view(
schema=schema
))
That is brilliant, thanks very much!
I am creating a new model within a mutation. I would like to set the model's
created_by
field to point to the current user (usingrequest.user
). However, AFAIK the request object is not available within a mutation'smutate_and_get_payload()
method.Note: It is entirely possible that I'm going about this the wrong way, I'm still new to GraphQL.