* Which Category is your question related to? *
AppSync GraphQL
* Provide additional details e.g. code snippets *
The docs at https://github.com/aws-amplify/amplify-cli/blob/master/how-to-write-a-transformer.md outline how to write custom transformers. But I was wondering how to actually integrate these into the amplify api gql-compile workflow?
We were actually discussing something like this today. There is no way to do it right now other than by building your own lightweight CLI that calls the transformer library under the hood. You can then load whatever transformers you want as well as write and include your own custom transformers. This is what is outlined in the doc and now on the amplify docs here https://aws-amplify.github.io/docs/js/graphql
Looking to the future, we want to develop some sort of system that would allow you to include your own transformers via a flag and/or a setting in .amplifyrc or another config file. I would think something like this could work:
amplify api gql-compile --transformers graphql-model-transformer graphql-auth-transformer my-custom-transformer-package
or have this config at a to be determined location:
# mapping of easy name from cli to name of npm package that must be installed on the machine.
transformers:
- graphql-model-transformer
- graphql-auth-transformer
- my-custom-transformer-package
About half-way thru building my own CLI copy I thought I would check, glad to know I wasn't missing something obvious. A system to include via flag/settings would be great in the future.
@lennybr Did you end up being able to run your own transformers by wrapping the CLI? I want to do something similar but am getting stuck on wrapping the CLI part.
+1
@TimothyKrell I got it working, but keeping in sync with all the refactoring of the master branch was a pain, so I went for a quick and dirty approach since the team is working on a long-term solution -- but it works well for my setup.
Instead of calling the amplify push
command directly, I made use of NPM's pre/post script hooks:
"gql-compile": "amplify api gql-compile",
"postgql-compile": "node scripts/custom-transformers/index.js",
"preamplify-push": "npm run gql-compile",
"amplify-push": "amplify push --no-gql-override"
Now when I use npm run amplify-push
it runs the standard amplify api gql-compile
command, then the postgql-compile
npm script runs my custom transformer (index.js is the entry-point to a few custom transformers which honestly just edit the already compiled files directly relying on replace-in-file) to do my custom work, then it runs the standard amplify push
command but with the --no-gql-override
flag so it doesn't undo my custom transformers.
Until we have better nested stacks, I also added a quick JSON minification to run as well during "postgql-compile" to temporarily work around #185
Closing this issue/question. Please track #185 for the nested stack solution which is currently in PR.
Most helpful comment
@TimothyKrell I got it working, but keeping in sync with all the refactoring of the master branch was a pain, so I went for a quick and dirty approach since the team is working on a long-term solution -- but it works well for my setup.
Instead of calling the
amplify push
command directly, I made use of NPM's pre/post script hooks:Now when I use
npm run amplify-push
it runs the standardamplify api gql-compile
command, then thepostgql-compile
npm script runs my custom transformer (index.js is the entry-point to a few custom transformers which honestly just edit the already compiled files directly relying on replace-in-file) to do my custom work, then it runs the standardamplify push
command but with the--no-gql-override
flag so it doesn't undo my custom transformers.Until we have better nested stacks, I also added a quick JSON minification to run as well during "postgql-compile" to temporarily work around #185