Skip to content

Reduce duplicate custom scalars tests between core APIs and React hooks - #13368

Merged
jerelmiller merged 1 commit into
release-4.3from
jerel/refactor-custom-scalars-tests
Jul 29, 2026
Merged

Reduce duplicate custom scalars tests between core APIs and React hooks#13368
jerelmiller merged 1 commit into
release-4.3from
jerel/refactor-custom-scalars-tests

Conversation

@jerelmiller

@jerelmiller jerelmiller commented Jul 29, 2026

Copy link
Copy Markdown
Member

When I first started working on custom scalars, I added tests all over the place to ensure it works throughout the entirety of the library. The problem however is that I essentially duplicated the entire test suite across every React hook. Since all React hooks use client.watchQuery under the hood, client.watchQuery tests really should be the test suite that checks all the edge cases (fetch policies, defer/stream, etc.), otherwise future maintenance is going to be a nightmare if we have to duplicate new tests for every React hooks.

The React hook custom scalars test suites are now reduced to a more minimal set to ensure the integration works as expected, but the core APIs are now where the full suite lives. This will make it easier to add tests in the future without having to duplicate them everywhere.

Summary by CodeRabbit

  • Tests
    • Expanded coverage for custom scalar parsing, including Date values returned through deferred and incremental responses.
    • Updated query, mutation, subscription, suspense, and preloader scenarios to validate parsed scalar fields and variables.
    • Added checks that identical scalar results preserve stable data references and avoid unnecessary updates.
    • Refined error-policy and loading-state expectations for successful parsed results.

@apollo-librarian

apollo-librarian Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 068947bfeed68865c514b534
Build Logs: View logs


✅ 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.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 421541d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: 982cf861-073a-4d39-bb88-54f55cddbf3a

📥 Commits

Reviewing files that changed from the base of the PR and between 7aaa484 and 421541d.

📒 Files selected for processing (10)
  • src/core/__tests__/client.mutate/customScalars.test.ts
  • src/react/hooks/__tests__/useBackgroundQuery/customScalars.test.tsx
  • src/react/hooks/__tests__/useLazyQuery/customScalars.test.tsx
  • src/react/hooks/__tests__/useLoadableQuery/customScalars.test.tsx
  • src/react/hooks/__tests__/useMutation/customScalars.test.tsx
  • src/react/hooks/__tests__/useQuery/customScalars.test.tsx
  • src/react/hooks/__tests__/useQueryRefHandlers/customScalars.test.tsx
  • src/react/hooks/__tests__/useSubscription/customScalars.test.tsx
  • src/react/hooks/__tests__/useSuspenseQuery/customScalars.test.tsx
  • src/react/query-preloader/__tests__/createQueryPreloader/customScalars.test.tsx

📝 Walkthrough

Walkthrough

Custom scalar tests now emphasize parsed Date fields, referential identity across refetches and subscriptions, successful query-preloader states, and mutation parsing across two @defer payload formats. Older incremental, error-policy, optimistic, and updater scenarios were removed.

Changes

Custom scalar coverage

Layer / File(s) Summary
Deferred mutation scalar parsing
src/core/__tests__/client.mutate/customScalars.test.ts
Adds coverage for parsing Date values across deferred mutation chunks using both incremental handlers.
React hook scalar parsing and identity
src/react/hooks/__tests__/useBackgroundQuery/*, src/react/hooks/__tests__/useLoadableQuery/*, src/react/hooks/__tests__/useQuery/*, src/react/hooks/__tests__/useSubscription/*, src/react/hooks/__tests__/useSuspenseQuery/*, src/react/hooks/__tests__/useQueryRefHandlers/*
Refocuses hook tests on parsed scalar fields and referential identity, while removing older incremental and error-policy scenarios.
Lazy query and mutation expectations
src/react/hooks/__tests__/useLazyQuery/customScalars.test.tsx, src/react/hooks/__tests__/useMutation/customScalars.test.tsx
Updates parsed variable and field assertions, successful error-policy snapshots, and stable data checks; removes superseded mutation scenarios.
Query preloader scalar state
src/react/query-preloader/__tests__/createQueryPreloader/customScalars.test.tsx
Validates parsed scalar output, ready states, and unchanged data references after a network-only query.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: auto-cleanup

Suggested reviewers: phryneas, daleseo

Poem

I’m a bunny with Dates in my queue,
Deferred little chunks hop through too.
Hooks keep references tight,
Scalars parse just right—
And old test thickets bid adieu!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: consolidating duplicate custom scalar test coverage between core APIs and React hooks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/core/__tests__/client.mutate/customScalars.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/react/hooks/__tests__/useBackgroundQuery/customScalars.test.tsx

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

src/react/hooks/__tests__/useLazyQuery/customScalars.test.tsx

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 7 others

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 Jul 29, 2026

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

commit: 421541d

@jerelmiller
jerelmiller merged commit 48f7386 into release-4.3 Jul 29, 2026
51 checks passed
@jerelmiller
jerelmiller deleted the jerel/refactor-custom-scalars-tests branch July 29, 2026 15:31
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.

1 participant