aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 76 forks source link

Datastore - TypeError: Cannot read property 'items' of null #1798

Open mhyassin opened 1 year ago

mhyassin commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication, Analytics, GraphQL API, DataStore, Storage

Amplify Categories

No response

Environment information

``` # Put output below this line System: OS: macOS 13.4.1 CPU: (10) arm64 Apple M1 Pro Memory: 154.89 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.3.0 - /opt/homebrew/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 9.6.7 - /opt/homebrew/bin/npm Watchman: 2023.06.12.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 115.0.5790.170 Firefox: 116.0.2 Safari: 16.5.2 npmPackages: @babel/core: ^7.20.0 => 7.21.3 (7.22.8, 7.18.13) @babel/eslint-parser: ^7.18.2 => 7.18.9 @babel/preset-env: ^7.20.0 => 7.20.2 (7.22.7) @babel/runtime: ^7.20.0 => 7.21.0 (7.18.9, 7.19.0) @commitlint/cli: ^17.0.3 => 17.0.3 @commitlint/config-conventional: ^17.0.3 => 17.0.3 @georstat/react-native-image-cache: 2.8.0 => 2.8.0 @react-native-async-storage/async-storage: 1.19.1 => 1.19.1 @react-native-clipboard/clipboard: 1.10.0 => 1.10.0 @react-native-community/datetimepicker: 6.1.3 => 6.1.3 @react-native-community/eslint-config: ^3.2.0 => 3.2.0 @react-native-community/eslint-plugin: ^1.3.0 => 1.3.0 (1.2.0) @react-native-community/netinfo: 9.4.1 => 9.4.1 @react-native-firebase/app: 15.7.0 => 15.7.0 @react-native-firebase/messaging: 15.7.0 => 15.7.0 @react-native-picker/picker: 2.4.1 => 2.4.1 (1.16.8) @react-navigation/bottom-tabs: 6.5.8 => 6.5.8 @react-navigation/elements: 1.3.18 => 1.3.18 @react-navigation/native: 6.1.7 => 6.1.7 @react-navigation/native-stack: 6.9.13 => 6.9.13 @react-navigation/stack: 6.3.17 => 6.3.17 @sentry/react-native: 5.1.1 => 5.1.1 @tsconfig/react-native: ^3.0.2 => 3.0.2 @types/d3-scale: 4.0.3 => 4.0.3 @types/jest: ^29.5.2 => 29.5.2 @types/lodash: 4.14.185 => 4.14.185 @types/react: 18.0.24 => 18.0.24 (18.0.17) @types/react-native-autocomplete-input: ^5.1.1 => 5.1.1 @types/react-native-vector-icons: 6.4.11 => 6.4.11 @types/react-native-version-check: 3.4.5 => 3.4.5 @types/react-test-renderer: 18.0.0 => 18.0.0 @typescript-eslint/eslint-plugin: ^5.61.0 => 5.61.0 (5.34.0) @typescript-eslint/parser: ^5.61.0 => 5.61.0 (5.34.0) HelloWorld: 0.0.1 amazon-cognito-identity-js: 6.3.1 => 6.3.1 amazon-cognito-identity-js/internals: undefined () aws-amplify: 5.3.6 => 5.3.6 axios: 0.27.2 => 0.27.2 (0.26.0) babel-jest: ^29.2.1 => 29.5.0 babel-plugin-module-resolver: 4.1.0 => 4.1.0 core-js: 3.30.2 => 3.30.2 crypto-js: 4.1.1 => 4.1.1 d3: 7.4.4 => 7.4.4 d3-array: 3.1.6 => 3.1.6 (3.2.0) d3-scale: 4.0.2 => 4.0.2 d3-shape: 3.1.0 => 3.1.0 date-fns: 2.28.0 => 2.28.0 eslint: ^8.21.0 => 8.22.0 eslint-config-prettier: 8.5.0 => 8.5.0 eslint-plugin-jest: ^26.8.2 => 26.8.7 fs-extra: ^10.1.0 => 10.1.0 (8.1.0, 11.1.1) graphql: 15.7.0 => 15.7.0 (15.8.0) husky: 8.0.1 => 8.0.1 i18next: 21.8.10 => 21.8.10 javascript-time-ago: 2.5.9 => 2.5.9 javascript-time-ago/cache: undefined () javascript-time-ago/commonjs: undefined () javascript-time-ago/gradation: undefined () javascript-time-ago/load-all-locales: undefined () javascript-time-ago/locale/af: undefined () javascript-time-ago/locale/am: undefined () javascript-time-ago/locale/ar: undefined () javascript-time-ago/locale/ar-AE: undefined () javascript-time-ago/locale/as: undefined () javascript-time-ago/locale/ast: undefined () javascript-time-ago/locale/az: undefined () javascript-time-ago/locale/be: undefined () javascript-time-ago/locale/bg: undefined () javascript-time-ago/locale/bgc: undefined () javascript-time-ago/locale/bn: undefined () javascript-time-ago/locale/br: undefined () javascript-time-ago/locale/brx: undefined () javascript-time-ago/locale/bs: undefined () javascript-time-ago/locale/bs-Cyrl: undefined () javascript-time-ago/locale/ca: undefined () javascript-time-ago/locale/ccp: undefined () javascript-time-ago/locale/ce: undefined () javascript-time-ago/locale/ceb: undefined () javascript-time-ago/locale/chr: undefined () javascript-time-ago/locale/cs: undefined () javascript-time-ago/locale/cv: undefined () javascript-time-ago/locale/cy: undefined () javascript-time-ago/locale/da: undefined () javascript-time-ago/locale/de: undefined () javascript-time-ago/locale/dsb: undefined () javascript-time-ago/locale/dz: undefined () javascript-time-ago/locale/ee: undefined () javascript-time-ago/locale/el: undefined () javascript-time-ago/locale/en: undefined () javascript-time-ago/locale/en-001: undefined () javascript-time-ago/locale/en-150: undefined () javascript-time-ago/locale/en-AG: undefined () javascript-time-ago/locale/en-AI: undefined () javascript-time-ago/locale/en-AT: undefined () javascript-time-ago/locale/en-AU: undefined () javascript-time-ago/locale/en-BB: undefined () javascript-time-ago/locale/en-BE: undefined () javascript-time-ago/locale/en-BM: undefined () javascript-time-ago/locale/en-BS: undefined () javascript-time-ago/locale/en-BW: undefined () javascript-time-ago/locale/en-BZ: undefined () javascript-time-ago/locale/en-CA: undefined () javascript-time-ago/locale/en-CC: undefined () javascript-time-ago/locale/en-CH: undefined () javascript-time-ago/locale/en-CK: undefined () javascript-time-ago/locale/en-CM: undefined () javascript-time-ago/locale/en-CX: undefined () javascript-time-ago/locale/en-CY: undefined () javascript-time-ago/locale/en-DE: undefined () javascript-time-ago/locale/en-DG: undefined () javascript-time-ago/locale/en-DK: undefined () javascript-time-ago/locale/en-DM: undefined () javascript-time-ago/locale/en-ER: undefined () javascript-time-ago/locale/en-FI: undefined () javascript-time-ago/locale/en-FJ: undefined () javascript-time-ago/locale/en-FK: undefined () javascript-time-ago/locale/en-FM: undefined () javascript-time-ago/locale/en-GB: undefined () javascript-time-ago/locale/en-GD: undefined () javascript-time-ago/locale/en-GG: undefined () javascript-time-ago/locale/en-GH: undefined () javascript-time-ago/locale/en-GI: undefined () javascript-time-ago/locale/en-GM: undefined () javascript-time-ago/locale/en-GY: undefined () javascript-time-ago/locale/en-HK: undefined () javascript-time-ago/locale/en-IE: undefined () javascript-time-ago/locale/en-IL: undefined () javascript-time-ago/locale/en-IM: undefined () javascript-time-ago/locale/en-IN: undefined () javascript-time-ago/locale/en-IO: undefined () javascript-time-ago/locale/en-JE: undefined () javascript-time-ago/locale/en-JM: undefined () javascript-time-ago/locale/en-KE: undefined () javascript-time-ago/locale/en-KI: undefined () javascript-time-ago/locale/en-KN: undefined () javascript-time-ago/locale/en-KY: undefined () javascript-time-ago/locale/en-LC: undefined () javascript-time-ago/locale/en-LR: undefined () javascript-time-ago/locale/en-LS: undefined () javascript-time-ago/locale/en-MG: undefined () javascript-time-ago/locale/en-MO: undefined () javascript-time-ago/locale/en-MS: undefined () javascript-time-ago/locale/en-MT: undefined () javascript-time-ago/locale/en-MU: undefined () javascript-time-ago/locale/en-MV: undefined () javascript-time-ago/locale/en-MW: undefined () javascript-time-ago/locale/en-MY: undefined () javascript-time-ago/locale/en-NA: undefined () javascript-time-ago/locale/en-NF: undefined () javascript-time-ago/locale/en-NG: undefined () javascript-time-ago/locale/en-NL: undefined () javascript-time-ago/locale/en-NR: undefined () javascript-time-ago/locale/en-NU: undefined () javascript-time-ago/locale/en-NZ: undefined () javascript-time-ago/locale/en-PG: undefined () javascript-time-ago/locale/en-PK: undefined () javascript-time-ago/locale/en-PN: undefined () javascript-time-ago/locale/en-PW: undefined () javascript-time-ago/locale/en-RW: undefined () javascript-time-ago/locale/en-SB: undefined () javascript-time-ago/locale/en-SC: undefined () javascript-time-ago/locale/en-SD: undefined () javascript-time-ago/locale/en-SE: undefined () javascript-time-ago/locale/en-SG: undefined () javascript-time-ago/locale/en-SH: undefined () javascript-time-ago/locale/en-SI: undefined () javascript-time-ago/locale/en-SL: undefined () javascript-time-ago/locale/en-SS: undefined () javascript-time-ago/locale/en-SX: undefined () javascript-time-ago/locale/en-SZ: undefined () javascript-time-ago/locale/en-TC: undefined () javascript-time-ago/locale/en-TK: undefined () javascript-time-ago/locale/en-TO: undefined () javascript-time-ago/locale/en-TT: undefined () javascript-time-ago/locale/en-TV: undefined () javascript-time-ago/locale/en-TZ: undefined () javascript-time-ago/locale/en-UG: undefined () javascript-time-ago/locale/en-VC: undefined () javascript-time-ago/locale/en-VG: undefined () javascript-time-ago/locale/en-VU: undefined () javascript-time-ago/locale/en-WS: undefined () javascript-time-ago/locale/en-ZA: undefined () javascript-time-ago/locale/en-ZM: undefined () javascript-time-ago/locale/en-ZW: undefined () javascript-time-ago/locale/eo: undefined () javascript-time-ago/locale/es: undefined () javascript-time-ago/locale/es-419: undefined () javascript-time-ago/locale/es-AR: undefined () javascript-time-ago/locale/es-BO: undefined () javascript-time-ago/locale/es-BR: undefined () javascript-time-ago/locale/es-BZ: undefined () javascript-time-ago/locale/es-CL: undefined () javascript-time-ago/locale/es-CO: undefined () javascript-time-ago/locale/es-CR: undefined () javascript-time-ago/locale/es-CU: undefined () javascript-time-ago/locale/es-DO: undefined () javascript-time-ago/locale/es-EC: undefined () javascript-time-ago/locale/es-GT: undefined () javascript-time-ago/locale/es-HN: undefined () javascript-time-ago/locale/es-MX: undefined () javascript-time-ago/locale/es-NI: undefined () javascript-time-ago/locale/es-PA: undefined () javascript-time-ago/locale/es-PE: undefined () javascript-time-ago/locale/es-PR: undefined () javascript-time-ago/locale/es-PY: undefined () javascript-time-ago/locale/es-SV: undefined () javascript-time-ago/locale/es-US: undefined () javascript-time-ago/locale/es-UY: undefined () javascript-time-ago/locale/es-VE: undefined () javascript-time-ago/locale/et: undefined () javascript-time-ago/locale/eu: undefined () javascript-time-ago/locale/fa: undefined () javascript-time-ago/locale/ff-Adlm: undefined () javascript-time-ago/locale/fi: undefined () javascript-time-ago/locale/fil: undefined () javascript-time-ago/locale/fo: undefined () javascript-time-ago/locale/fr: undefined () javascript-time-ago/locale/fr-CA: undefined () javascript-time-ago/locale/fur: undefined () javascript-time-ago/locale/fy: undefined () javascript-time-ago/locale/ga: undefined () javascript-time-ago/locale/gd: undefined () javascript-time-ago/locale/gl: undefined () javascript-time-ago/locale/gu: undefined () javascript-time-ago/locale/ha: undefined () javascript-time-ago/locale/he: undefined () javascript-time-ago/locale/hi: undefined () javascript-time-ago/locale/hi-Latn: undefined () javascript-time-ago/locale/hr: undefined () javascript-time-ago/locale/hsb: undefined () javascript-time-ago/locale/hu: undefined () javascript-time-ago/locale/hy: undefined () javascript-time-ago/locale/ia: undefined () javascript-time-ago/locale/id: undefined () javascript-time-ago/locale/ig: undefined () javascript-time-ago/locale/is: undefined () javascript-time-ago/locale/it: undefined () javascript-time-ago/locale/ja: undefined () javascript-time-ago/locale/jgo: undefined () javascript-time-ago/locale/jv: undefined () javascript-time-ago/locale/ka: undefined () javascript-time-ago/locale/kea: undefined () javascript-time-ago/locale/kgp: undefined () javascript-time-ago/locale/kk: undefined () javascript-time-ago/locale/kl: undefined () javascript-time-ago/locale/km: undefined () javascript-time-ago/locale/kn: undefined () javascript-time-ago/locale/ko: undefined () javascript-time-ago/locale/kok: undefined () javascript-time-ago/locale/ks: undefined () javascript-time-ago/locale/ksh: undefined () javascript-time-ago/locale/ku: undefined () javascript-time-ago/locale/ky: undefined () javascript-time-ago/locale/lb: undefined () javascript-time-ago/locale/lkt: undefined () javascript-time-ago/locale/lo: undefined () javascript-time-ago/locale/lt: undefined () javascript-time-ago/locale/lv: undefined () javascript-time-ago/locale/mai: undefined () javascript-time-ago/locale/mi: undefined () javascript-time-ago/locale/mk: undefined () javascript-time-ago/locale/ml: undefined () javascript-time-ago/locale/mn: undefined () javascript-time-ago/locale/mni: undefined () javascript-time-ago/locale/mr: undefined () javascript-time-ago/locale/ms: undefined () javascript-time-ago/locale/mt: undefined () javascript-time-ago/locale/my: undefined () javascript-time-ago/locale/mzn: undefined () javascript-time-ago/locale/nb: undefined () javascript-time-ago/locale/ne: undefined () javascript-time-ago/locale/nl: undefined () javascript-time-ago/locale/nn: undefined () javascript-time-ago/locale/no: undefined () javascript-time-ago/locale/or: undefined () javascript-time-ago/locale/pa: undefined () javascript-time-ago/locale/pcm: undefined () javascript-time-ago/locale/pl: undefined () javascript-time-ago/locale/ps: undefined () javascript-time-ago/locale/ps-PK: undefined () javascript-time-ago/locale/pt: undefined () javascript-time-ago/locale/pt-AO: undefined () javascript-time-ago/locale/pt-CH: undefined () javascript-time-ago/locale/pt-CV: undefined () javascript-time-ago/locale/pt-GQ: undefined () javascript-time-ago/locale/pt-GW: undefined () javascript-time-ago/locale/pt-LU: undefined () javascript-time-ago/locale/pt-MO: undefined () javascript-time-ago/locale/pt-MZ: undefined () javascript-time-ago/locale/pt-PT: undefined () javascript-time-ago/locale/pt-ST: undefined () javascript-time-ago/locale/pt-TL: undefined () javascript-time-ago/locale/qu: undefined () javascript-time-ago/locale/raj: undefined () javascript-time-ago/locale/rm: undefined () javascript-time-ago/locale/ro: undefined () javascript-time-ago/locale/ru: undefined () javascript-time-ago/locale/sah: undefined () javascript-time-ago/locale/sc: undefined () javascript-time-ago/locale/sd: undefined () javascript-time-ago/locale/se: undefined () javascript-time-ago/locale/se-FI: undefined () javascript-time-ago/locale/si: undefined () javascript-time-ago/locale/sk: undefined () javascript-time-ago/locale/sl: undefined () javascript-time-ago/locale/so: undefined () javascript-time-ago/locale/sq: undefined () javascript-time-ago/locale/sr: undefined () javascript-time-ago/locale/sr-Cyrl-BA: undefined () javascript-time-ago/locale/sr-Latn: undefined () javascript-time-ago/locale/sr-Latn-BA: undefined () javascript-time-ago/locale/su: undefined () javascript-time-ago/locale/sv: undefined () javascript-time-ago/locale/sw: undefined () javascript-time-ago/locale/ta: undefined () javascript-time-ago/locale/te: undefined () javascript-time-ago/locale/tg: undefined () javascript-time-ago/locale/th: undefined () javascript-time-ago/locale/ti: undefined () javascript-time-ago/locale/tk: undefined () javascript-time-ago/locale/to: undefined () javascript-time-ago/locale/tr: undefined () javascript-time-ago/locale/tt: undefined () javascript-time-ago/locale/ug: undefined () javascript-time-ago/locale/uk: undefined () javascript-time-ago/locale/ur: undefined () javascript-time-ago/locale/ur-IN: undefined () javascript-time-ago/locale/uz: undefined () javascript-time-ago/locale/uz-Cyrl: undefined () javascript-time-ago/locale/vi: undefined () javascript-time-ago/locale/wae: undefined () javascript-time-ago/locale/wo: undefined () javascript-time-ago/locale/xh: undefined () javascript-time-ago/locale/yi: undefined () javascript-time-ago/locale/yo: undefined () javascript-time-ago/locale/yo-BJ: undefined () javascript-time-ago/locale/yrl: undefined () javascript-time-ago/locale/yue: undefined () javascript-time-ago/locale/yue-Hans: undefined () javascript-time-ago/locale/zh: undefined () javascript-time-ago/locale/zh-Hans-HK: undefined () javascript-time-ago/locale/zh-Hans-MO: undefined () javascript-time-ago/locale/zh-Hans-SG: undefined () javascript-time-ago/locale/zh-Hant: undefined () javascript-time-ago/locale/zh-Hant-HK: undefined () javascript-time-ago/locale/zh-Hant-MO: undefined () javascript-time-ago/locale/zu: undefined () javascript-time-ago/prop-types: undefined () javascript-time-ago/steps: undefined () jest: ^29.2.1 => 29.5.0 jest-environment-jsdom: ^29.5.0 => 29.5.0 jest-transform-stub: 2.0.0 => 2.0.0 lint-staged: ^13.2.3 => 13.2.3 lodash-es: 4.17.21 => 4.17.21 lottie-react-native: 5.1.4 => 5.1.4 metro-react-native-babel-preset: 0.73.9 => 0.73.9 moment: 2.29.4 => 2.29.4 polished: 4.2.2 => 4.2.2 prettier: 2.8.8 => 2.8.8 react: 18.2.0 => 18.2.0 react-i18next: 11.18.3 => 11.18.3 react-native: 0.71.7 => 0.71.7 react-native-appsflyer: 6.10.2 => 6.10.2 react-native-autocomplete-input: 5.2.0 => 5.2.0 react-native-bootsplash: 4.6.0 => 4.6.0 react-native-config: 1.4.6 => 1.4.6 react-native-email-link: 1.14.1 => 1.14.1 react-native-file-access: 3.0.4 => 3.0.4 react-native-gesture-handler: 2.12.0 => 2.12.0 react-native-image-crop-picker: 0.39.0 => 0.39.0 react-native-inappbrowser-reborn: 3.7.0 => 3.7.0 react-native-keyboard-aware-scroll-view: 0.9.5 => 0.9.5 react-native-linear-gradient: 2.6.2 => 2.6.2 react-native-localize: 2.2.4 => 2.2.4 react-native-picker-select: 8.0.4 => 8.0.4 react-native-purchases: 5.2.2 => 5.2.2 react-native-reanimated: 3.3.0 => 3.3.0 react-native-reanimated-carousel: 3.3.2 => 3.3.2 react-native-safe-area-context: 4.4.1 => 4.4.1 react-native-screens: 3.18.2 => 3.18.2 react-native-shared-element: 0.8.4 => 0.8.4 react-native-snackbar: 2.4.0 => 2.4.0 react-native-svg: 12.4.4 => 12.4.4 react-native-svg-transformer: 1.0.0 => 1.0.0 react-native-toast-message: 2.1.5 => 2.1.5 react-native-track-player: 2.1.3 => 2.1.3 react-native-vector-icons: 9.2.0 => 9.2.0 react-native-version-check: 3.4.7 => 3.4.7 react-native-webview: 11.22.2 => 11.22.2 react-navigation-shared-element: 3.1.3 => 3.1.3 react-test-renderer: 18.2.0 => 18.2.0 react-time-ago: 7.2.1 => 7.2.1 react-time-ago/commonjs: undefined () styled-components: 6.0.4 => 6.0.4 styled-components/macro: undefined () styled-components/native: undefined () terra-react: 1.4.18 => 1.4.18 tiny-timer: 1.6.0 => 1.6.0 ts-jest: ^29.1.1 => 29.1.1 ts-node: ^10.9.1 => 10.9.1 typescript: ^4.9.5 => 4.9.5 (4.7.4) zustand: 4.3.6 => 4.3.6 npmGlobalPackages: @sentry/wizard: 2.2.1 create-react-native-app: 3.8.0 ios-deploy: 1.11.4 npm: 9.6.7 react-devtools: 4.25.0 ts-node: 10.9.1 vercel: 27.2.0 yarn: 1.22.19 ```

