我正在使用Django和GraphQL(graphenedjango)创建一个API。为了验证用户,我使用JWT(https://django-graphql-jwt.domake.io/en/latest/)。接下来,我也使用继电器
现在,在查询和转换中处理权限的最佳方法是什么?假设我有两个模型(Products
和Transactions
)。普通用户可以对products
进行查询和变异Transactions
但是应该限制,并且只能由管理员/员工访问
在Graphene Django网页(https://docs.graphene-python.org/projects/django/en/latest/authorization/)上,他们(除其他外)讨论了以下两个选项:
def get_queryset(cls, queryset, info)
-可以在此处检查授权(使用:if info.context.user.is_anonymous:
raise GraphQLError('You do not have permission to access this information')
return queryset
)?对于突变,我们可以在mutate_and_get_payload
中做类似的事情
目前没有回答
相关问题 更多 >
编程相关推荐