【发布时间】:2020-04-22 02:46:00
【问题描述】:
我一直在关注此guide,以通过 AppSync 模式查询 Aurora Serverless 数据库。现在我想同时运行几个查询,请求映射如下:
{
"version": "2018-05-29",
"statements": [
"SELECT * FROM MyTable WHERE category='$ctx.args.category'",
"SELECT COUNT(*) FROM MyTable WHERE category='$ctx.args.category'",
]
}
那么,如何处理响应映射中的多个选择?该页面有几个示例,但没有一个有两个选择:
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0]) ## For first item results
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0]) ## For first item of first query
$utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0]) ## For first item of second query
$utils.toJson($utils.rds.toJsonObject($ctx.result)??????) ## ?? For first & second item results
我预测响应类型如下,但不严格,只要我能得到值。
type MyResponse {
MyResponseItemList [MyResponseItem]
Count Int
}
type MyResponseItem {
Id: ID!
Name: String
...
}
【问题讨论】:
-
我可以在 GraphQL 中查看您的响应类型吗?
-
您可以建议任何结构以产生所需的输出,即列表项和计数。但我已经编辑分享了我认为它会是什么样子。
标签: amazon-web-services amazon-rds aws-appsync vtl