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 77 forks source link

amplify mock ignores override.ts. #1659

Open aoi opened 1 year ago

aoi commented 1 year ago

How did you install the Amplify CLI?

npm

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

v18.16.1

Amplify CLI Version

12.1.1

What operating system are you using?

Windows, Ubuntu

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

No.

Describe the bug

amplify mock ignores override.ts.

For example, there are ModelA (ModelATable) and ModelB (ModelBTable). If you want to access the ModelBTable in ModelA pipeline, you can write the code below in override.ts.

export function override(resources: AmplifyApiGraphQlResourceStackTemplate, amplifyProjectInfo: AmplifyProjectInfo) {
    const modelARes = resources.models["ModelA"];
    const listModelAsAuth1Func = modelARes.appsyncFunctions["QuerylistModelAsauth1FunctionQuerylistModelAsauth1Function.AppSyncFunction"];
    listModelAsAuth1Func.dataSourceName = "ModelBTable";
}

(QuerylistModelAsauth1FunctionQuerylistModelAsauth1Function.AppSyncFunction is generated Query.listModelAs.auth.2.req.vtl which is extended resolver after auth.1.req.vtl.)

When executing amplify build, an output stack file ModelA.json in build/stacks has "DataSourceName": "ModelBTable", instead of NONE_DS.

But when executing amplify mock api, this data source will be NONE_DS because of amplify mock ignores override.ts.

Expected behavior

override.ts is supposed to be effect when execute amplify mock.

Reproduction steps

  1. amplify override api
  2. Edit override.ts. e.g., Write console.log('override'); as debug log in override method.
  3. amplify mock api, but not debug log.

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

josefaidt commented 1 year ago

Hey @aoi :wave: thanks for raising this! I'm going to transfer this over to our API repo for tracking purposes, but unfortunately this is not currently supported. There is an active feature request to support this, would you mind sharing your thoughts or adding a 👍 ? https://github.com/aws-amplify/amplify-category-api/issues/775#issuecomment-1234820704

aoi commented 1 year ago

Hello @josefaidt. Thank you for your reply and transfering this issue. Also I'm preparing a PR for fixing this issue. I will submit PR in few days.