-
Notifications
You must be signed in to change notification settings - Fork 820
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
Custom Transformer v2 - Error: Template asset can be used only with TransformerStackSynthesizer #9362
Comments
It looks like you're hitting this exception because this Since the CLI must be installed globally, it's probably easiest for your directive to rely on the global versions of the dependency. |
@cjihrig thanks - I can follow your reasoning, however I'm puzzled. How would I achieve this? Relying on the global versions of the dependency? From where would I import this 🤷♂️ import {
MappingTemplate,
TransformerPluginBase,
} from '@aws-amplify/graphql-transformer-core'; I also had a look on a Custom Transformer V2 from another party, it is done the same way here, and it also does crash upon Edit: I added the error log in the initial post above. It seems to confirm your theory. The error gets thrown by the local dependency while being invoked from the global version of the Amplify CLI. |
Node's module resolution algorithm searches some global installation locations by default (it's generally discouraged to rely on global installs, but since the CLI must be installed globally, 🤷). You can find out the exact path that a module is resolved to like this: require.resolve('@aws-amplify/cli') You can also figure out which paths the resolution algorithm will look in like this: require.resolve.paths('@aws-amplify/cli') If the modules that you need are installed globally, then you don't need to add them in your |
Thanks for your suggestion, @cjihrig - Unfortunately this does not work at all. // globalPath.js
const globalPath = require.resolve('@aws-amplify/graphql-transformer-core'); Running the code above ( Error: Cannot find module '@aws-amplify/graphql-transformer-core' Same with const Despite that, I cannot use this in TypeScript const globalPath = require.resolve('@aws-amplify/graphql-transformer-core');
const { TransformerPluginBase, MappingTemplate } = require(globalPath);
export class TenantTransformer extends TransformerPluginBase {
...
} 'extends' clause of exported class 'TenantTransformer' has or is using private name 'TransformerPluginBase'.ts(4020) Question: Are we facing a bug or badly designed Plugin System here? I assume that behavior is not intended. What would be an appropriate label (bug, documentation) to bring this issue to the attention of the AWS Amplify CLI team? Our company's development work has stopped for over two weeks because we're not able to implement 3 important Custom Transformers V2. The official documentation about Adding Custom GraphQL Transformers to the Project is not helpful. Thank you very much in advance. |
I found a workaround. The path below along with // @ts-ignore
import { MappingTemplate, TransformerPluginBase} from '/snapshot/node_modules/@aws-amplify/graphql-transformer-core'; Still I feel this is not a good approach for a Plugin System. As you pointed out, this will probably not work across machines. Any comment/suggestion for a safe approach from AWS Amplify CLI team would be nice. I will leave this issue open. |
Indeed. I'm not sure using I've hit this issue too, and at least in my case it's only triggered when using |
I realise this is happening because the amplify CLI is running via a global installation, with packages in
I believe this is incorrect, as Node doesn't have this behaviour unlike say Python. I haven't tried this, but I wonder if setting |
It does. Node's module resolution algorithm is described here. Search for I think the better short term solution is to investigate making the existing |
Apologies, you're right. I guess because it's tricky to get Typescript to recognise these global libraries I assumed they weren't accessible. |
Before opening, please confirm:
How did you install the Amplify CLI?
curl
If applicable, what version of Node.js are you using?
v17.0.1
Amplify CLI Version
7.6.4
What operating system are you using?
Mac
Amplify Categories
api
Amplify Commands
Not applicable
Describe the bug
When adding a slot to an existing resolver, the following error is thrown:
Template asset can be used only with TransformerStackSynthesizer
. It refers toamplify-graphql-transformer-core/src/cdk-compat/file-asset.ts
Expected behavior
I expect additional VTL files to be automatically generated when adding a slot. In my example
Mutation.createTodo.auth.2.req.vtl
The Transformer v2 is very sparsely documented - any fix, help or workaround is appreciated 😥
Reproduction steps
transform.conf.json
, add @Tenant directive to GraphQL Schemaamplify push
Custom Transformer code:
GraphQL schema(s)
Log output
Additional information
No response
The text was updated successfully, but these errors were encountered: