Skip to content
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

feat: inject project info into api overrides #1372

Merged
merged 7 commits into from
Mar 27, 2023

Conversation

sobolk
Copy link
Member

@sobolk sobolk commented Mar 27, 2023

Description of changes

This PR adds additional parameter to the override() that has environment name and project name.
This is a common functionality that has been implemented across other overrides here aws-amplify/amplify-cli#12064 .

Completes coverage for this ask aws-amplify/amplify-cli#9063 .

CDK / CloudFormation Parameters Changed

Issue #, if available

Description of how you validated changes

https://app.circleci.com/pipelines/github/aws-amplify/amplify-category-api?branch=run-e2e%2Fsobkamil%2Finject-project-info

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Any CDK or CloudFormation parameter changes are called out explicitly

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sobolk sobolk requested a review from a team as a code owner March 27, 2023 20:59
Comment on lines +4 to +14
if (!amplifyProjectInfo || !amplifyProjectInfo.envName || !amplifyProjectInfo.projectName) {
throw new Error(`Project info is missing in override: ${JSON.stringify(amplifyProjectInfo)}`);
}

if (amplifyProjectInfo.envName != '##EXPECTED_ENV_NAME') {
throw new Error(`Received unexpected envName: ${amplifyProjectInfo.envName}`);
}

if (amplifyProjectInfo.projectName != '##EXPECTED_PROJECT_NAME') {
throw new Error(`Received unexpected projectName: ${amplifyProjectInfo.projectName}`);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertions are injected into override code with placeholders. This is because overrides don't return anything (or even if they do nothing captures return value).
(this pattern is repeated in other tests, with placeholders in e2e tests and hardcoded values in unit tests).

Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question for the old projects using override. Is it mandatory for them to change the override code of adding the new params? Or they can continue staying at the old ones? (when the feature is released in CLI)

@sobolk
Copy link
Member Author

sobolk commented Mar 27, 2023

Just one question for the old projects using override. Is it mandatory for them to change the override code of adding the new params? Or they can continue staying at the old ones? (when the feature is released in CLI)

There's no action for existing overrides. Additional parameter is ignored at runtime.
They may opt into this feature by adding variable to their function declaration.

@AaronZyLee AaronZyLee merged commit 2b92351 into aws-amplify:main Mar 27, 2023
@sobolk sobolk deleted the inject-project-info branch March 27, 2023 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants