Skip to content

observeQuery errors without including selectionSet #14582

@dancj

Description

@dancj

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

Amplify Gen 2

Environment information

# Put output below this line
System:
    OS: macOS 15.5
    CPU: (8) arm64 Apple M1 Pro
    Memory: 106.42 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 11.6.1 - ~/.nvm/versions/node/v22.12.0/bin/npm
    Watchman: 2025.05.26.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 123.1.64.116
    Chrome: 140.0.7339.215
    Edge: 140.0.3485.94
    Safari: 18.5
  npmPackages:
    @aws-amplify/backend: ^1.16.1 => 1.16.1 
    @aws-amplify/backend-cli: ^1.8.0 => 1.8.0 
    @aws-amplify/ui-react: ^6.12.0 => 6.12.0 
    @aws-amplify/ui-react-internal:  undefined ()
    @aws-amplify/ui-react-server:  undefined ()
    @aws-sdk/client-eventbridge: ^3.891.0 => 3.891.0 
    @aws-sdk/lib-dynamodb: ^3.888.0 => 3.890.0 
    @aws-sdk/util-dynamodb: ^3.888.0 => 3.890.0 
    @dotenvx/dotenvx: ^1.49.1 => 1.49.1 
    @headlessui/react: ^2.2.8 => 2.2.8 
    @heroicons/react: ^2.2.0 => 2.2.0 
    @reduxjs/toolkit: ^2.9.0 => 2.9.0 
    @reduxjs/toolkit-query:  1.0.0 
    @reduxjs/toolkit-query-react:  1.0.0 
    @reduxjs/toolkit-react:  1.0.0 
    @tailwindcss/forms: ^0.5.10 => 0.5.10 
    @tailwindcss/postcss: ^4.1.13 => 4.1.13 
    @tailwindcss/vite: ^4.1.13 => 4.1.13 
    @testing-library/jest-dom: ^6.8.0 => 6.8.0 
    @testing-library/react: ^16.3.0 => 16.3.0 
    @types/aws-lambda: ^8.10.152 => 8.10.152 
    @types/crypto-js: ^4.2.2 => 4.2.2 
    @types/react: ^19.1.10 => 19.1.13 
    @types/react-dom: ^19.1.7 => 19.1.9 
    @types/react-modal: ^3.16.3 => 3.16.3 
    @types/redux-mock-store: ^1.5.0 => 1.5.0 
    @types/testing-library__jest-dom: ^5.14.9 => 5.14.9 
    @types/testing-library__react: ^10.0.1 => 10.0.1 
    @typescript-eslint/eslint-plugin: ^6.2.1 => 6.21.0 
    @typescript-eslint/parser: ^6.2.1 => 6.21.0 
    @vis.gl/react-google-maps: ^1.5.5 => 1.5.5 
    @vitejs/plugin-react: ^5.0.2 => 5.0.3 
    @vitejs/plugin-react-swc: ^4.0.0 => 4.1.0 
    autoprefixer: ^10.4.21 => 10.4.21 
    aws-amplify: ^6.15.6 => 6.15.6 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/adapter-core/internals:  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/internals:  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 ()
    aws-cdk-lib: ^2.215.0 => 2.215.0 
    constructs: ^10.4.2 => 10.4.2 
    crypto-js: ^4.2.0 => 4.2.0 
    date-fns: ^4.1.0 => 4.1.0 
    esbuild: ^0.25.9 => 0.25.10 
    eslint: ^8.46.0 => 8.57.1 
    eslint-config-prettier: ^8.10.0 => 8.10.2 
    eslint-plugin-prettier: ^5.0.0 => 5.5.4 
    eslint-plugin-react: ^7.33.1 => 7.37.5 
    eslint-plugin-react-hooks: ^4.6.0 => 4.6.2 
    eslint-plugin-tailwindcss: ^3.13.0 => 3.18.2 
    form-data: ^4.0.4 => 4.0.4 
    glob: ^11.0.3 => 11.0.3 (7.2.3, 10.4.5)
    globals: ^16.3.0 => 16.4.0 (13.24.0)
    heroicons: ^2.2.0 => 2.2.0 
    postcss: ^8.5.6 => 8.5.6 
    prettier: ^3.6.2 => 3.6.2 (2.3.2, 1.19.1)
    react: ^19.1.1 => 19.1.1 (18.3.1)
    react-datepicker: ^8.7.0 => 8.7.0 
    react-dom: ^19.1.1 => 19.1.1 (18.3.1)
    react-modal: ^3.16.3 => 3.16.3 
    react-number-format: ^5.4.4 => 5.4.4 
    react-redux: ^9.2.0 => 9.2.0 
    react-router-dom: ^7.9.1 => 7.9.1 
    react-tooltip: ^5.29.1 => 5.29.1 
    rimraf: ^6.0.1 => 6.0.1 (3.0.2)
    tailwindcss: ^3.4.17 => 3.4.17 (4.1.13)
    ts-jest: ^29.4.1 => 29.4.2 
    tsx: ^4.20.5 => 4.20.5 (4.19.4)
    typescript: ^5.9.2 => 5.9.2 (4.4.4, 4.9.5)
    vite: ^7.1.2 => 7.1.5 
    vitest: ^3.2.4 => 3.2.4 
  npmGlobalPackages:
    corepack: 0.29.4
    npm: 11.6.1

