aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

Upgrading from 12.2.3 to 12.2.4+ causes "template.substituteValues is not a function" error #1897

Open hisham opened 1 year ago

hisham commented 1 year ago

How did you install the Amplify CLI?

npm

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

18.16.1

Amplify CLI Version

12.2.4

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

When running 'amplify api gql-compile' / amplify push I get the following error:

"🛑 template.substituteValues is not a function"

Expected behavior

Graphql schema should compile succesfully

Reproduction steps

Not sure but I sent my project configurations.

Project Identifier

3def1a2bd59d61900f734d59f169a578

Log output

``` # Put your logs below this line 🛑 template.substituteValues is not a function ```

Additional information

No response

Before submitting, please confirm:

AnilMaktala commented 1 year ago

Hi @hisham, Thank you for raising this. It appears that this issue is a duplicate of #1695. Would you mind upgrading to CLI 12.3.0 and let us know the outcome?

hisham commented 1 year ago

Upgrading to 12.3.0 does not fix. However, we do have have custom transformers that are using ""@aws-amplify/graphql-transformer-core": "^1.2.0"", and if I disable these custom transformers the gql-compile command succeeds.

So the comment in https://github.com/aws-amplify/amplify-category-api/issues/1695 about updating to graphql-transformer-core to 1.3.5 may be the solution. I'll work on updating the custom graphql directives.

hisham commented 1 year ago

Upgrading @aws-amplify/graphql-transformer-core to 1.4.0 on the custom graphql directive packages works. However updating it to 2.1.0 or above causes "AssetProvider not initialized" error. What is this error all about?

hisham commented 1 year ago

After upgrading our custom transformers to use @aws-amplify/graphql-transformer-core@1.4.0, I am now able to use the latest amplify cli (12.5.1).

Only issue is if in the future we update our transformers to reference "@aws-amplify/graphql-transformer-core" 2.0+, I would have to look into what this ""AssetProvider not initialized" error is all about.

olliethedev commented 1 year ago

Encountered same issue for a custom transformer of my own. Downgrading to @aws-amplify/graphql-transformer-core@1.4.0 indeed resolved the error.

olliethedev commented 1 year ago

Here is more info for anyone trying to debug this in the future.

I can reproduce the same error message by forking amplify-category-api repo locally and pointing the transform.conf.json to

    "transformers": [
        "file:///Users/ollie/Work/amplify-category-api/packages/amplify-graphql-function-transformer/lib/index.js"
    ]

here is the verbose crash log:

   🛑 AssetProvider not initialized

Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

DeploymentFault: AssetProvider not initialized
    at Object.run (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/push-resources.js:362:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/push-resources.js:137:16
    at async Promise.all (index 0)
    at async providersPush (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/push-resources.js:133:5)
    at async AmplifyToolkit.pushResources (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/push-resources.js:107:13)
    at async Object.executeAmplifyCommand (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/index.js:194:9)
    at async executePluginModuleCommand (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:139:5)
    at async executeCommand (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:37:9)
    at async Object.run (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/index.js:121:5)

AssetProvider not initialized
Error: AssetProvider not initialized
    at AssetManager.getAssetProvider (/Users/ollie/Work/amplify-category-api/packages/amplify-graphql-transformer-core/lib/transformer-context/asset-manager.js:10:19)
    at AssetManager.createAsset (/Users/ollie/Work/amplify-category-api/packages/amplify-graphql-transformer-core/lib/transformer-context/asset-manager.js:6:21)
    at S3MappingTemplate.bind (/Users/ollie/Work/amplify-category-api/packages/amplify-graphql-transformer-core/lib/cdk-compat/template-asset.js:59:55)
    at new AppSyncFunctionConfiguration (/snapshot/amplify-cli/build/node_modules/@aws-amplify/graphql-transformer-core/lib/appsync-function.js:12:62)
    at DefaultTransformHost.addAppSyncFunction (/snapshot/amplify-cli/build/node_modules/@aws-amplify/graphql-transformer-core/lib/transform-host.js:78:24)
    at /Users/ollie/Work/amplify-category-api/packages/amplify-graphql-function-transformer/lib/graphql-function-transformer.js:84:49
    at Array.forEach (<anonymous>)
    at /Users/ollie/Work/amplify-category-api/packages/amplify-graphql-function-transformer/lib/graphql-function-transformer.js:68:29
    at Map.forEach (<anonymous>)
    at FunctionTransformer.generateResolvers (/Users/ollie/Work/amplify-category-api/packages/amplify-graphql-function-transformer/lib/graphql-function-transformer.js:67:33)
    at GraphQLTransform.transform (/snapshot/amplify-cli/build/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.js:172:29)
    at executeTransform (/snapshot/amplify-cli/build/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.js:80:19)
    at buildAPIProject (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-category-api/lib/graphql-transformer/transform-graphql-schema-v2.js:146:48)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async transformGraphQLSchemaV2 (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-category-api/lib/graphql-transformer/transform-graphql-schema-v2.js:114:31)
    at async transformGraphQLSchema (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-category-api/lib/graphql-transformer/transform-graphql-schema.js:11:43)
    at async Object.run (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/push-resources.js:169:7)
    at async /snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/push-resources.js:137:16
    at async Promise.all (index 0)
    at async providersPush (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/push-resources.js:133:5)
    at async AmplifyToolkit.pushResources (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/push-resources.js:107:13)
    at async Object.executeAmplifyCommand (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/index.js:194:9)
    at async executePluginModuleCommand (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:139:5)
    at async executeCommand (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:37:9)
    at async Object.run (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/index.js:121:5)

This is probably a good place to start debugging for anyone brave enough.