aws / aws/aws-appsync-community
Numbers from DynamoDB results can't be converted to string
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
I have items coming from DynamoDB. When a field is a number then when I use something like ```ctx.result.num + ""``` the result is ```"null"```.
For example, I have a table with this item:
- id: {S: "1"}
- num: {N: "100"}
In the resolver, I get this item:
```
export function request(ctx) {
return {
version : "2018-05-29",
operation : "GetItem",
key : {
id : {S: "1"}
},
consistentRead : true
}
}
```
In the response handler, I try to convert the field to a string:
```
export function response(ctx) {
return {
res: ctx.result.num,
normal: ctx.result.num + "",
fixed: ctx.result.num + 0 + "",
}
}
```
The result I get:
```
{"res":100,"normal":"null","fixed":"100"}"
```
Both the ```typeof ctx.result.num``` and ```typeof (ctx.result.num + 0)``` yields ```number```, but there is clearly a difference between them.
A full reproduction example:
```
provider "aws" {
}
resource "random_id" "id" {
byte_length = 8
}
resource "aws_iam_role" "appsync" {
assume_role_policy = <
Contributor guide
Research direction
Start with the Terraform reproduction and the APPSYNC_JS resolver request and response handlers shown in the issue. Deploy it with terraform init and terraform apply, then run the MyQuery query to isolate the numeric string-coercion behavior. Done means the normal conversion of the DynamoDB number produces the expected string without the arithmetic workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, graphql, javascript, terraform
- Domain
- api, cloud, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100