在 Graphql 查询上跳过 DRF 身份验证

时间:2021-07-11 11:22:41

标签: django authentication django-rest-framework graphql graphene-django

我正在尝试在我的 Django 项目中在 GraphQl api 上添加我现有的身份验证。 我做了以下事情:

class DRFAuthenticatedGraphQLView(GraphQLView):
    @classmethod
    def as_view(cls, *args, **kwargs):
        view = super(DRFAuthenticatedGraphQLView, cls).as_view(*args, **kwargs)
        view = permission_classes((IsAuthenticated,))(view)
        view = authentication_classes((TokenAuthentication, ))(view)
        view = api_view(['POST','GET'])(view)
        return view

urlpatterns = [
    path('graphql', csrf_exempt(DRFAuthenticatedGraphQLView.as_view(graphiql=True)))
]

这会对 GraphQl 的所有突变和查询应用身份验证检查。

我希望 1 个查询没有身份验证检查。如何跳过该查询?

0 个答案:

没有答案
相关问题