aws / aws/aws-appsync-community

Spread operator does not work with util.appendError

Open
#323 2 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Spread operator does not work to pass arguments to util.appendError. This causes an error when attempting to update the resolver code: "Ln 12, Col 22 code.js(12,22): error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter. "

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Here is the minimal reproduction using a JavaScript unit resolver with a null data source:

```
export function request(ctx) {
return {};
}

export function response(ctx) {
const error_args = [
`Downstream HTTP request failed with status foo.`,
`http_504`,
{a: 1},
{b: 2},
]
util.appendError(...error_args)
return ctx.prev.result;
}
```
What is the expected behavior?
The util.appendError call should be allowed, and the resolver code should be updated without receiving a TypeScript error.

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?
APPSYNC_JS issue. It has never worked as far as I can tell.

A workaround is to define a wrapper function and use that to call util.AppendError:
```

function wrapper(a, b, c, d) {
util.appendError(a, b, c, d)
}

export function request(ctx) {
return {};
}

export function response(ctx) {
const error_args = [
`Downstream HTTP request failed with status foo.`,
`http_504`,
{a: 1},
{b: 2},
]
wrapper(...error_args)
return ctx.prev.result;
}
```

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal JavaScript unit resolver reproduction with a null data source, then inspect the AppSync JS util.appendError entry point and its accepted argument types. Done means the spread call updates the resolver without TS2556 while preserving the direct-call behavior shown in the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, javascript, typescript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.