Skip to content

Type useQuery data as partial when returnPartialData is true - #7

Open
johanrd wants to merge 1 commit into
mainfrom
partial-data-type
Open

johanrd wants to merge 1 commit into
mainfrom
partial-data-type

Conversation

@johanrd

@johanrd johanrd commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

With returnPartialData: true, data holds what the cache had until the network answers, so fields can be missing. Apollo Client 4 types this as DataValue.Partial<TData> (dataState: "partial"). useQuery typed it as complete, so code that reads a missing field compiles.

This adds an overload to both signature styles: with returnPartialData: true in the options, useQuery returns a PartialQueryResource whose data is DataValue.Partial<TData> | undefined. No runtime change.

The same approach in Apollo Client 4.2.10:

Type tests cover both signature styles; the existing tests and the test-app suite pass.

Cowritten by Claude

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The partial data type uses the unmasked DataValue.Partial<TData> instead of wrapping with MaybeMasked, which is inconsistent with the resource's complete-data typing and Apollo Client's own useQuery.Result.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR adds type-only support for returnPartialData: true to useQuery. When that option is set, Apollo Client's cache can return an incomplete result until the network responds, so the returned data should be typed as partial. Previously useQuery always typed data as complete, so reading a missing field would compile. The PR introduces a PartialQueryResource type and adds overloads to both the Classic and Modern signature styles that return it when returnPartialData: true is present. There is no runtime change.

Changes:

  • Added PartialQueryResource<TData, TVariables> in query.ts, overriding data to DataValue.Partial<TData> | undefined.
  • Added returnPartialData: true overloads to useQuery.Signatures.Classic and .Modern returning PartialQueryResource.
  • Exported PartialQueryResource from the package entrypoint and added type tests for both signature styles.
File Description
glimmer-apollo/​src/​-private/​query.ts Imports DataValue and defines the new PartialQueryResource type.
glimmer-apollo/​src/​-private/​usables.ts Adds returnPartialData: true overloads to the Classic and Modern signatures.
glimmer-apollo/​src/​index.ts Re-exports PartialQueryResource from the public API.
test-app/​tests/​unit/​types/​query-types-test.ts Adds type assertions covering partial data for both signature styles.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread glimmer-apollo/src/-private/query.ts Outdated
With returnPartialData, data can miss fields, so Apollo Client types it as
DataValue.Partial<TData>; useQuery typed it as complete.

QueryResource gets a third type parameter for the shape of data, and the
returnPartialData overloads (literal true or a boolean flag, as in
Apollo's own overloads) return it as DataValue.Partial<MaybeMasked<TData>>.
onComplete receives the same shape. A complete resource stays assignable
to a partial one.

Also drop the NoInfer import from @apollo/client/utilities/internal:
Apollo 4.3 removed it and TypeScript 5.4+ ships it. This is what failed
the floating dependencies CI job.
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.

2 participants