如何防止访问Amplify graphql公共API中的某些字段

问题描述

我在Amplify中有一个graphql模型,如下所示:

type Blog @model @auth(rules: [
    { allow: owner },{ allow: groups,groups: ["admins"] },{ allow: public,provider: apiKey,operations: [read] }
    ]){
    id: ID!
    title: String!
    content: String!
    author: String
}

我希望所有字段都可以通过API密钥进行读取访问,但“作者”字段除外。该字段只能由所有者和“管理员”组读取。 我尝试了顶级和字段级@auth指令的各种组合,但是它不起作用。 有谁知道如何解决这个问题。 谢谢

解决方法

您是否尝试过使用 Field Level Authorization

type User @model {
  id: ID!
  username: String
  ssn: String @auth(rules: [{ allow: owner,ownerField: "username" }])
}

更新:我的错误,在你的问题中确实说你试过了。