-
Notifications
You must be signed in to change notification settings - Fork 2.7k
add variablesUnknown option to watchQuery, avoid refetching queries that start off with a skipToken
#13049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…es that start off with a `skipToken`
🦋 Changeset detectedLatest 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 |
| * | ||
| * Changing this option after the query has been created will have no effect. | ||
| */ | ||
| variablesUnknown?: boolean; |
There was a problem hiding this comment.
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.
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: 07fb064be4003792167cd526 |
commit: |
There was a problem hiding this 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
variablesUnknownboolean option toWatchQueryOptionsthat can only be used withfetchPolicy: "standby" - Modified
QueryManager.refetchQueriesto skip queries withvariablesUnknown: true - The flag automatically resets to
falsewhen the query leaves standby mode - Applied the option in React hooks (
useQuery,useSuspenseQuery,useLazyQuery,useBackgroundQuery) when usingskipTokenor 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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
| * | ||
| * Changing this option after the query has been created will have no effect. | ||
| */ | ||
| variablesUnknown?: boolean; |
There was a problem hiding this comment.
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.
This change adds a new option to
client.watchQuery,variablesUnknown, which may be settruefor queries starting with afetchPolicyofstandby. It will only be applied when creating theObervableQueryinstance 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
skipTokenwere included inclient.refetchQueries()before they had been executed for the first time. While generally queries with astandbyfetchPolicyshould be included in refetch, these queries never hadvariablespassed 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.