【发布时间】:2022-10-16 20:19:51
【问题描述】:
所以我目前正在使用 AWS AppSync 和 Amplify,一切都很好,除了使用新的 Transformer V2,我很难让事情正常工作。
这是我的架构:
type Post
@model
@auth(
rules: [
{ allow: owner, ownerField: "username" }
{ allow: public, operations: [read] }
]
) {
id: ID!
title: String!
content: String!
username: String
@index(name: "postsByUsername", queryField: "postsByUsername")
coverImage: String
comments: [Comment] @hasMany
}
type Comment
@model
@auth(
rules: [
{ allow: owner, ownerField: "createdBy" }
{ allow: public, operations: [read] }
]
) {
id: ID!
message: String
}
我可以创建帖子和评论。但是,每当我查询帖子列表时,我从来没有得到 cmets。
下面是一个查询示例:
query MyQuery {
listPosts {
items {
comments {
items {
id
message
createdAt
}
}
content
title
username
}
}
}
这是我得到的相应结果:
{
"data": {
"listPosts": {
"items": [
{
"comments": {
"items": []
},
"content": "Testing stuff",
"title": "Today is the day",
"username": "bawp"
},
{
"comments": {
"items": []
},
"content": "### hello\n````\n function call()\n```",
"title": "next item of the day",
"username": "paulod"
},
{
"comments": {
"items": []
},
"content": "Hello Word",
"title": "santo dia",
"username": "paulod"
}
]
}
}
}
注意如何
"comments": {
"items": []
},
它总是空的!
尽管如此,当我查询 Comments 表时,我至少添加了一条评论。
query MyQuery {
listComments {
items {
id
message
createdBy
}
}
}
结果:
{
"data": {
"listComments": {
"items": [
{
"id": "ddddf58b-df1c-498c-97b4-6d61361b4b9e",
"message": "Thjis is may coment here\n\n```\nCode could go here also!\n```",
"createdBy": "paulod"
}
]
}
}
}
我不确定我在这里缺少什么。请记住,我使用的是新指令(Transformer v2),而不是旧的关系指令,例如
@connection
任何帮助是极大的赞赏。
非常感谢!
【问题讨论】:
标签: amazon-web-services relationship amplify