Describe the bug

Our DataStore's initial sync is kind of fast, but after that every time I close the app and re opens (should trigger delta sync) the ready event takes too much time to be sent, while debugging Amplify I saw a lot of these errors

 LOG  [DEBUG] 56:29.21 Util - error on  [TypeError: Cannot read property 'items' of null]

I noticed that they are being logged after trying to execute the sync queries(7 out of 9 models, the other 2 are syncing quite fine), they keep being attempted 12 times, after the 12th attempt this is logged:

 LOG  [DEBUG] 59:54.606 Util - error on  [TypeError: Cannot read property 'items' of null]
 LOG  [DEBUG] 59:54.606 Util -  retrying in false ms
 LOG  [DEBUG] 59:54.607 DataStore - Sync failed with authMode: AMAZON_COGNITO_USER_POOLS [TypeError: Cannot read property 'items' of null]
 WARN  [WARN] 59:54.608 DataStore - User is unauthorized to query syncWorkouts with auth mode AMAZON_COGNITO_USER_POOLS. No data could be returned.

I researched for the User is unauthorized issue and the fix in aws-amplify/amplify-js#9179 isn't working, and there are no UnauthorizedException in the appsync logs

Since the ready event is taking forever to be sent the outbox doesn't get synced at all, till all the 12 attempts are done Project identifier: 1f41c9d6304e82061193f8ee2e85ae0a

