-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
aws-appsync: support passing dynamic values from CDK to APPSYNC_JS #26848
Comments
I don't know enough to create a PR, however it may be something like;
Not sure if extending Then I have no idea how to get this into the file, ie |
I totally agree with solving this use case in a first class way. FWIW we solved it for now via creating a factory function for creating a dynamic Pipeline Resolver that added the value to the context's Here's our factory function verbatim, including all our comments and reference to what inspired our solution as they may be helpful. This is used in a CDK construct, as the comments below explain, via // For Batch DynamoDB operations the AppSync Resolvers need access to the table name to read from
// This isn't available at runtime so we need to inject it at build time using the following Pipeline Resolver factory function
//
// Note: This returns generated string with the resolvered table name embedded and so needs to be used with Code.fromInline() rather than Code.fromAsset().
// Inspired by: https://kieron-mckenna.medium.com/appsync-resolvers-with-typescript-cdk-getting-a-dynamodb-table-name-for-transactions-d8060f438b6b
export const createTableNameInjector = (tableName: string) => `
export function request(ctx) {
ctx.stash.tableName = "${tableName}"
return {}
}
export function response(ctx) {
return ctx.prev.result
}
`; Hope that's at least helpful as a possible solution in the short term. |
Right now, I am using this construct https://constructs.dev/packages/cdk-appsync-typescript-resolver which transpiles TS to JS and replace strings (for example ENV or TABLE_NAME) PS: I created the construct |
Thank you for the feature request and we welcome pull requests from the community. |
We released support for env vars in appsync: https://docs.aws.amazon.com/appsync/latest/devguide/environmental-variables.html |
@samturner3 Good morning. Could you please check if support for env vars in appsync: https://docs.aws.amazon.com/appsync/latest/devguide/environmental-variables.html helps resolve your use case? Thanks, |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
I am not able to test the solution as the specific use case engagement has ended, however from just reading the docs it looks like it is solved in principle, thanks! 👍 |
|
Describe the feature
javascript resolver support was added: #22921
However for some configurations context in the cdk file is required to be passed to the APPSYNC_JS file.
Use Case
For example when using other DynamoDB operations such as, TransactionWriteItem, the table name is required. If the table name is different for each application environment there is currently no way to provide a dynamic value to the resolver. The work arounds are to write the resolver code inline in the CDK stack or provide the table name as part of the GraphQL request context.
Another example is in this aws-sample step functions example where we need to pass in
stateMachineArn
to the request template.Proposed Solution
something like:
codeArgs
cdk-stack.ts
AssetCode
options add a new option such ascodeArgs
(may need a better name):Then in the code file:
ctx.codeArgs
appSyncResolver.js
codeArgs
appSyncResolver.js
Other Information
This is a much wanted feature as mentioned:
I am using amplify that transpiles TS files, I then reference the built file into
appsync.Code.fromAsset
.Acknowledgements
CDK version used
v2 (unknown exactly as using amplify)
Environment details (OS name and version, etc.)
Mac OS 11.6
The text was updated successfully, but these errors were encountered: