我是Aws Amplify和GraphQL的新手,我正在尝试找到处理以下问题的最佳方法:
我希望能够在前台编辑我的常见问题。前端从后端获取数据,我在前台编辑一个字段并保存,它应该存储在后端
我已经创建了一个简单的amplify graphql模式:
type FAQ @model(timestamps: null) {
id: ID!
sectionTitle: String
questionAndAnswer: [QuestionAndAnswer!]!
}
type QuestionAndAnswer {
id: ID!
question: String
answer: String
}然后我填充了它,使其包含以下数据:
{
"data": {
"listFAQS": {
"items": [
{
"sectionTitle": "Title2",
"id": "22735682-2bab-4695-b93e-1e50642d4654",
"questionAndAnswer": [
{
"answer": "answer4",
"id": "4",
"question": "question4"
},
{
"answer": "answer5",
"id": "5",
"question": "question5"
},
{
"answer": "answer6",
"id": "6",
"question": "question6"
}
]
},
{
"sectionTitle": "Title1",
"id": "21be8234-69f2-47fe-b942-d3e655197c70",
"questionAndAnswer": [
{
"answer": "answer1",
"id": "1",
"question": "question1"
},
{
"answer": "answer2",
"id": "2",
"question": "question2"
},
{
"answer": "answer3",
"id": "3",
"question": "question3"
}
]
}
]
}
}
}有没有一种简单的方法,我可以只改变例如问题"question4“,而不必发送整个常见问题”行“?
当我尝试它的时候,似乎整个数组都被重置了,只保存了新的数据。常见问题解答和QuestionAndAnswer是否都应该是@模型,我用@connection将它们连接起来,并根据需要分别更新它们?
发布于 2021-09-15 20:02:35
下面似乎是一种简单的方法,因为如果需要,您可以通过使用带有GraphQL突变的唯一ID来仅更新"question4“。
type FAQ @model(timestamps: null) {
id: ID!
sectionTitle: String
questionAndAnswer: [QuestionAndAnswer!]!
}
type QuestionAndAnswer @model {
id: ID!
question: Question
answer: Answer
}
type Question @model {
id: ID!
question: String
}
type Answer @model {
id: ID!
answer: String
}我没有包括@connections (它们应该在QuestionAndAnswer模型中),但是“FAQ和QuestionAndAnswer应该都是@模型吗?我用@connection连接它们,并根据需要分别更新它们?”
https://stackoverflow.com/questions/69194155
复制相似问题