【发布时间】:2022-01-23 01:04:41
【问题描述】:
我正在尝试将我的 GraphQL Web API 与 AppSync 集成。但我收到以下错误
"errorType": "MappingTemplate",
"message": "Template transformation yielded an empty response."
我的数据源 HTTP 端点是:https://mybooking123.com
我的查询是:
mutation
{
Booking(ID:111,BusNumber:"AAAA1", comment:"None")
{
BusNumber
PassngerName
TravelDate
TravelTime
ValidityDate
ValidaityTime
ErrorCode
}
}: [BookingResponse]
架构
type Mutation {
Booking(
ID: Int!,
BusNumber: String,
comment: String
): [BookingResponse]
}
type BookingResponse
{
BusNumber: String
PassngerName: String
BookingDate: String
BookingTime: String
ValidityDate: String
ValidaityTime: String
ErrorCode: Int
}
AppSync - 请求映射模板
{
"version": "2018-05-29",
"method": "POST",
"resourcePath": "/GraphQL",
"params":{
"query":$util.toJson($ctx.args),
"headers": {
"Authorization": "$ctx.request.headers.Authorization"
}
}
}
AppSync - 响应映射模板
## 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)
#set($body = $util.parseJson($ctx.result.body))
$util.toJson($body) ##make it $body.data depending on the return on your rest api
#else
$utils.appendError($ctx.result.body, "$ctx.result.statusCode")
#end
我的 GraphQL API 不使用 AppSync。但我想实现 AppSync 来访问 GraphQL API。我不确定模板映射有什么问题。感谢您的帮助。
【问题讨论】:
标签: c# graphql aws-appsync webapi vtl