@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.
@@ -1254,13 +1254,49 @@ export class ObservableQuery {
1254
1254
  });
1255
1255
  }
1256
1256
  operator = filterMap((notification) => {
1257
- const { query, variables, meta } = notification;
1257
+ const { query, meta } = notification;
1258
1258
  if (notification.source === "setResult") {
1259
- return { query, variables, result: notification.value, meta };
1259
+ return {
1260
+ query,
1261
+ variables: this.variables,
1262
+ result: notification.value,
1263
+ meta,
1264
+ };
1260
1265
  }
1261
- if (notification.kind === "C" || !isEqualQuery(notification, this)) {
1266
+ if (notification.kind === "C") {
1267
+ return;
1268
+ }
1269
+ const resolvedVariables = "resolvedVariables" in notification ?
1270
+ notification.resolvedVariables
1271
+ : undefined;
1272
+ // Usually we prefer to drop notifications that don't match this query
1273
+ // but this breaks when used with `@export` queries that resolve variables
1274
+ // after the request is initiated. `notification.resolvedVariables` gives us
1275
+ // the variables the query actually resolved with during evaluation in
1276
+ // QueryManager (which is the variables value after `@export` variables have
1277
+ // been applied), but we need to update this query with those resolved
1278
+ // variables maybe in the middle of a request (updating is handled below).
1279
+ // When we update this.variables to the resolved variables, this causes
1280
+ // isEqualQuery(notification, this) to fail for future notifications since
1281
+ // the notification.variables holds the stale variables value. In this case,
1282
+ // we want to allow the notification through only if the current variables
1283
+ // value matches the resolved variables.
1284
+ //
1285
+ // Note: the check for matching resolved variables typically kicks in for
1286
+ // multi-emission fetches (such as defer, or cache-and-network, etc).
1287
+ if (notification.query !== this.query) {
1262
1288
  return;
1263
1289
  }
1290
+ if (!equal(resolvedVariables, this.variables)) {
1291
+ if (!equal(notification.variables, this.variables)) {
1292
+ return;
1293
+ }
1294
+ if (resolvedVariables) {
1295
+ this.options.variables = resolvedVariables;
1296
+ this.resubscribeCache();
1297
+ }
1298
+ }
1299
+ const variables = this.variables;
1264
1300
  let result;
1265
1301
  const previous = this.subject.getValue();
1266
1302
  if (notification.source === "cache") {
@@ -1281,7 +1317,9 @@ export class ObservableQuery {
1281
1317
  result =
1282
1318
  notification.kind === "E" ?
1283
1319
  {
1284
- ...(isEqualQuery(previous, notification) ?
1320
+ ...((isEqualQuery(previous, notification) ||
1321
+ (resolvedVariables &&
1322
+ equal(resolvedVariables, previous.variables))) ?
1285
1323
  previous.result
1286
1324
  : { data: undefined, dataState: "empty", partial: true }),
1287
1325
  error: notification.error,