0

我正在尝试在 AWS App Sync 中学习 graphql,作为其中的一部分,我们编写了架构并附加了 Http Endpoint Resolver,我在其中从 rest 获取数据,这是一个 GET 调用,但在将响应从 rest 端点映射到 graphql 时遇到问题无法在“查询”选项卡的响应中查看它

schema
------
type Query {
 getDetails(id:ID):User
}

type User
{
details: Contact
}

type Contact
{
name: String
address: String
}

Resolver Request Template
----------------
{
    "version": "2018-05-29",
    "method": "GET",
    "params": {
        "headers": {
            "Content-Type": "application/json"
        }
    },
    "resourcePath": $util.toJson("/customer/${ctx.args.id}/details")
}

resolver response template
----------------------
## Raise a GraphQL field error in case of a datasource invocation error
#if($ctx.error)
  $util.error($ctx.error.message, $ctx.error.type)
#end
## If the response is not 200 then return an error. Else return the body **
#if($ctx.result.statusCode == 200)
$ctx.result.body
#else
    $utils.appendError($ctx.result.body, "$ctx.result.statusCode")
#end

我尝试了多种方法,但无法将响应正文转换为用户。我也尝试使用 $util.parseJson(String)

4

0 回答 0