Describe the bug

I'm following this observeQuery example in the gen2 docs and kept getting this error:

Uncaught TypeError: needle is null from amplify internal file findIndexByFields.ts

I resolved this by including selectionSet param, listing the properties requested.

Expected behavior

I was unaware of this selectionSet param because it wasn't in the docs page, and just assumed all properties would be returned.

Reproduction steps

  1. Create subscription observeQuery without the selectionSet specified,
  2. do some graphql create or update on the observed table
Image

Code Snippet

// Put your code below this line.
// working example with selectionSet
const querySub = client.models.VendorResult.observeQuery({
      filter: { searchSessionID: { eq: searchSessionID } },
      selectionSet: ["id", "status", "createdAt"],
      authMode: "userPool",
    }).subscribe({
      next: ({ items, isSynced }) => {
        console.log("Subscription received items:", items, "isSynced:", isSynced);
        
      },
      error: (err) => console.error("subscription error", err),
    });

Log output

// Put your logs below this line

Subscription received items: 
Array []
 isSynced: false [SubscribedVendorList.tsx:57:17](http://localhost:5173/src/components/VendorIndex/FindVendors/SubscribedVendorList.tsx)
Subscription received items: 
Array []
 isSynced: true [SubscribedVendorList.tsx:57:17](http://localhost:5173/src/components/VendorIndex/FindVendors/SubscribedVendorList.tsx)
Uncaught TypeError: can't access property "id", needle is null
    searchObject findIndexByFields.ts:12
    findIndexByFields findIndexByFields.ts:12
    ingestMessages observeQuery.ts:47
    receiveMessages observeQuery.ts:100
    next observeQuery.ts:22
    RxJS 8
    _handleSubscriptionData index.ts:67
    _handleIncomingSubscriptionMessage index.ts:427
    _registerWebsocketHandlers index.ts:676
    onmessage index.ts:641
    _initiateHandshake index.ts:631
    _initiateHandshake index.ts:617
    _establishConnection index.ts:35
    retry retry.ts:39
    retry retry.ts:16
    jitteredExponentialRetry jitteredExponentialRetry.ts:10
    _establishRetryableConnection index.ts:592
    _initializeWebSocketConnection index.ts:566
    _initializeWebSocketConnection index.ts:541
    _connectWebSocket index.ts:149
    _startSubscriptionWithAWSAppSyncRealTime index.ts:281
    startSubscription index.ts:106
    subscribe index.ts:127
    RxJS 14
    observeQuery observeQuery.ts:20
    RxJS 4
    SubscribedVendorList SubscribedVendorList.tsx:55
    React 8

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DataRelated to Amplify Data category https://docs.amplify.aws/javascript/build-a-backend/data/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions