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: add api id and amplify environment name to stash #2273

Merged
merged 16 commits into from
Dec 19, 2024
Merged

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Nov 26, 2024

Problem

Customers are not able to use DDB batch operations in custom JS resolvers. The customer needs the DDB table name to perform batch operations. The customer can construct the table name from the GraphQL API ID and the Amplify environment name (<model-name>-<graphql-api-id>-<environment-name>).

Issue number, if available: aws-amplify/amplify-category-api#408 (comment)

Changes

Add GraphQL API ID and the Amplify environment name to resolver context stash.

Corresponding docs PR, if applicable: aws-amplify/docs#8145

Validation

  • Add unit test
  • Test in sample app

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

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

Copy link

changeset-bot bot commented Nov 26, 2024

🦋 Changeset detected

Latest commit: 8987f6e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-amplify/backend-data Minor
@aws-amplify/backend Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

* Pipeline resolver request handler
*/
export const request = (ctx) => {
ctx.stash.apiId = '${amplifyApi.apiId}';
Copy link
Member

Choose a reason for hiding this comment

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

I'd normally recommend we namespace all amplify variables, as in:

  • amplifyAppsyncApiId
  • amplifyEnvironmentName
  • amplifyFooBar...

However! Since we already have an output name for API ID, I wonder if we should use that:

  • awsAppsyncApiId

For parallelism, that makes the other variable something like:

  • awsAmplifyEnvironmentName

@dpilch dpilch marked this pull request as ready for review November 27, 2024 16:35
@dpilch dpilch requested a review from a team as a code owner November 27, 2024 16:35
packages/backend-data/src/convert_js_resolvers.ts Outdated Show resolved Hide resolved
packages/backend-data/src/convert_js_resolvers.ts Outdated Show resolved Hide resolved
sobolk
sobolk previously approved these changes Dec 2, 2024
@sobolk
Copy link
Member

sobolk commented Dec 2, 2024

Please make checks happy.
image

sobolk
sobolk previously approved these changes Dec 2, 2024
sobolk
sobolk previously approved these changes Dec 17, 2024
@dpilch dpilch enabled auto-merge (squash) December 17, 2024 18:46
.changeset/strong-toes-sniff.md Show resolved Hide resolved
@@ -71,12 +78,15 @@ export const convertJsResolverDefinition = (

const resolverName = `Resolver_${resolver.typeName}_${resolver.fieldName}`;

const amplifyEnvironmentName =
scope.node.tryGetContext('amplifyEnvironmentName') ?? 'NONE';
Copy link
Contributor

Choose a reason for hiding this comment

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

This context var amplifyEnvironmentName looks like is set by data construct exclusively? Is this the branchName for CI/CD deployments and NONE for sandbox?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is this the branchName for CI/CD deployments and NONE for sandbox.

Copy link
Contributor

Choose a reason for hiding this comment

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

than we are using the wrong naming here. amplifyEnvironmentName suggests amplify wide name for the environment which is not the case here. May I suggest amplifyApiEnvironmentName?

Copy link
Member Author

Choose a reason for hiding this comment

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

The value is already used in the data construct. To use the new name without a breaking change we would need to set both variables, then it might be confusing why there are two variables with the same value. I think it is a better option to continue using the existing one.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not asking to change in the data construct but rather the new variables created in the backend-data to which this value is assigned. As well as the new variable set in the convert_js_resolvers.ts. It's not a branch name since it's applicable for sandboxes as well.

Copy link
Member Author

@dpilch dpilch Dec 18, 2024

Choose a reason for hiding this comment

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

Oh sorry, you mean const amplifyEnvironmentName not what is in context?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I understand context vars are harder to change, but we should not create more vars with this naming (such as amplifyBranchName)

Amplifiyer
Amplifiyer previously approved these changes Dec 18, 2024
sobolk
sobolk previously approved these changes Dec 18, 2024
Comment on lines 81 to 82
const amplifyApiEnvironmentName =
scope.node.tryGetContext('amplifyApiEnvironmentName') ?? 'NONE';
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we didn't want to change the context parameter, is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, hasty find and replace.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed now.

@dpilch dpilch merged commit fbf209e into main Dec 19, 2024
41 checks passed
@dpilch dpilch deleted the apiid-resolver branch December 19, 2024 09:34
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.

4 participants