Do you want to request a feature or report a bug?
Bug
What is the current behavior?
AWSJSON fields arriving on a subscription are double encoded.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Layout:
Schema:
type Message {
event: AWSJSON!
}
type Mutation {
createMessage(event: AWSJSON!): Message
}
type Subscription {
subscribeToNewMessage(): Message @aws_subscribe(mutations: ["createMessage"])
}
Pipeline Resolver attached to createMessage mutation
Before Mapping template:
$util.qr($ctx.stash.put("source", "ourSource"))
{}
After Mapping Template
`
$util.toJson($context.result)
`
One function in the pipeline
Request Mapping:
{
"version": "2017-02-28",
"payload": {
"event": $util.toJson($context.arguments.event)
}
}
Response Mapping:
$util.toJson($ctx.result)
What is the expected behavior?
Single encoding of AWSJSON on a subscription as per previous versions
Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?
Happening on Chrome in macOS 10.15
The issue only presented itself after moving from aws-appsync 1.8.1 -> 3.0.2
Worked in 1.8.1
In 1.8.1 the 'event' JSON appeared as:
{"id":"w3VFb03WGK","version":"v2","timestamp":1583838183535}
In 3.0.2 the 'event' JSON appears as:
"{\"id\":\"5SEt78RoYx\",\"version\":\"v2\",\"timestamp\":1583837494973}"
With no changes to the underlying appsync API
Curious if you are still getting this error? I had an application break overnight even though the code hasn't been touched in ages, and in debugging it, the error is where we were doing a double decode to work around this issue:
const payload = JSON.parse(JSON.parse(_payload))
Contrived debug example shows that the error is being caused by the double decode now, and a single decode seems to work as expected:

We are seeing the same.
Interesting. That implies to me that it鈥檚 probably on the AppSync side rather than this lib. I wonder if there鈥檚 an AWS AppSync changelog/etc type entry somewhere that explains/ ores the change.
Most helpful comment
We are seeing the same.