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.42k stars 2.12k forks source link

List queries retrieve an empty array #9719

Closed OmarAbaroa closed 2 years ago

OmarAbaroa commented 2 years ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

GraphQL API

Amplify Categories

api

Environment information

``` # Put output below this line System: OS: macOS 12.0.1 CPU: (8) arm64 Apple M1 Memory: 175.39 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.14.0 - /usr/local/bin/node npm: 8.3.1 - /opt/homebrew/bin/npm Watchman: 2021.11.15.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 99.0.4844.74 Firefox: 98.0.1 Safari: 15.1 npmPackages: @amplitude/react-native: ^2.8.0 => 2.8.0 @babel/core: ^7.12.9 => 7.16.5 @expo/vector-icons: ^12.0.0 => 12.0.5 @hookform/resolvers: ^2.8.8 => 2.8.8 @logrocket/react-native: ^0.28.0 => 0.28.0 @react-native-async-storage/async-storage: ~1.15.0 => 1.15.14 @react-native-community/netinfo: 7.1.3 => 7.1.3 @react-native-picker/picker: 2.2.1 => 2.2.1 (1.16.8) @react-navigation/bottom-tabs: ^6.0.5 => 6.0.9 @react-navigation/native: ^6.0.2 => 6.0.6 @react-navigation/native-stack: ^6.1.0 => 6.2.5 @react-navigation/stack: ^6.0.11 => 6.0.11 @types/i18n-js: ^3.8.2 => 3.8.2 @types/jest: ^27.0.2 => 27.0.3 @types/lodash: ^4.14.176 => 4.14.178 @types/react: ~17.0.21 => 17.0.38 @types/react-native: ~0.64.12 => 0.64.20 @types/react-native-snap-carousel: ^3.8.4 => 3.8.5 @types/react-test-renderer: ^17.0.1 => 17.0.1 @typescript-eslint/eslint-plugin: ^5.2.0 => 5.8.1 @typescript-eslint/parser: ^5.2.0 => 5.8.1 HelloWorld: 0.0.1 amazon-cognito-identity-js: ^5.2.7 => 5.2.7 aws-amplify: ^4.3.15 => 4.3.15 aws-amplify-react-native: ^6.0.3 => 6.0.3 aws-sdk: ^2.1046.0 => 2.1048.0 class-validator: 1.0.0 computed-types: 1.0.0 eslint: ^7.32.0 => 7.32.0 eslint-config-airbnb: ^18.2.1 => 18.2.1 eslint-config-prettier: ^8.3.0 => 8.3.0 eslint-plugin-import: ^2.25.2 => 2.25.3 eslint-plugin-jest: ^25.2.2 => 25.3.2 eslint-plugin-jsx-a11y: ^6.4.1 => 6.5.1 eslint-plugin-prettier: ^4.0.0 => 4.0.0 eslint-plugin-react: ^7.26.1 => 7.28.0 eslint-plugin-react-hooks: ^4.2.0 => 4.3.0 eslint-plugin-react-native: ^4.0.0 => 4.0.0 eslint-plugin-spellcheck: ^0.0.19 => 0.0.19 expo: ^44.0.0 => 44.0.3 expo-asset: ~8.4.6 => 8.4.6 expo-clipboard: ~2.1.0 => 2.1.1 expo-constants: ~13.0.1 => 13.0.1 expo-dev-client: ~0.8.4 => 0.8.4 expo-font: ~10.0.4 => 10.0.4 expo-linking: ~3.0.0 => 3.0.0 expo-localization: ~12.0.0 => 12.0.0 expo-location: ~14.0.1 => 14.0.1 expo-splash-screen: ~0.14.1 => 0.14.1 expo-status-bar: ~1.2.0 => 1.2.0 expo-updates: ~0.11.6 => 0.11.6 expo-web-browser: ~10.1.0 => 10.1.0 hermes-inspector-msggen: 1.0.0 husky: ^7.0.4 => 7.0.4 i18n-js: ^3.8.0 => 3.8.0 io-ts: 1.0.0 jest-expo: ^44.0.0 => 44.0.1 joi: 1.0.0 lint-staged: ^11.2.6 => 11.2.6 lodash: ^4.17.21 => 4.17.21 lottie-react-native: 5.0.1 => 5.0.1 nope: 1.0.0 prettier: ^2.4.1 => 2.5.1 react: 17.0.1 => 17.0.1 (17.0.2) react-dom: 17.0.1 => 17.0.1 react-hook-form: ^7.26.0 => 7.26.1 react-native: 0.64.3 => 0.64.3 react-native-collapsible: ^1.6.0 => 1.6.0 react-native-date-picker: ^4.2.0 => 4.2.0 react-native-emoji-selector: ^0.2.0 => 0.2.0 react-native-geolocation-service: ^5.3.0-beta.3 => 5.3.0-beta.4 react-native-gesture-handler: ~2.1.0 => 2.1.0 react-native-keyboard-aware-scroll-view: ^0.9.5 => 0.9.5 react-native-mask-input: ^1.1.1 => 1.1.1 react-native-mask-text: ^0.7.0 => 0.7.0 react-native-picker-select: ^8.0.4 => 8.0.4 react-native-reanimated: ~2.4.1 => 2.4.1 react-native-safe-area-context: 3.3.2 => 3.3.2 react-native-screens: ~3.10.1 => 3.10.1 react-native-snap-carousel: ^3.9.1 => 3.9.1 react-native-svg: 12.1.1 => 12.1.1 react-native-web: 0.17.1 => 0.17.1 react-native-webview: 11.17.2 => 11.17.2 react-test-renderer: ^16.13.1 => 16.14.0 (17.0.2) superstruct: 1.0.0 svg-path-properties: ^1.0.11 => 1.0.11 typanion: 1.0.0 typescript: ~4.3.5 => 4.3.5 uuid: ^8.3.2 => 8.3.2 (3.4.0, 3.3.2, 7.0.3) vest: 1.0.0 yup: ^0.32.11 => 0.32.11 (1.0.0) zod: 1.0.0 npmGlobalPackages: @aws-amplify/cli: 7.6.24 expo-cli: 5.3.0 n: 8.0.0 npm: 8.3.1 react-devtools: 4.23.0 ```

