我有突变。如何使用 graphql 查询中的变量在 hasura 中创建权限?
例如:
mutation MyMutation($name:String!) {
insert_post(objects: {name:$name}){
name
}
}
如何在权限中使用
name
变量?
Hasura v2 现在允许这种模式。
例如,如果您有一个包含允许名称列表的表, 您可以检查正在插入的名称是否在列表中 通过执行以下操作来允许名称:
insert_permissions:
- role: user
permission:
check:
_exists:
_table:
name: allowed_names
schema: public
_where:
name:
_ceq: ["$", "name"]
另请参阅:
https://github.com/hasura/graphql-engine/issues/3459#issuecomment-1085666541
https://hasura.io/docs/latest/graphql/core/api-reference/syntax-defs/
只是为了有人有同样的问题。目前,Hasura 不支持检查用户输入值的权限,它只接受来自
session variables
的值,如 x-hasura-user-id
等
但我认为当不允许根据用户输入设置权限时,Hasura 方法是正确的。