hirochachacha / graphql-auto-transformer

A custom transformer of the amplify-cli. It can control accessibility of auto generated fields.
Apache License 2.0
45 stars 3 forks source link

Cannot find module 'graphql-auto-transformer' #2

Closed pcvvelzen closed 4 years ago

pcvvelzen commented 4 years ago

After following the installation instructions (step1) with npm install and (step 2) adding graphql-auto-transformer to the transform.conf.json file of my Amplify API:

{
    "Version": 5,
    "transformers": [
        "graphql-auto-transformer"
    ]
}

When attempting to use @auto directive in my model

type Post @model {
[...]
    createdAt: AWSDateTime! @auto
}

I get the following error

$ amplify push -y
- Fetching updates to backend environment: dev from the cloud.
√ Successfully pulled backend environment dev from the cloud.

Current Environment: dev

| Category | Resource name                       | Operation | Provider plugin   |
| -------- | ----------------------------------- | --------- | ----------------- |
| Api      | pocapi                                  | Update    | awscloudformation |
| Auth     | userPoolGroups                      | No Change | awscloudformation |
| Auth     | pocapixxxxxxxxx                    | No Change | awscloudformation |
| Hosting  | S3AndCloudFront                     | No Change | awscloudformation |
× An error occurred when pushing the resources to the cloud

Unknown directive "auto".
An error occurred during the push operation: Unknown directive "auto".

When removing the @auto directory from my schema and running amplify push -y I get the error that graphql-auto-transformer module could not be found, while the module is present in .\node_modules\graphql-auto-transformer (after being installed through npm as mentioned in the readme.MD).

$ amplify push -y
- Fetching updates to backend environment: dev from the cloud.
√ Successfully pulled backend environment dev from the cloud.

Current Environment: dev

| Category | Resource name                       | Operation | Provider plugin   |
| -------- | ----------------------------------- | --------- | ----------------- |
| Api      | pocapi                                  | Update    | awscloudformation |
| Auth     | userPoolGroups                      | No Change | awscloudformation |
| Auth     | pocapixxxxxxxxx                    | No Change | awscloudformation |
| Hosting  | S3AndCloudFront                     | No Change | awscloudformation |
Unable to import custom transformer module(graphql-auto-transformer).
You may fix this error by editing transformers at ~\poc\amplify\backend\api\pocapi\transform.conf.json
× An error occurred when pushing the resources to the cloud

Cannot find module 'graphql-auto-transformer'
Require stack:
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\transform-graphql-schema.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\push-resources.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\amplify-service-migrate.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\initializer.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\index.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\lib\commands\push.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\lib\index.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\bin\amplify
An error occured during the push operation: Cannot find module 'graphql-auto-transformer'
Require stack:
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\transform-graphql-schema.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\push-resources.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\amplify-service-migrate.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\lib\initializer.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\amplify-provider-awscloudformation\index.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\lib\commands\push.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\lib\index.js
- C:\Users\PC\AppData\Roaming\npm\node_modules\@aws-amplify\cli\bin\amplify

This was only resolved through installing the package globally: npm install graphql-auto-transformer -g.

Note: I am not certain as if this issue is related to this package, or to the Amplify CLI perhaps containing a bug in combination with Windows, with finding the correct relative path to ./node_nodules/graphql-auto-transformer

hirochachacha commented 4 years ago

Did you try export NODE_PATH=./node_modules ? https://github.com/hirochachacha/graphql-auto-transformer#4-export-node_path

hirochachacha commented 4 years ago

let me know if the issue persists

r0zar commented 4 years ago

I did have to run npm i -g graphql-auto-transformer in the build step to get it working.

KarthickSelvam commented 3 years ago

I did have to run npm i -g graphql-auto-transformer in the build step to get it working.

How do you add this to build step?