aws-appsync-community icon indicating copy to clipboard operation
aws-appsync-community copied to clipboard

Allow VTL templates to define and use macros

Open davidmessem opened this issue 5 years ago • 7 comments
trafficstars

I unsuccessfully tried to make use of the VTL standard macro functionality. Below is an example of what I would like to do

#macro( escape $string )
  $string.replaceAll("'", "''").replaceAll...
#end

#set($safeName = "#escape($name)")

I have read on the AWS forums that most standard tools and macros are blocked. Is there a particular reason for this? Can macros be allowed?

davidmessem avatar Mar 18 '20 09:03 davidmessem

I also have this issue. I would like to use a math.random() function into my mock response for API Gateway and am unable to do so.

hheavener-kyd avatar Mar 19 '20 18:03 hheavener-kyd

Thank you for the feedback! This is a feature request, we have heard this request in the past and I will +1 it internally on your behalf. As with all feature requests, I cannot comment on the eventual availability.

itrestian avatar Apr 20 '20 17:04 itrestian

Any news about this request? Or availability is still unknown? This could significantly shorten some resolvers and that's an important thing as there is a mapping templates size limit.

Sunac avatar Oct 14 '20 07:10 Sunac

Are there any updates to this request? This would be of great use to us as well!

jkruse14 avatar Sep 03 '21 19:09 jkruse14

2 years since this request. Any updates please?

reply2srij avatar May 11 '22 16:05 reply2srij

2 years since this request. Any updates please?

Still nothing but meanwhile I saw this nice trick from MappingTool

Sunac avatar May 11 '22 18:05 Sunac

Yes, I saw this too, but our use case is some more complicated than this example. Macro would be a perfect fit.

reply2srij avatar May 11 '22 19:05 reply2srij

Hello, we currently do not support macros. We have released support for JavaScript resolvers which makes it easier to write your business logic. https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-js-version.html

onlybakam avatar Dec 13 '23 23:12 onlybakam