我在 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 key 进行读取访问,除了“作者”字段。它应该只能由所有者和“管理员”组读取。 我已经尝试了顶级和字段级 @auth 指令的各种组合,但它不起作用。 有谁知道如何解决这个问题。 谢谢
最佳答案
您是否尝试过使用 Field Level Authorization ?
type User @model {
id: ID!
username: String
ssn: String @auth(rules: [{ allow: owner, ownerField: "username" }])
}
更新:我的错误,在你的问题中它确实说你试过了。
关于graphql - 如何防止访问 Amplify graphql 公共(public) API 中的某些字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63513047/