【发布时间】:2019-12-27 07:39:46
【问题描述】:
input CarInput{
name: String
brand: String
}
type Car{
id: ID
name: String
brand: String
}
type Vehicle{
id: ID
carId: Id
}
type CustomResponse{
createdCar : Car
allCars: [Car]
}
type Mutation {
createCar(input: CarInput): CustomResponse
}
createCar
的附加管道解析器映射模板之前
{}
1 - CreateCarFunction
请求映射模板
{
"version" : "2017-02-28",
"operation": "Invoke",
"payload":{
"body":$util.toJson($context.args.input),
"resource":"/car",
"httpmethod":"POST"
}
}
响应映射模板
$context.result.body
2 - CreateVehicleFunction
请求映射模板
{
"version" : "2017-02-28",
"operation": "Invoke",
"payload":{
"body":$util.toJson($ctx.prev.result.id),
"resource":"/vehicle",
"httpmethod":"POST"
}
}
响应映射模板
$context.result.body
3 - GetCarsFunction
请求映射模板
{
"version" : "2017-02-28",
"operation": "Invoke",
"payload": {
"body":"",
"resource":"/getCars" ,
"httpmethod":"GET"
}
}
响应映射模板
$context.result.body
映射后模板
$util.toJson($ctx.result)
数据源是Lamda。我会从 CreateCarFunction、CreateVehicleFunction 和 GetCarsFunction 得到三种不同的响应。
mutation{createCar(input:
{
name: "A6"
brand: "Audi"
})
{
createdCar
{
id
name
brand
}
allCars
{
id
name
brand
}
}
我想要这样的回应
{
"data": {
"createCar": {
"createdCar ": {
id : "2"
name : "A6"
brand : "Audi"
},
"allCars": [
{
id : "1"
name : "S"
brand : "Benz"
},
{
id : "2"
name : "A6"
brand : "Audi"
}
]
}
}
所以我需要 CreateCarFunction 和 GetCarsFunction 的响应,以便将 CustomResponse 类型填充为输出。我如何做到这一点?
【问题讨论】:
标签: aws-appsync