![](/img/trans.png)
[英]How to prevent losing production data when changing my GraphQL schema in AWS Amplify?
[英]AWS Amplify Graphql Schema, how to filter own data?
例如,考虑如下所述的 Comment 类型:
type Comment @model @auth(rules: [
{ allow: public, operations: [read]}
{ allow: owner }
]) {
id: ID!
text: String!
}
我的问题是所有者如何过滤自己的评论,我们可以在 Apmlify Auth 和 Amplify api 之间使用任何隐式关系,否则我将在架构中添加一个新字段
cognitoID @index(name:'byCognitoID', queryField: "commentByCognitoID")
谢谢
您必须创建字段才能建立关系:
type Comment @model @auth(rules: [
{ allow: owner }
{ allow: public, operations: [read]}
]) {
id: ID!
text: String!
owner: String @index(name: "commentsByOwner", queryField: "commentsByOwner")
}
然后使用:
amplify push
现在它将创建您的查询,您应该会看到一个名为 commentsByOwner 的查询。
我意识到这仍在您的架构中创建一个新属性,但我相信这是目前在不删除公共身份验证规则的情况下执行此操作的唯一方法。
https://docs.amplify.aws/cli-legacy/graphql-transformer/auth/#field-level-authorization
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.