Skip to content

fix(data-schema): skip null items in observeQuery - #796

Open
Tharaka-Chathuranga wants to merge 1 commit into
aws-amplify:mainfrom
Tharaka-Chathuranga:fix/observe-query-null-item
Open

Tharaka-Chathuranga wants to merge 1 commit into
aws-amplify:mainfrom
Tharaka-Chathuranga:fix/observe-query-null-item

Conversation

@Tharaka-Chathuranga

Copy link
Copy Markdown

Problem

observeQuery crashes with TypeError: Cannot read properties of null (reading 'id') when a subscription event arrives without an item.

AppSync sends { data: { onCreateTodo: null }, errors: [...] } when the mutation that fired the event didn't return every required field. This is common with observeQuery, because it subscribes with every field by default. It's also why passing a smaller selectionSet makes the error go away.

observeQuery passed that null item to findIndexByFields, which threw. The error happens inside the subscription's next handler, so the subscriber's error callback never runs and the app gets an uncaught exception.

Issue number, if available: Fixes #655

Changes

  • observeQuery.ts: skip subscription events that have no item. Everything else works the same.
  • Added an integration test in 2-expected-use/subscribe-to-real-time-events.ts. It sends empty create, update and delete events, then a normal create, and checks that:
    • nothing throws
    • the subscriber's error callback isn't called
    • the new item still shows up in the snapshot
  • Added a patch changeset for @aws-amplify/data-schema.

One thing I left alone: the errors on those empty events are still dropped, the same as before. Sending them to subscriber.error would close the whole observable, which felt like the wrong trade-off here. Happy to follow up if you'd like them surfaced another way.

Corresponding docs PR, if applicable: N/A

Validation

  • The new integration test fails on main with the same stack trace as the issue, and passes with the fix.
  • yarn check passes locally (build, test, lint, check:api, check:type-perf).

Checklist

  • If this PR includes a functional change to the runtime or type-level behavior of the code, I have added or updated automated test coverage for this change. (see Testing Strategy README)
  • If this PR requires a docs update, I have linked to that docs PR above.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Tharaka-Chathuranga
Tharaka-Chathuranga requested review from a team as code owners September 19, 2026 05:54
@changeset-bot

changeset-bot Bot commented Sep 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c113220

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/data-schema Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

observeQuery errors without including selectionSet

1 participant