@apollo/client 4.2.7 → 4.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1262,13 +1262,49 @@ class ObservableQuery {
1262
1262
  });
1263
1263
  }
1264
1264
  operator = (0, internal_1.filterMap)((notification) => {
1265
- const { query, variables, meta } = notification;
1265
+ const { query, meta } = notification;
1266
1266
  if (notification.source === "setResult") {
1267
- return { query, variables, result: notification.value, meta };
1267
+ return {
1268
+ query,
1269
+ variables: this.variables,
1270
+ result: notification.value,
1271
+ meta,
1272
+ };
1268
1273
  }
1269
- if (notification.kind === "C" || !isEqualQuery(notification, this)) {
1274
+ if (notification.kind === "C") {
1275
+ return;
1276
+ }
1277
+ const resolvedVariables = "resolvedVariables" in notification ?
1278
+ notification.resolvedVariables
1279
+ : undefined;
1280
+ // Usually we prefer to drop notifications that don't match this query
1281
+ // but this breaks when used with `@export` queries that resolve variables
1282
+ // after the request is initiated. `notification.resolvedVariables` gives us
1283
+ // the variables the query actually resolved with during evaluation in
1284
+ // QueryManager (which is the variables value after `@export` variables have
1285
+ // been applied), but we need to update this query with those resolved
1286
+ // variables maybe in the middle of a request (updating is handled below).
1287
+ // When we update this.variables to the resolved variables, this causes
1288
+ // isEqualQuery(notification, this) to fail for future notifications since
1289
+ // the notification.variables holds the stale variables value. In this case,
1290
+ // we want to allow the notification through only if the current variables
1291
+ // value matches the resolved variables.
1292
+ //
1293
+ // Note: the check for matching resolved variables typically kicks in for
1294
+ // multi-emission fetches (such as defer, or cache-and-network, etc).
1295
+ if (notification.query !== this.query) {
1270
1296
  return;
1271
1297
  }
1298
+ if (!(0, equality_1.equal)(resolvedVariables, this.variables)) {
1299
+ if (!(0, equality_1.equal)(notification.variables, this.variables)) {
1300
+ return;
1301
+ }
1302
+ if (resolvedVariables) {
1303
+ this.options.variables = resolvedVariables;
1304
+ this.resubscribeCache();
1305
+ }
1306
+ }
1307
+ const variables = this.variables;
1272
1308
  let result;
1273
1309
  const previous = this.subject.getValue();
1274
1310
  if (notification.source === "cache") {
@@ -1289,7 +1325,9 @@ class ObservableQuery {
1289
1325
  result =
1290
1326
  notification.kind === "E" ?
1291
1327
  {
1292
- ...(isEqualQuery(previous, notification) ?
1328
+ ...((isEqualQuery(previous, notification) ||
1329
+ (resolvedVariables &&
1330
+ (0, equality_1.equal)(resolvedVariables, previous.variables))) ?
1293
1331
  previous.result
1294
1332
  : { data: undefined, dataState: "empty", partial: true }),
1295
1333
  error: notification.error,