Skip to content

Fix client.readFragment/client.readQuery when passing optimistic: true in options#13281

Merged
jerelmiller merged 6 commits into
mainfrom
jerel/fix-optimistic-read
Jun 30, 2026
Merged

Fix client.readFragment/client.readQuery when passing optimistic: true in options#13281
jerelmiller merged 6 commits into
mainfrom
jerel/fix-optimistic-read

Conversation

@jerelmiller

@jerelmiller jerelmiller commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes #13276

Summary by CodeRabbit

  • Bug Fixes

    • readQuery and readFragment now correctly respect the optimistic option provided in the options object, rather than defaulting to false.
  • Tests

    • Added test coverage for optimistic read operations.

@jerelmiller jerelmiller requested a review from phryneas June 17, 2026 02:37
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c03a2b7

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

This PR includes changesets to release 1 package
Name Type
@apollo/client 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

@apollo-librarian

apollo-librarian Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/react/(latest)/development-testing/testing.mdx

Build ID: 32d8a67dd842969441b0f51d
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/32d8a67dd842969441b0f51d


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: dc0b7235-9d4f-4b1f-96ae-4884fd675764

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

ApolloClient.readQuery and ApolloClient.readFragment each change the default value of their deprecated second optimistic parameter from false to !!options.optimistic. Two tests verify the fix using cache.recordOptimisticTransaction. A patch changeset entry is added.

Changes

Optimistic option fix for readQuery and readFragment

Layer / File(s) Summary
readQuery and readFragment optimistic default fix
src/core/ApolloClient.ts, src/__tests__/ApolloClient.ts, .changeset/gold-crabs-invent.md
Default of deprecated optimistic parameter changed from false to !!options.optimistic in both readQuery and readFragment. Two new tests seed optimistic cache state via recordOptimisticTransaction and assert each method returns optimistic data when optimistic: true is in the options object. Changeset records a patch bump.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

Poem

🐇 A hop, a skip, a tiny patch so neat,
optimistic: true now works — what a treat!
No more ignored flags hiding in the code,
The cache reads truthfully down the optimistic road.
thump thump — the rabbit stamps with glee! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR objectives and commit messages focus on fixing optimistic option handling, but the linked issue #13280 addresses test coverage for cache writes after errors with errorPolicy, creating a significant mismatch. Verify the correct linked issue is referenced. The PR changes do not align with the stated objective of adding error handling tests for errorPolicy: 'all'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing client.readFragment and client.readQuery to respect the optimistic option in options.
Out of Scope Changes check ✅ Passed The changeset entry and code changes are focused solely on fixing optimistic option handling in readFragment/readQuery methods, with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@apollo/client@13281

commit: c03a2b7

@jerelmiller jerelmiller enabled auto-merge (squash) June 17, 2026 04:48
@jerelmiller jerelmiller disabled auto-merge June 17, 2026 04:48
@phryneas

Copy link
Copy Markdown
Member

Looks like this partially overlaps with #13278 - we should probably see that we coordinate this, but get the user contribution in, too.

@jerelmiller

Copy link
Copy Markdown
Member Author

@phryneas somehow I missed that PR open. Thanks! We'll have to wait for the CLA to be signed so lets see what happens with that.

@jerelmiller jerelmiller merged commit e4df809 into main Jun 30, 2026
46 of 47 checks passed
@jerelmiller jerelmiller deleted the jerel/fix-optimistic-read branch June 30, 2026 18:00
This was referenced Jun 30, 2026
jerelmiller pushed a commit that referenced this pull request Jun 30, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @apollo/client@4.2.4

### Patch Changes

- [#13281](#13281)
[`e4df809`](e4df809)
Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fixes an issue
where `client.readFragment` and `client.readQuery` ignored the
`optimistic` option when passed in the options object.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

client.readFragment incorrectly handles optimistic option

2 participants