【问题标题】:Why am i only seeing 1 record not 2 records?为什么我只看到 1 条记录而不是 2 条记录?
【发布时间】:2019-08-14 14:16:56
【问题描述】:

当有 2 条记录时,我只看到 1 条记录。

解析器响应映射部分是 $utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])

我想如果我改变:

    $utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])

到:

    $utils.toJson($utils.rds.toJsonObject($ctx.result)[0][1])

我得到了第二条记录,但没有得到第一条记录?

Resolver for Query.getdpackByind_subcat, Request mapping template
{
    "version": "2018-05-29",
    "statements": [
        "select * from dpack WHERE ind = '$ctx.args.ind' AND subcat = 
         '$ctx.args.subcat'"
    ]
}

Resolver for Query.getdpackByind_subcat, Response mapping template
#if($ctx.error)
    $utils.error($ctx.error.message, $ctx.error.type)
#end
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])

此信息来自:

https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-rds- 
resolvers.html the Query.getPet Resolvers

In the CloudWatch log at the bottom of the Response mapping section
,indicated by the `_____->`, 2 records are returned. However, only 1 was 
Transformed, indicated by the `*******>`, why? 

"____>records\":[[{\"stringValue\"
:\"bb973271-0091-4b0e-84c4-f1b50fe6517e\"}, 
{\"stringValue\":\"Government\"},{\"stringValue\":\"Police 
Surveillance\"},{\"stringValue\":\"20 pixs\"},{\"longValue\":700}, 
{\"stringValue\":\"service 20 pixs\"},{\"blobValue\":\"Yi5qcGc=\"}], 
[{\"stringValue\":\"d219d0f8-aef7-4a17-bcaf-85504f56494a\"}, 
{\"stringValue\":\"Government\"},{\"stringValue\":\"Police 
Surveillance\"},{\"stringValue\":\"15 picks\"},{\"longValue\":500}, 
{\"stringValue\":\"service 15 picks\"}, 
{\"blobValue\":\"YS5qcGc=\"}]]}]}","stash": {},"outErrors": []},

 *******>"transformedTemplate": "\n{\"pack_id\"
 :\"bb973271-0091-4b0e-84c4- 
 f1b50fe6517e\",\"price\":700,\"subcat\":\"Police 
 Surveillance\",\"pack_title\":\"service 20 
 pixs\",\"ind\":\"Government\",\"content\":\"20 
 pixs\",\"picture\":\"Yi5qcGc=\"}"

谢谢

【问题讨论】:

  • 抱歉,但不太可能有人会通读您的整个问题以试图弄清楚您在做什么。有什么方法可以缩短您的问题,以专注于导致您遇到困难的特定问题或代码部分?有关提出好问题的提示,请参阅:How do I ask a good question?
  • 你能分享更多关于你的数据源的信息吗?碰巧是 DynamoDB 吗?
  • 极光通过 appsync

标签: aws-appsync resolver


【解决方案1】:

看起来您的查询结果是一个列表。

因此$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0]) 对应于列表的第一项,因此只返回一项。

要返回整个列表,您应该删除第二个数组索引。查看 Appsync RDS 教程中Query.listPet 的响应映射模板以获取示例。

Tutorial: Aurora Serverless

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多