首页 > 解决方案 > 跳过 Graphql 查询的 DRF 身份验证

问题描述

我正在尝试在我的 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 个查询没有身份验证检查。如何跳过该查询?

标签: djangoauthenticationdjango-rest-frameworkgraphqlgraphene-django

解决方案


推荐阅读