Skip to content

Commit 2b39cc8

Browse files
authored
Fix issue where changes to @export fields did not trigger updates (#13367)
Fixes #13335 We had a regression in 4.x with regards to `@export` fields where queries would sometimes not respond to cache updates. This happened when a field changed an object that depended on the variables keyed by the `@export` values. ```gql query ($userId: ID!) { userId @client @export(as: "userId") user(id: $userId) { id name } } ``` In this case, `ObservableQuery` subscribed to the cache using the initial empty variables value, but never resubscribed after export variables were known. This meant changes to data inside that `user` object never notified the query of the change. This fix now emits a `resolvedVariables` value along with the notification to `ObservableQuery` so that `ObservableQuery` can update its `variables` and resubscribe to the cache using the export variables. I added a whole bunch of other tests to catch other potential edge cases to make sure we didn't miss this for other situations. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed reactivity issues affecting queries that use `@export` variables. * Cache updates now correctly trigger refreshed results when exported-variable fields change or are evicted. * Improved behavior for refetching, partial data, cache-and-network requests, and network-only requests. * Improved handling of streamed responses and variable changes during in-flight requests. * **Tests** * Added coverage for cache, network, refetch, partial-result, and streaming scenarios involving `@export` variables. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: jerelmiller <565661+jerelmiller@users.noreply.github.com>
1 parent 2f383e7 commit 2b39cc8

9 files changed

Lines changed: 1291 additions & 9 deletions

File tree

.api-reports/api-report-core.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,12 @@ interface QueryManagerOptions {
11161116
namespace QueryNotification {
11171117
// (undocumented)
11181118
type FromCache<TData> = NextNotification<ObservableQuery.Result<TData>> & {
1119+
resolvedVariables?: OperationVariables;
11191120
source: "cache";
11201121
};
11211122
// (undocumented)
11221123
type FromNetwork<TData> = ObservableNotification<ObservableQuery.Result<TData>> & {
1124+
resolvedVariables?: OperationVariables;
11231125
source: "network";
11241126
};
11251127
// (undocumented)

.api-reports/api-report.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,10 +2530,12 @@ interface QueryManagerOptions {
25302530
namespace QueryNotification {
25312531
// (undocumented)
25322532
type FromCache<TData> = NextNotification<ObservableQuery.Result<TData>> & {
2533+
resolvedVariables?: OperationVariables;
25332534
source: "cache";
25342535
};
25352536
// (undocumented)
25362537
type FromNetwork<TData> = ObservableNotification<ObservableQuery.Result<TData>> & {
2538+
resolvedVariables?: OperationVariables;
25372539
source: "network";
25382540
};
25392541
// (undocumented)

.changeset/stale-moles-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Fix an issue where some `@export` queries would not react to cache updates when the fields keyed by exported variables were updated.

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 47972,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 42227,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 35919,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 29427
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 48044,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 42315,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 35982,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 29489
66
}

0 commit comments

Comments
 (0)