【发布时间】:2018-11-15 07:59:47
【问题描述】:
我正在尝试为相关实体编写解析器。
这是我的架构的外观。
type User{
id:ID!
name: String!
posts:[Post] #Resolver 1
}
type Post{
id:ID!,
title: String!
body: String!
}
type CreatePostInput{
id:ID!,
title: String!
body: String!
}
type mutation{
addUserPost(userid:ID!, input:CreatePostInput!): Post
}
现在我为帖子添加了一个解析器(参见#resolver 1)
{
"version" : "2017-02-28",
"operation" : "Scan",
"key": {
"userid" : { "S" : "${context.source.id}" }
},
}
现在我为突变 addUserPost 添加了一个解析器
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key": {
"userid" : { "S" : "${context.arguments.userid}" },
"input" : $util.dynamodb.toDynamoDBJson(${context.arguments.input})
}
}
现在当我运行查询时
mutation addnewposttest{
addChapterToCourse(addUserPost:"c85a0508-ee0e-4ad8-8629-34880e1c6d74",
input:{
title:"Demo",
body:"Test Body",
id: "c85a0508-c85a0-508c-85a-0508"
}){
id
}
}
I get DynamoDB:AmazonDynamoDBException as One or more parameter values were invalid: Missing the key id in the item (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: XXXXXXXXXXXX
我尝试更改第二个解析器的数据源,但没有成功。除了 this 之外,我没有找到 AWS 的任何好的文档,但是这里讨论的是简单的字符串数据类型,而不是对象类型集合。
有人可以帮助我理解如何处理解析器中的关系吗?谢谢
【问题讨论】:
-
您在 addUserPost 的解析器中有
courseid。应该是userid? -
感谢@LisaMShon 指出,这里发帖时出现了一些复制粘贴错误。
-
我认为您的 #resolver1 模板也有误。
Scan操作不支持key元素
标签: amazon-web-services aws-appsync