-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$util.map.copyAndRemoveAllKeys is not working #106
Comments
@yukitaka13-1110 This is a known issue in amplify-cli I have noticed it too and haven't had time to fix it. It happens because In the meantime, here is the workaround I use:
|
@bboure Thank you for your response! Additionally, I found
Do you have any idea about this? |
@bboure I confirmed my code worked correctly in AppSync console query. |
@bboure Sample code. #set($obj = {})
#set($count = -1)
#set($count = $obj.size()) Local simulator: Missing request mapping template errror |
Thanks @yukitaka13-1110 I know by experience that empty templates don't work, but I thought it was an AppSync, not simulator. I will have a try at this. In any case, that would also be an issue in |
@bboure I found node version v16.0.0 caused this error. See this. #set($records = [
{ "id": "id-001"},
{ "id": "id-002"},
{ "id": "id-001"},
{ "id": "id-002"},
])
#set($obj = {})
#foreach($record in $records)
#if($util.isNull($obj[$record.id]))
$util.qr($obj.put($record.id, 1))
#else
#set($count = $obj[$record.id] + 1)
$util.qr($obj.put($record.id, $count))
#end
#end
## $obj = \":{\"id-001\":1,\"id-002\":1}
## $obj.size() -> 4 but expected 2 I think this occurs when put same key twice. #set($records = [
{ "id": "id-001"},
{ "id": "id-002"},
])
#set($obj = {})
#foreach($record in $records)
#if($util.isNull($obj[$record.id]))
$util.qr($obj.put($record.id, 1))
#else
#set($count = $obj[$record.id] + 1)
$util.qr($obj.put($record.id, $count))
#end
#end
## $obj = \":{\"id-001\":1,\"id-002\":1}
## $obj.size() -> 2 expected 2 |
@bboure In AppSync console, I got expected result. #set($records = [
{ "id": "id-001"},
{ "id": "id-002"},
{ "id": "id-001"},
{ "id": "id-002"}
])
#set($obj = {})
#foreach($record in $records)
#if($util.isNull($obj[$record.id]))
$util.qr($obj.put($record.id, 1))
#else
#set($count = $obj[$record.id] + 1)
$util.qr($obj.put($record.id, $count))
#end
#end
#set($count = $obj.size())
#set($result = { "obj": $obj, "count": $count })
$util.error($util.toJson($result), "debug")
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I'm developing appsync with serverless-framewrok.
I use dynamodb so I implemented vtl resolver files.
But
copyAndRemoveAllKeys
is not working.See the following example code.
This is a
respose.vtl
code.This always returns null and no error occurred.
I deployed this code and query it.
Unfortunately, I could retrieve expected response, not null.
query
AppSync console result
Local AppSync Simulator
Is this bug?
Environment
The text was updated successfully, but these errors were encountered: