amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Amplify codegen iOS: Unable to import custom transformer module(graphql-assert-transformer)

Open nielsautrata opened this issue 5 years ago • 7 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

14.17.1

Amplify CLI Version

5.1.0

What operating system are you using?

Mac

Amplify Codegen Command

codegen models

Describe the bug

Unable to import custom transformer module(graphql-assert-transformer). You may fix this error by editing transformers at /XXX/XXX/XXX/XXX/amplify/backend/api/XXX/transform.conf.json Error: Cannot find module '/Users/XXX/XXX/XXX/~/.npm-global/lib/node_modules/graphql-assert-transformer' Require stack:

  • /snapshot/node_modules/import-global/index.js
  • /snapshot/node_modules/amplify-provider-awscloudformation/lib/transform-graphql-schema.js
  • /snapshot/node_modules/amplify-provider-awscloudformation/lib/push-resources.js
  • /snapshot/node_modules/amplify-provider-awscloudformation/lib/amplify-service-migrate.js
  • /snapshot/node_modules/amplify-provider-awscloudformation/lib/initializer.js
  • /snapshot/node_modules/amplify-provider-awscloudformation/lib/index.js
  • /snapshot/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/execute-provider-utils.js
  • /snapshot/node_modules/@aws-amplify/cli/lib/domain/amplify-toolkit.js
  • /snapshot/node_modules/@aws-amplify/cli/lib/domain/context.js
  • /snapshot/node_modules/@aws-amplify/cli/lib/context-manager.js
  • /snapshot/node_modules/@aws-amplify/cli/lib/index.js
  • /snapshot/node_modules/@aws-amplify/cli/bin/amplify Unable to import custom transformer module(graphql-assert-transformer).

Transform.conf.json: "transformers": [ "graphql-default-value-transformer", "graphql-assert-transformer", "graphql-auto-transformer" ]

Expected behavior

Successfully generated models

Reproduction steps

iOS project: After pulling from the backend, I am unable to run $ amplify codegen models successfully. Updating Xcode project: ✅ Amplify project found. ✅ Amplify config files found. ✅ Successfully updated project /Users/XXX/XXX/XXX. ✅ Amplify models folder found at /Users/XXX/XXX/XXX/amplify/generated/models ✅ Successfully added models [] to 'AmplifyModels' group. Amplify setup completed successfully.

$ amplify codegen models

GraphQL schema(s)

# Put schemas below this line


Log output

# Put your logs below this line


Additional information

No response

nielsautrata avatar Jul 07 '21 09:07 nielsautrata

The error is thrown by the schema validation, which depends on the graphql transformer package of CLI. I will transfer this to CLI so that they will better assist you

AaronZyLee avatar Jul 07 '21 18:07 AaronZyLee

@nielsautrata I have a few questions:

  1. Was this working with a previous version of the CLI?
  2. I see that you're importing other modules as well (graphql-default-value-transformer, graphql-auto-transformer). Are those working properly?
  3. Is graphql-assert-transformer installed where it's expected?

cjihrig avatar Jul 07 '21 22:07 cjihrig

  1. Yes, before version 5
  2. Yes, in the react and android projects there are no error for compiling with codegen
  3. Yes, there are installed generally, this is my transform.conf.json:
{
    "Version": 5,
    "ElasticsearchWarning": true,
    "transformers": [
        "graphql-default-value-transformer",
        "graphql-assert-transformer",
        "graphql-auto-transformer"
    ],
    "StackMapping": {
        "QuerylistResponsiblesByAssignmentResolver": "Responsible",
        "QuerylistResponsiblesByEmployeeResolver": "ResponsibleM"
    }
}

In the case, you want to download my graph.ql this my app id dl91s1m9oit3p and the region is us-east-1

nielsautrata avatar Jul 08 '21 09:07 nielsautrata

Thanks for the info @nielsautrata. I'm marking this as a bug.

cjihrig avatar Jul 08 '21 16:07 cjihrig

@nielsautrata I see that you are using the packaged CLI, right? Can you confirm that if you install the CLI from NPM then codegen models will work? (so the custom transformer is correctly installed?)

But that's the other question, how is the custom transformer installed, as you reference it by package name, CLI looks for it as a global module, which it is failed to find.

attilah avatar Jul 10 '21 14:07 attilah

After Installing the custom transformer via npm locally in the respective project folder then codegen models will work. "Successfully added models".

nielsautrata avatar Jul 12 '21 12:07 nielsautrata

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar Sep 11 '21 01:09 github-actions[bot]