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

appsync: error destructuring within function signature in JS resolver runtime (TypeScript) #26355

Closed
berkzorlu opened this issue Jul 13, 2023 · 4 comments
Labels
@aws-cdk/aws-appsync Related to AWS AppSync bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@berkzorlu
Copy link

berkzorlu commented Jul 13, 2023

Describe the bug

When using JS resolver pipelines with TS, I have encountered an unexpected error in my code.

If:

  • we have a props object containing optional parameters
  • we destructure that object within the function signature
  • and a usage of this function does not provide the optional parameter

The deployment results in an error.

My tsconfig settings are identical to the ones recommended on https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html#working-with-typescript but the transpiled js is still troublesome to the js runtime.

Expected Behavior

I expect the JS resolver code to deploy without errors.

Current Behavior

The deployment results in an error.

Reproduction Steps

export type Props = {
	s: string;
	o?: string;
};

export const test = ({ s, o }: Props): void => {
	util.appendError(`${s}${o}`, 'type');
};

And we call this function without providing the optional property:

test({ s: 'test' });

The transpiled js file looks like this:

// src/test.ts
var test = ({ s, o }) => {
  util.appendError(`${s}${o}`, "type");
};
export {
  test
};

This is reproducible every time when the object parameter contains an optional property and at least one usage of this function does not provide the optional property.

Possible Solution

The error goes away if we destructure inside the function rather than the function signature:

export type Props = {
	s: string;
	o?: string;
};

export const test = (props: Props): void => {
	const { s, o } = props;
	util.appendError(`${s}${o}`, 'type');
};

Additional Information/Context

No response

CDK CLI Version

n/a

Framework Version

SST v2.8.27

Node.js Version

n/a

OS

mac

Language

Typescript

Language Version

No response

Other information

No response

@berkzorlu berkzorlu added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 13, 2023
@github-actions github-actions bot added the @aws-cdk/aws-appsync Related to AWS AppSync label Jul 13, 2023
@peterwoodworth
Copy link
Contributor

Hey @berkzorlu, I'm a bit confused. What does this have to do with CDK?

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 13, 2023
@berkzorlu
Copy link
Author

berkzorlu commented Jul 13, 2023

Hey @berkzorlu, I'm a bit confused. What does this have to do with CDK?

Hmm I think you're right. It's more of a potential issue with the JS resolver runtime in combination with the recommended TS configuration, and that probably doesn't belong here since the same result is achievable if we deployed the resolver manually through the AWS console.

What might be the proper channel to report this?

@peterwoodworth
Copy link
Contributor

peterwoodworth commented Jul 13, 2023

I'm not sure the specific error you're getting, or if you can or are supposed to work around your error by modifying the tsconfig. The best place would be premium support if you have it, else I'd recommend asking Stack Overflow, or something like repost

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants