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

The implementation of the compound assignment operator (+=) in AppSync_JS resolvers is not consistent with JS #3192

Open
2 tasks done
naedx opened this issue Feb 24, 2025 · 0 comments

Comments

@naedx
Copy link
Contributor

naedx commented Feb 24, 2025

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v20.9.0

Amplify CLI Version

1.4.9

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Describe the bug

When the compound assignment operator (+=) is used as the return expression the behavior differs from plain JS. Specifically, JS will evaluate the expression and the new value will be returned. AppSync_JS will return "".

This occurs whether the operands are string or numeric.

Expected behavior

The behavior should be consistent with JS or disallowed via a lint rule and the syntax checker in the AWS Console.

Reproduction steps

  1. Define the following resolver in the Amplify console.
  2. Create the default test context and run the test.
  3. Observe that the request and response resolvers return different results.
  4. (Optional) Uncomment return data.foo ?? "some other value" and observe that it works as expected
// APPSYNC_JS

import { util } from "@aws-appsync/utils";
  
export function request1(ctx) {
  let someText = "initialValue";
  
  return someText += ":modifiedValue"; // << returns ""
}

export function response2(ctx) {
  let someText = "initialValue";
  
  return someText = someText + ":modifiedValue"; // << returns "initialValue:modifiedValue"
}
  1. (Optional) Observe that the the following code returns "initialValue:modifiedValue" from both functions as expected if run in the browser.
function request(ctx) {
  let someText = "initialValue";
  
  return someText += ":modifiedValue";
}

function response(ctx) {
  let someText = "initialValue";
  
  return someText = someText + ":modifiedValue";
}

[request(), response()]

Project Identifier

No response

Log output

No response

Additional information

This will probably need to be looked at with #3170

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant