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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

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: 9aff173

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
import { Asset } from 'aws-cdk-lib/aws-s3-assets';
import { resolveEntryPath } from './resolve_entry_path.js';

const APPSYNC_PIPELINE_RESOLVER = 'PIPELINE';
const APPSYNC_JS_RUNTIME_NAME = 'APPSYNC_JS';
const APPSYNC_JS_RUNTIME_VERSION = '1.0.0';
const JS_PIPELINE_RESOLVER_HANDLER = './assets/js_resolver_handler.js';
Copy link
Member

Choose a reason for hiding this comment

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

if we're dropping this. Shall we remove unused assets?

(before you do please read other comments).

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

Comment on lines +36 to +37
.replace('${amplifyApiId}', amplifyApiId)
.replace('${amplifyEnvironmentName}', amplifyEnvironmentName);
Copy link
Member

Choose a reason for hiding this comment

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

For future proofing: If templates reference the match patterns more than once, this will fail. Consider a global regexp:

Suggested change
.replace('${amplifyApiId}', amplifyApiId)
.replace('${amplifyEnvironmentName}', amplifyEnvironmentName);
.replace(new RegExp('\$\{amplifyApiId\}', 'g'), amplifyApiId)
.replace(new RegExp('\$\{amplifyEnvironmentName\}', 'g'), amplifyEnvironmentName);

If you do adopt this change, please add tests to verify.

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