Skip to content

Conversation

@phryneas
Copy link
Member

This change adds a new option to client.watchQuery, variablesUnknown, which may be set true for queries starting with a fetchPolicy of standby. It will only be applied when creating the ObervableQuery instance and cannot be changed later. This flag indicates that the query's variables are not yet known, and thus it should be excluded from refetch operations until they are.

Fixes #12996, an issue where queries starting with skipToken were included in client.refetchQueries() before they had been executed for the first time. While generally queries with a standby fetchPolicy should be included in refetch, these queries never had variables passed in, so they should be excluded until they have run once and received their actual variables.

These queries are now properly excluded from refetch operations until after their initial execution.

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: b656fe0

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

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

@phryneas phryneas requested a review from jerelmiller December 12, 2025 11:19
*
* Changing this option after the query has been created will have no effect.
*/
variablesUnknown?: boolean;
Copy link
Member Author

Choose a reason for hiding this comment

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

I debated with myself if we should hide this option behind a symbol, but in the end it might be useful for other framework integrations, too, so I decided to keep it here.

@apollo-librarian
Copy link

apollo-librarian bot commented Dec 12, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 07fb064be4003792167cd526
Build Logs: View logs

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 12, 2025

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@13049

commit: b656fe0

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new variablesUnknown option to client.watchQuery to prevent queries with unknown variables (starting with skipToken or lazy queries) from being included in refetch operations before their first execution. This fixes issue #12996 where such queries were incorrectly refetched despite having no meaningful variables set.

Key changes:

  • Added variablesUnknown boolean option to WatchQueryOptions that can only be used with fetchPolicy: "standby"
  • Modified QueryManager.refetchQueries to skip queries with variablesUnknown: true
  • The flag automatically resets to false when the query leaves standby mode
  • Applied the option in React hooks (useQuery, useSuspenseQuery, useLazyQuery, useBackgroundQuery) when using skipToken or lazy execution

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/core/ApolloClient.ts Added variablesUnknown type definition to WatchQueryOptions with documentation
src/core/ObservableQuery.ts Added variablesUnknown property and logic to reset it when leaving standby mode
src/core/QueryManager.ts Modified refetch logic to exclude queries with variablesUnknown: true
src/react/hooks/useSuspenseQuery.ts Set variablesUnknown: true when using skipToken
src/react/hooks/useQuery.ts Set variablesUnknown: true when using skipToken
src/react/hooks/useLazyQuery.ts Set variablesUnknown: true for lazy queries
.changeset/quiet-dragons-sleep.md Added changeset documentation (contains typo)
.api-reports/*.api.md Updated API reports with new option
Test files Added comprehensive test coverage for all affected hooks and core functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*
* Changing this option after the query has been created will have no effect.
*/
variablesUnknown?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Discussed in person and decided to move this to a symbol property.

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.

refetchQueries refetches queries with skipToken when provided by name

3 participants