Amazon web services 用于更新的相关表的AWS Appsync解析器
我正在尝试为相关实体编写一个解析器 下面是我的模式的外观Amazon web services 用于更新的相关表的AWS Appsync解析器,amazon-web-services,aws-appsync,Amazon Web Services,Aws Appsync,我正在尝试为相关实体编写一个解析器 下面是我的模式的外观 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:Crea
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
}
现在我为POST添加了一个解析器(请参见#解析器1),如下所示
现在我为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
}
}
我得到DynamoDB:amazondynamodexception,因为一个或多个参数值无效:缺少项中的键id(服务:amazondynamodv2;状态代码:400;错误代码:ValidationException;请求id:XXXXXXXXXXXX)
我尝试更改第二个解析器的数据源,但没有成功。除了,我没有找到任何好的AWS文档,但这里讨论的是简单的字符串数据类型,而不是对象类型集合
有人能帮我理解,如何处理解析器中的关系吗?谢谢,正如我所评论的,您有一些更新要做
但主要的问题是,addUserPost的解析器模板包含
用户id
,但您需要将其更改为id
。您的用户类型或帖子类型似乎没有名为用户id
的字段。我指的是两个单独的数据表,并将数据存储在我们需要的两个表中e BatchUpdate项并指定表名。但是,我不能这样做,因为在我的用例中,我必须在一个表中插入并在另一个表中更新
最后,我将Id复制到另一个集合中,并在其上建立索引
这就是我最终的模式
type User{
id:ID!
name: String!
posts:[Post] #Resolver 1 -
}
type Post{
id:ID!,
userId:ID!# I will look for source.id on this field
title: String!
body: String!
}
感谢大家的参与!您在addUserPost的解析程序中有
courseid
。应该是userid
?感谢@LisaMShon指出,在这里发布时出现了一些复制粘贴错误。我想您的#resolver1的模板也是错误的。Scan
操作不支持键ementThanks谢谢你的回复。看这篇文章,我只是遵循了这一点。userid对应于变异的参数(键)。现在我学到了艰难的方法,这只适用于这两个实体位于同一个表中并且具有相同的数据源的情况。
type User{
id:ID!
name: String!
posts:[Post] #Resolver 1 -
}
type Post{
id:ID!,
userId:ID!# I will look for source.id on this field
title: String!
body: String!
}