amazon-web-services - AppSync - creating nested mutation with array and objects?
问题描述
Does AppSync support nested single mutation?
I want to call a single mutation which will insert records into two tables, eg: User
and Roles
tables in DynamoDB.
Something like this for example:
createUser(
input: {
Name: "John"
Email: "user@domain.com"
LinesRoles: [
{ Name: "Role 1" }
{ Name: "Role 2" }
]
}) {
Id
Name
LinesRoles {
Id
Name
}
}
Do I need to create two resolvers in AppSync for User
and Roles
to insert the records in both tables?
解决方案
我可以想到三种方法来实现这一点:
- 使用BatchPutItem一次将记录保存到两个表中。但是,您将无法使用任何
ConditionExpression
- 使用具有两个 AppSync 函数的管道解析器,其中一个函数将 PutItem 生成到
Roles
表中,另一个生成到User
表中。但是,您需要对可能不一致的情况感到满意,即记录已插入到一个表中但未插入另一个表中。 - 使用Lambda解析器在 DynamoDB 事务中写入 2 个表。
推荐阅读
- flutter - Flutter:AudioPlayer 停止多个声音
- docker - Docker 状态退出 (2)
- excel - Excel VBA 相当于单击插入->形状->自由形式:形状
- powerbi - dax 聚合总和和计数,仅忽略过滤器上下文的某些部分
- c# - 试图理解为什么在这种情况下会发生 EF Core InvalidOperationException
- sage - 从 Sage 详细输出中提取值
- javascript - 使用 js/jquery 将数据值从内部函数传递到内部函数
- reactjs - setInterval 中的 setState 未按预期工作。任何想法为什么?
- python - 将一系列字符串转换为数组并替换值
- sharepoint - MS Graph API 共享点 GetDriveItem