Expected behavior

User should be authorized to sync queries

Reproduction steps

  1. Create a react native app with @auth models
  2. Login with a user
  3. Close app
  4. Open app again

Code Snippet

// Put your code below this line.
DataStore.configure({
  syncExpressions: models.map((model) =>
    syncExpression(model, async () => {
      const authedUserName = (await Auth.currentAuthenticatedUser()).username;
      return (m) => m.user_name.eq(authedUserName);
    })
  ),
});

Log output

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

aws-exports.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "eu-central-1",
    "aws_mobile_analytics_app_id": "a1388dec81a442ceb839f84d167a11a8",
    "aws_mobile_analytics_app_region": "eu-central-1",
    "Analytics": {
        "AWSPinpoint": {
            "appId": "a1388dec81a442ceb839f84d167a11a8",
            "region": "eu-central-1"
        }
    },
    "aws_appsync_graphqlEndpoint": "https://ahimr3zb4fgulabuhizhyfr7p4.appsync-api.eu-central-1.amazonaws.com/graphql",
    "aws_appsync_region": "eu-central-1",
    "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
    "aws_cognito_identity_pool_id": "eu-central-1:db005f1f-ac80-4c2b-b7ad-a1f97d4f4d0a",
    "aws_cognito_region": "eu-central-1",
    "aws_user_pools_id": "eu-central-1_647mHYjCN",
    "aws_user_pools_web_client_id": "65nn0jjpl05h9r18oh4sgkf9u6",
    "oauth": {
        "domain": "testing.auth.api.onvy.health.auth.eu-central-1.amazoncognito.com",
        "scope": [
            "aws.cognito.signin.user.admin",
            "email",
            "openid",
            "phone",
            "profile"
        ],
        "redirectSignIn": "onvyapp://",
        "redirectSignOut": "onvyapp://",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_POOLS",
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [
        "GOOGLE",
        "APPLE"
    ],
    "aws_cognito_signup_attributes": [],
    "aws_cognito_mfa_configuration": "OPTIONAL",
    "aws_cognito_mfa_types": [
        "TOTP"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ],
    "aws_user_files_s3_bucket": "testing-onvy-mobileapp",
    "aws_user_files_s3_bucket_region": "eu-central-1"
};

