aws / aws/aws-appsync-community

Add method to check if variable is of type array

Open
#295 3 comments 4 reactions 0 assignees View on GitHub
feature-request
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Currently, there is no way to check whether a variable is an array in JS resolver functions.

Here are a couple of approaches as to how you would go about it in a browser or Nodejs environment:

1. Use `Array.isArray`, which doesn't exist in `APPSYNC_JS`.
2. Use `arr.constructor === Array`. That doesn't work, because `arr.constructor` is undefined in `APPSYNC_JS`.
3. Check for multiple array functions. Ex:
```js
function isArray(x) {
return (
typeof x.find === 'function' &&
typeof x.length === 'number' &&
typeof x.sort === 'function'
);
}
```
This also doesn't work because `typeof` any function is `'undefined'` in `APPSYNC_JS`. This is also (IMO) the worst solution.

The functionality is present in `vtl` resolvers with `$util.isList`, so it would be nice if it was available in the JS runtime as well.

Contributor guide

Open the contributing guide

Research direction

No files or tests are named in the issue. Start by locating the APPSYNC_JS resolver runtime and compare its available type-checking helpers with VTL’s `$util.isList`; done should mean JS resolver functions can reliably determine whether a value is an array.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, javascript
Domain
api, backend
Issue type
Feature
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.