-
Notifications
You must be signed in to change notification settings - Fork 64
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: bc9b37c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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}'; |
There was a problem hiding this comment.
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
Co-authored-by: Tim Schmelter <[email protected]>
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'; |
There was a problem hiding this comment.
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).
/** | ||
* The top-level passthrough resolver request/response handler (see: https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html#anatomy-of-a-pipeline-resolver-js) | ||
* It's required for defining a pipeline resolver. Adds the GraphQL API ID and Amplify environment name to the context stash. | ||
* Returns the output of the last function in the pipeline back to the client. | ||
* | ||
* Customer-provided handlers are added as a Functions list in `pipelineConfig.functions` | ||
* | ||
* Uses synth-time inline code to avoid circular dependency when adding the API ID as an environment variable. | ||
*/ | ||
code: ` | ||
/** | ||
* Pipeline resolver request handler | ||
*/ | ||
export const request = (ctx) => { | ||
ctx.stash.awsAppsyncApiId = '${amplifyApi.apiId}'; | ||
ctx.stash.awsAmplifyEnvironmentName = '${amplifyEnvironmentName}'; | ||
return {}; | ||
}; | ||
/** | ||
* Pipeline resolver response handler | ||
*/ | ||
export const response = (ctx) => { | ||
return ctx.prev.result; | ||
}; | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep this in ts
file that is under compiler checks? And have unit tests?
and fs.readSync
the compiled lib/<name>.js
file at runtime?
We should avoid JS/TS code in string literals. Otherwise the only way we can assert it's correct in such setup is e2e tests.
See example here:
amplify-backend/packages/backend-function/src/factory.ts
Lines 423 to 431 in 72b2fe0
/** | |
* This code concatenates the contents of the ssm resolver and invoker into a single line that can be used as the esbuild banner content | |
* This banner is responsible for resolving the customer's SSM parameters at runtime | |
*/ | |
const bannerCode = readFileSync(ssmResolverFile, 'utf-8') | |
.concat(readFileSync(invokeSsmResolverFile, 'utf-8')) | |
.split(new RegExp(`${EOL}|\n|\r`, 'g')) | |
.map((line) => line.replace(/\/\/.*$/, '')) // strip out inline comments because the banner is going to be flattened into a single line | |
.join(''); |
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: TODO
Validation
Checklist
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.