通过突变连接到另一个对象来创建对象的最佳实践是什么。
使用以下架构:
type Question @model {
id: ID!
text: String!
answers: [Answer] @connection(name: "QuestionAnswers")
}
type Answer @model {
id: ID!
text: String!
question: Question @connection(name: "QuestionAnswers")
}
以下(及其变体)失败:
mutation CreateAnswer {
createAnswer(input: {
text:"Yes",
question: {
id: "9d38c759-6b64-4c1f-9e0e-d3b95a72b3a8"
}
})
{
id
}
}
服务器端代码:
mutation CreateAnswer($input: CreateAnswerInput!) {
createAnswer(input: $input) {
id
text
question {
id
text
answers {
nextToken
}
}
}
}
以上所述,收到以下错误:
“ WrongType类型的验证错误:参数'input'具有值 'ObjectValue {objectFields = [ObjectField {name ='text', value = StringValue {value ='3'}},ObjectField {name ='question', value = ObjectValue {objectFields = [ObjectField {name ='id', value = StringValue {value ='9d38c759-6b64-4c1f-9e0e-d3b95a72b3a8'}}}}]}}' 包含不在'CreateAnswerInput'中的字段:'question'@ 'createAnswer'“
答案 0 :(得分:-1)
似乎这可能是AppSync中的命名约定。以下为我工作:
mutation createAnswer {
createAnswer (input: {
text: "5"
answerQuestionId: "9d38c759-6b64-4c1f-9e0e-d3b95a72b3a8"
}) {
id
}
需要为<{1}添加 answer 。