【问题标题】:AppSync returns attribute values as null from AuroraDBAppSync 从 AuroraDB 返回属性值为 null
【发布时间】:2022-02-02 20:22:45
【问题描述】:

我正在尝试使用 Aurora RDS 实现 Appsync。获取查询返回所有属性值为空的响应。我认为它能够正确连接数据库,因为当我故意拼错表名时看到了一些错误。我不确定问题出在哪里。 我用 Dynamodb 尝试了相同的实现,效果很好。这是解析器的问题还是与权限相关的问题?

响应如下所示:

回复:

{
  "data": {
    "getTest": {
      "id": null,
      "name": null,
      "surname": null
    }
  }
}

数据库表描述:

id  int(11) 
name    text    
surname text

AppSync GraphQL 架构是:

 type Query {
    getTest(id: ID!): Test
}

type Test {
    id: ID
    name: String
    surname: String
}

schema {
    query: Query
}

请求解析器:

{
    "version": "2018-05-29",
    "statements": [
        "select * from TestTable where id = '$ctx.args.id'"
    ]
}

响应解析器:

#if($ctx.error)
    $utils.error($ctx.error.message, $ctx.error.type)
#end
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0])

【问题讨论】:

    标签: aws-appsync aws-aurora-serverless aws-appsync-resolver


    【解决方案1】:

    我能够解决我的问题。问题在于在响应解析器中引用结果。在结果对象中添加另一个 [0] 后它起作用了。

    #if($ctx.error)
        $utils.error($ctx.error.message, $ctx.error.type)
    #end
    $utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      相关资源
      最近更新 更多