我正在使用此 AppSync 解析器映射模板来更新用户:
{
"version": "2018-05-29",
"method": "PATCH",
"params": {
"headers": {
"Content-Type": "application/json"
},
"body": $utils.toJson(${context.arguments.input})
},
"resourcePath": $utils.toJson("/users/${context.arguments.input.id}")
}
后端的服务接受PATCH
更新用户的请求。
当我运行突变时,出现此错误:An internal failure occurred while resolving this field.
这是请求映射和响应映射的 CloudWatch 日志:
{
"logType": "RequestMapping",
"path": [
"updateUser"
],
"fieldName": "updateUser",
"resolverArn": "arn:aws:appsync:us-east-1:xxxxxx:apis/xxxxx/types/Mutation/resolvers/updateUser",
"requestId": "xxxxxx",
"context": {
"arguments": {
"input": {
"id": "user1",
"firstName": "John"
}
},
"stash": {},
"outErrors": []
},
"fieldInError": false,
"errors": [],
"parentType": "Mutation",
"graphQLAPIId": "xxxxxx",
"transformedTemplate": "{\n \"version\": \"2018-05-29\",\n \"method\": \"PATCH\",\n \"params\": {\n \"headers\": {\n \"Content-Type\": \"application/json\"\n },\n \"body\": {\"id\":\"user1\",\"firstName\":\"John\"}\n },\n \"resourcePath\": \"/users/user1\"\n}"
}
{
"logType": "ResponseMapping",
"path": [
"updateUser"
],
"fieldName": "updateUser",
"resolverArn": "arn:aws:appsync:us-east-1:xxxxx:apis/xxxxx/types/Mutation/resolvers/updateUser",
"requestId": "xxxxxx",
"context": {
"arguments": {
"input": {
"id": "user1",
"firstName": "John"
}
},
"stash": {},
"error": {
"message": "An internal failure occurred while resolving this field.",
"type": "InternalFailure"
},
"outErrors": []
},
"fieldInError": true,
"errors": [
"CustomTemplateException(message=A custom error was thrown from a mapping template., errorType=$context.result.statusCode, data=null, errorInfo=null)"
],
"parentType": "Mutation",
"graphQLAPIId": "xxxxxx"
}
请求不会转发到后端服务(我正在监视传入的请求),但是如果我将映射中的方法更改为POST
或者PUT
我可以看到请求到达服务。
我有其他需要PATCH
方法的请求,他们也有同样的问题。我是否在PATCH
请求的解析器中遗漏了某些内容,或者这是 AppSync 错误?