在Hasura中如何在权限中使用graphql变量?

问题描述 投票:0回答:2

我有突变。如何使用 graphql 查询中的变量在 hasura 中创建权限?

例如:

mutation MyMutation($name:String!) {
  insert_post(objects: {name:$name}){
    name
  }
}

如何在权限中使用

name
变量?

graphql hasura graphql-mutation
2个回答
1
投票

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/


0
投票

只是为了有人有同样的问题。目前,Hasura 不支持检查用户输入值的权限,它只接受来自

session variables
的值,如
x-hasura-user-id

但我认为当不允许根据用户输入设置权限时,Hasura 方法是正确的。

© www.soinside.com 2019 - 2024. All rights reserved.