aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.12k forks source link

indexQueryFactory tries to run Object.keys(null) what causes error #13941

Open WojciechKasprzyk opened 2 days ago

WojciechKasprzyk commented 2 days ago

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

Amplify Gen 2

Environment information

``` System: OS: macOS 14.6.1 CPU: (10) arm64 Apple M1 Pro Memory: 101.64 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.2.0 - /usr/local/bin/node npm: 10.7.0 - /usr/local/bin/npm bun: 1.0.0 - ~/.bun/bin/bun Browsers: Chrome: 129.0.6668.101 Safari: 17.6 Safari Technology Preview: 18.0 npmPackages: @angular-devkit/build-angular: ^18.2.1 => 18.2.1 @angular-slider/ngx-slider: 18.0.0 => 18.0.0 @angular/animations: ^18.2.1 => 18.2.1 @angular/cli: ^18.2.1 => 18.2.1 @angular/common: ^18.2.1 => 18.2.1 @angular/compiler: ^18.2.1 => 18.2.1 @angular/compiler-cli: ^18.2.1 => 18.2.1 @angular/core: ^18.2.1 => 18.2.1 @angular/forms: ^18.2.1 => 18.2.1 @angular/platform-browser: ^18.2.1 => 18.2.1 @angular/platform-browser-dynamic: ^18.2.1 => 18.2.1 @angular/router: ^18.2.1 => 18.2.1 @aws-amplify/backend: ^1.1.1 => 1.1.1 @aws-amplify/backend-cli: ^1.2.5 => 1.2.5 @aws-amplify/ui-angular: ^5.0.19 => 5.0.28 @ngrx/effects: ^18.0.2 => 18.0.2 @ngrx/entity: ^18.0.2 => 18.0.2 @ngrx/eslint-plugin: ^18.0.2 => 18.0.2 @ngrx/operators: ^18.0.2 => 18.0.2 (18.0.1) @ngrx/schematics: ^18.0.2 => 18.0.2 @ngrx/store: ^18.0.2 => 18.0.2 @ngrx/store-devtools: ^18.0.2 => 18.0.2 @types/jasmine: ~5.1.4 => 5.1.4 aws-amplify: ^6.6.3 => 6.6.3 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/data: undefined () aws-amplify/data/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () bootstrap: ^5.3.3 => 5.3.3 jasmine-core: ~5.2.0 => 5.2.0 (4.6.1) karma: ~6.4.4 => 6.4.4 karma-chrome-launcher: ~3.2.0 => 3.2.0 karma-coverage: ~2.2.1 => 2.2.1 karma-coverage-coffee-example: 1.0.0 karma-jasmine: ~5.1.0 => 5.1.0 karma-jasmine-html-reporter: ~2.1.0 => 2.1.0 ngx-toastr: ^19.0.0 => 19.0.0 rxjs: ~7.8.1 => 7.8.1 rxjs/ajax: undefined () rxjs/fetch: undefined () rxjs/operators: undefined () rxjs/testing: undefined () rxjs/webSocket: undefined () swiper: ^10.3.1 => 10.3.1 tslib: ^2.7.0 => 2.7.0 (2.6.3, 2.0.3, 2.4.1, 2.2.0, 2.3.1, 1.14.1) typescript: ~5.5.4 => 5.5.4 (4.4.4, 4.9.5) zone.js: ~0.14.10 => 0.14.10 npmGlobalPackages: @angular/cli: 18.2.6 @aws-amplify/cli: 12.12.4 @ionic/cli: 7.2.0 cordova-res: 0.15.4 cordova: 12.0.0 corepack: 0.28.1 jest: 29.7.0 n: 9.2.3 npm: 10.7.0 ts-node: 10.9.2 ```

Describe the bug

If API return data equals null then indexQueryFactory tries to run Object.keys(null) which causes error. It's funny that you mentioned in the comment that data can be null and you mentioned that you check it but actually, it is not.

image

null !== undefined so Object.keys is called with invalid argument.

Expected behavior

There should be a condition like data != null to check both null and undefined.

Reproduction steps

Call API that returns data: null

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

WojciechKasprzyk commented 2 days ago

@chachasammy is it a scam? @aws-amplify-ops Could you ban it?

stocaaro commented 2 days ago

@WojciechKasprzyk Thanks for calling that out! Deleted/reported.

chrisbonifacio commented 2 days ago

Hi @WojciechKasprzyk 👋 thanks for raising this issue and we've taken action against the comment you pointed out.

Regarding this issue, we will reproduce with the conditions you mentioned and look into addressing it

chrisbonifacio commented 21 hours ago

Hi @WojciechKasprzyk just curious, could you share the server code that is returning potentially null values? I'm curious if this is caused by an auto-generated query/mutation of ours or if it is custom business logic in a custom query/mutation.

WojciechKasprzyk commented 21 hours ago

Hi @chrisbonifacio Unfortunately I cannot, but as far as I know there is a model issue the causes API error an then responses null data. Anyway, what does it change? The code should be prepared for null as it is described in comment 😄

chrisbonifacio commented 21 hours ago

@WojciechKasprzyk I'm trying to figure out how to reproduce the behavior so we can address it but I can't think of a scenario where a null might be in the response. Is the shape of the response an array of items and some null values in the array? Or is the server returning only null?

WojciechKasprzyk commented 21 hours ago

This is the response I get

image
chrisbonifacio commented 21 hours ago

oh okay, I believe that particular error message means that the query is asking for fields that don't exist on the schema.

Can you confirm that parentGci and parentChannelID are defined as fields on the Category model?

WojciechKasprzyk commented 21 hours ago

Yes, they are both type of id on the Category model

chrisbonifacio commented 21 hours ago

Is that schema deployed and up to date in the AppSync console?

WojciechKasprzyk commented 21 hours ago

it was not in sync, now there is no this error - I get different ehhh... 😄 But still the condition in amplify codebase is invalid

chrisbonifacio commented 20 hours ago

We will look into the discrepancy in the codebase.

In the meantime, are you getting a different error now or are you unblocked at this time?

WojciechKasprzyk commented 8 hours ago

Oh, I'm unblocked at this time, thank you very much @chrisbonifacio for helping me, I really appreciate 😄