AWS Amplify GraphqlSchema,如何过滤自己的数据



例如,考虑下面描述的注释类型:

type Comment @model  @auth(rules: [
{ allow: public, operations: [read]}
{ allow: owner }
]) {
id: ID!
text: String!
}

我的问题是所有者如何过滤自己的评论,在Apmlify Auth&放大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-级别授权

最新更新