Describe the bug

We have a graphql API and we need to list objects using the list queries with a secondary index that helps us to sort the data by date.

In the graphql schema we wrote the auth rules to allow owners to create, read, delete and update their data.

However since last week the list queries are retrieving an empty array of items for our users, even if we know the user has objects that they own.

We recently learned that we might need to add a limit (eg 1000) to the queries and page through results via the nextToken. Strangely, these queries were working fine before a couple of weeks ago and without the use of the limit or nextToken. When we add the limit 1000 and nextToken, we see results for our users.

We're on graphql transformer v2.

Expected behavior

We would expect the list queries to retrieve the expected items without the need for the limit and paging described above and as it was working a couple of weeks ago.

Reproduction steps

  1. Generate a graphql schema with models and secondary indexes to sort by "CreatedAt" and owner auth rules

type FinancialModel @model @auth(rules: [{ allow: owner }, { allow: groups, groups: ["Admin"] }]) { type: FinancialModelType! @index( name: "listFinancialModelsByDate" queryField: "listFinancialModelsByDate" sortKeyFields: ["createdAt"] ) id: ID! @primaryKey }

  1. Create records owned by a user
  2. Open AppSync console
  3. Login with that user
  4. Run List queries using the secondary indexes

query MyQuery { listFinancialModelsByDate(type: FinancialModel, sortDirection: ASC) { items { id } nextToken } }

Captura de Pantalla 2022-03-18 a la(s) 17 10 27

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

chrisbonifacio commented 2 years ago

Hi @OmarAbaroa 👋 thanks for raising this issue. Can also you share the schema for your FinancialModelType?

chrisbonifacio commented 2 years ago

It seems that you might've been running into a known limitation of the AppSync service. There is a fetch limit of 1000 records because of the service quota for Iterations in a foreach loop in mapping templates.

Including a limit and nextToken in subsequent queries until nextToken is no longer returned (meaning there are no more records that meet filter criteria to fetch) is the correct approach to this limitation.

P.S. For customers using DataStore, there is the DataStore.observeQuery method which works similarly, fetching records in a paginated way until all records have been fetched and 'isSyncedistrue`.

https://docs.amplify.aws/lib/datastore/real-time/q/platform/js/

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.