How to use Graphene GraphQL framework with Django REST Framework authentication

后端 未结 2 1738
心在旅途
心在旅途 2020-12-24 02:55

I got some REST API endpoints in Django and I\'d like to use the same authentication for Graphene. The documentation does not provide any guidance.

2条回答
  •  长情又很酷
    2020-12-24 03:07

    Adding some additional steps that I had to take when following this integration:

    class RTGraphQLView(GraphQLView):
    
    def parse_body(self, request):
        if type(request) is rest_framework.request.Request:
            return request.data
        return super().parse_body(request)
    

    Graphene was expecting the .body attr but DRF reads it and attaches it to .data before being passed to GraphQLView.

提交回复
热议问题