Skip to content
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

chore(appsync): Correct VTL for aurora Serverless #15874

Merged
merged 3 commits into from
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ rdsDS.createResolver({
}
`),
responseMappingTemplate: MappingTemplate.fromString(`
$util.rds.toJsonObject($ctx.result)
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
`),
});

Expand All @@ -157,7 +157,7 @@ rdsDS.createResolver({
}
`),
responseMappingTemplate: MappingTemplate.fromString(`
$util.rds.toJsonObject($ctx.result)
$utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some explanation for these indices? Also, is there another solution that doesn't involve indices at all? (Using Array.filter(), for example).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otaviomacedo one would expect $utils.rds.toJsonObject($ctx.result) to correctly return the correct object, so that user wouldn't need to do the indices[1]. I don't have a proper way to test vtl, but what is in the index[0]? if in the vtl helper class we can remove whatever is in index 0, we can probably remove the usage of indices

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, @otaviomacedo Have you tested whatever is in the doc? The example in the doc uses mysql, but mine uses postgresql. There shouldn't be any difference but I want to make sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I hadn't seen that in the AppSync Tutorial they also use these indices without much in the way of an explanation. So we can leave it like this here, too.

Just FYI, in the mutation the first index refers to the statement you provided in the request mapping template. Since we want the result of the query, which is the second element of the statements array, we pass the index 1. And the result itself is a list of elements. But in this case we know this list has only one element (because we are querying by ID), so we select that element by passing the index 0.

`),
});
```
Expand Down