我可以使用 aws amplify 和 @auth 装饰器将 GraphQL 突变设为私有吗?这被认为是一种安全的方法吗?

Can I make GraphQL mutations private by using aws amplify and @auth decorator? Is that considered as a secured approach?

我正在使用 React 和 AWS 构建 post 办公应用程序。我目前正在构建我的 GraphQL API,我知道我可以在我的 graphQL 方案中使用 @auth 装饰器,这允许我根据他们的身份验证状态和组来阻止某些用户读取属性。

我想知道是否可以将这些@auth 规则添加到突变中?我的目的是防止不在 Admin 或 Worker 组中的用户访问我的 API 突变以删除包。如果不可能,什么是使特定突变只能由特定组访问的最佳方法(这些组存储在 AWS Coginto 用户投票中)?

实际上,您可以使用 @auth 指令将给定 @model 的突变访问限制为一组已知组。例如,要仅允许管理员和员工访问给定模型的删除操作,您可以尝试这样的操作:

type Package
  @model
  @auth(
    rules: [
      { allow: groups, groups: ["Admin", "Workers"], operations: [delete] }
    ]
  ) {
  id: ID!
}

此处,当调用API时,对于任何未注册到admin 或employee 组的用户,该操作将失败。查看 Static Group Authorization and Dynamic Group Authorization 上的文档了解更多信息。