export default awsmobile;

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

mhyassin commented 1 year ago

So I tried removing the syncExpressions it definitely fixed the issue, but that will result in scans on the base sync

mhyassin commented 1 year ago
{"limit":1000,"nextToken":null,"lastSync":0,"filter":{"and":[{"user_name":{"eq":"XXX"}}]}}

Trying a query those vars on the delta table from the console fails as well, removing the and fixes it, we don't know why it fails though with the and operator, removing the syncExpressions fixed it because it dropped the vars

iartemiev commented 1 year ago

Removing the and from the filter expression should result in a Scan operation. The and is necessary for the generated resolver to map the filter to an index/key condition correctly.

When you execute the sync query in the AppSync Console with the arguments in your last comment, what error do you get back?

mhyassin commented 1 year ago

@iartemiev Oh interesting, that's the error on the AppSync Console Query condition missed key schema element: ds_pk (Service: DynamoDb, Status Code: 400,

iartemiev commented 1 year ago

That error suggests DynamoDB is not receiving the expected key condition when performing the query.

I tried to reproduce this with the schema you shared in this comment. But everything seems to work as expected. image

Could you enable logs on your AppSync API by going to Settings > API configurations > Edit. Select these options: image Click Save.

Go back to Queries in the Console, check the Logs checkbox in the bottom right and perform another sync query with the same arguments.

