aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Is it possible to reuse vtl code to extend multiple resolvers *in the same way* ? #9552

Open jimjoes opened 2 years ago

jimjoes commented 2 years ago

Is it possible to reuse common logic to extend the generated resolvers? As far as I can tell, you need the logic for each resolver in separate files, but I'd like to reuse the same logic (in the same slot) across multiple queries and I'd rather not have to maintain the same code across multiple files in my project,

Which Category is your question related to? API

Amplify CLI Version

You can use amplify -v to check the amplify cli version on your system 7.6.5

What AWS Services are you utilizing?

danielleadams commented 2 years ago

Hi @econtentmaps - The v2 of transformers support pipeline resolvers, so I think using custom resolvers and either overriding or extending the resolvers, you should be able to reuse VTL code in your app. I will add this as a feature request though since we don't have an easier way to do this with the transformers.

edwardfoyle commented 2 years ago

@econtentmaps Another option you could look into is command hooks. You could write your common resolver code in a single file and then have a pre-push hook that copies the code into all of the relevant resolver files.

jimjoes commented 2 years ago

Hi @danielleadams, Thanks - by reuse do you mean copy the same code into all the separate files needed according to the 'slots as filenames' approach? If so, that's what I'd like to avoid, but as far as I can tell, vtl doesn't have imports or anything to allow one file to be the dry source. @edwardfoyle that looks useful, but seems a little brittle. Would be useful to be able to do this from the cli or the sdl somehow I guess.