After the query executes, click the "View in Cloudwatch" link. Once the CloudWatch console opens up, filter the log events on RequestMapping syncScores

Expand the most recent log event (by timestamp) that matches that filter. Then inspect the transformedTemplate property. Please paste it here, redacting any sensitive information if present. It should look similar to this: image

mhyassin commented 1 year ago

Hey @iartemiev, thanks a lot for looking this further it is very important for us as it is causing us a lot of production issues right now.

Right now I can't actually replicate the issue for the scores table with my user at least, it seems to be random somehow, we have 9 models in total, sometimes it can be reproduced on 7 or 8 of them, now I can only reproduce it on only one (on this specific environment at least)

The model I'm currently testing with looks like this:

type CoachMessage
  @model
  @auth(
    rules: [
      {
        allow: owner
        operations: [read, update, create]
        identityClaim: "username" # explicit use of username
        ownerField: "user_name"
      }
    ]
  ) {
  user_name: String! @primaryKey(sortKeyFields: ["id"])
  id: String!
  reply_to: String
  datetime: AWSDateTime!
  type: CoachMessageType!
  role: CoachMessageRole!
  content: String!
  followup_questions: [String!]
  data: String
}

I've did some queries in order to let you know exactly what fails:

  1. With lastsync set to 0

    image
  2. With last sync set to timestamp older than 30 minutes (Delta ttl)

    image
  3. With lastsync set to timestamp not older than 30 minutes (Delta ttl)

    image

This is how the transformTemplate looks like for the last query

"transformedTemplate": "                {\"version\":\"2018-05-29\",\"operation\":\"Sync\",\"limit\":1000,\"lastSync\":1691842203749,\"query\":{\"expression\":\"#pk = :pk\",\"expressionNames\":{\"#pk\":\"user_name\"},\"expressionValues\":{\":pk\":{\"S\":\"236448d2-9001-7036-bbec-0234424b9b3d\"}}},\"scanIndexForward\":true}\n"
image
iartemiev commented 1 year ago

I verified with the team that manages the Amplify GraphQL Transformer (https://github.com/aws-amplify/amplify-category-api/) that there is a limitation that prevents us from performing a Query operation against the Delta table when using a custom PK.

Overall, we don't recommend using the owner field as the primary key (see grey call out in this section of the docs https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access)

I suggest changing your data model to use a separate primary key field and then creating a GSI using the @index directive on your owner field. That'll allow you to use that field in your selective sync expression successfully.

I'll transfer this issue to the category-api repo

mhyassin commented 1 year ago

@iartemiev Thanks a lot for the help!

May you elaborate more on why is it not recommended to use the the owner field as the primary key? is it only because of that delta table issue? or is there something else?

So if that PR you mentioned gets merged, would it then be possible to use the owner field as a primary key? creating another index would double our storage pricing