@apollo/client 4.3.0-alpha.6 → 4.3.0-alpha.7

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  4. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  5. package/__cjs/cache/inmemory/policies.cjs +5 -5
  6. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  7. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  8. package/__cjs/core/ObservableQuery.cjs +166 -54
  9. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  10. package/__cjs/core/ObservableQuery.d.cts +3 -6
  11. package/__cjs/core/QueryInfo.cjs +11 -125
  12. package/__cjs/core/QueryInfo.cjs.map +1 -1
  13. package/__cjs/core/QueryInfo.d.cts +0 -24
  14. package/__cjs/core/QueryManager.cjs +12 -14
  15. package/__cjs/core/QueryManager.cjs.map +1 -1
  16. package/__cjs/core/RefetchEventManager.cjs +3 -3
  17. package/__cjs/invariantErrorCodes.cjs +52 -32
  18. package/__cjs/version.cjs +1 -1
  19. package/cache/core/cache.js +1 -1
  20. package/cache/inmemory/entityStore.js +3 -3
  21. package/cache/inmemory/key-extractor.js +1 -1
  22. package/cache/inmemory/policies.js +5 -5
  23. package/cache/inmemory/readFromStore.js +3 -3
  24. package/cache/inmemory/writeToStore.js +4 -4
  25. package/core/ObservableQuery.d.ts +3 -6
  26. package/core/ObservableQuery.js +162 -54
  27. package/core/ObservableQuery.js.map +1 -1
  28. package/core/QueryInfo.d.ts +1 -25
  29. package/core/QueryInfo.js +11 -125
  30. package/core/QueryInfo.js.map +1 -1
  31. package/core/QueryManager.js +12 -14
  32. package/core/QueryManager.js.map +1 -1
  33. package/core/RefetchEventManager.js +3 -3
  34. package/invariantErrorCodes.js +52 -32
  35. package/package.json +1 -1
  36. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 4.3.0-alpha.7
4
+
5
+ ### Minor Changes
6
+
7
+ - [#13406](https://github.com/apollographql/apollo-client/pull/13406) [`bd74ccb`](https://github.com/apollographql/apollo-client/commit/bd74ccb2f75bc434afc4f5172311b551266f8196) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Emit a development-only warning when a feud is detected between queries that overwrite each other's data. This should make it easier to detect when you need to select a key field or add a `merge` function to a field policy.
8
+
9
+ - [#13406](https://github.com/apollographql/apollo-client/pull/13406) [`bd74ccb`](https://github.com/apollographql/apollo-client/commit/bd74ccb2f75bc434afc4f5172311b551266f8196) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fixes an issue where cache feuds between queries selecting incompatible non-normalized data could return untransformed network values.
10
+
11
+ Apollo Client now always writes network results to the cache before delivering them, ensuring custom scalars and field `read` functions are applied. To prevent repeated refetches when competing queries repeatedly make each other's cache results incomplete, Apollo Client stops automatically refetching a query after it sees the same incomplete result again.
12
+
13
+ This may add one network request in these cache-feud scenarios.
14
+
3
15
  ## 4.3.0-alpha.6
4
16
 
5
17
  ### Minor Changes
@@ -147,7 +147,7 @@ class ApolloCache {
147
147
  if (environment_1.__DEV__) {
148
148
  const actualFragmentName = fragmentName || (0, internal_1.getFragmentDefinition)(fragment).name.value;
149
149
  if (id === undefined) {
150
- __DEV__ && invariant_1.invariant.warn(121, actualFragmentName);
150
+ __DEV__ && invariant_1.invariant.warn(122, actualFragmentName);
151
151
  }
152
152
  }
153
153
  return id;
@@ -82,7 +82,7 @@ class EntityStore {
82
82
  // then there are no fields to be merged, so we're done.
83
83
  if (!incoming)
84
84
  return;
85
- (0, invariant_1.invariant)(typeof dataId === "string", 105);
85
+ (0, invariant_1.invariant)(typeof dataId === "string", 106);
86
86
  // Parse all scalars before merging so that the storeObjectReconciler can
87
87
  // deep compare the parsed value with the existing value
88
88
  incoming = this.coerceStoreObject(incoming, (scalar, value) => scalar.coerceToParsed(value), incoming.__typename ||
@@ -189,7 +189,7 @@ class EntityStore {
189
189
  if (environment_1.__DEV__) {
190
190
  const checkReference = (ref) => {
191
191
  if (this.lookup(ref.__ref) === undefined) {
192
- __DEV__ && invariant_1.invariant.warn(106, ref);
192
+ __DEV__ && invariant_1.invariant.warn(107, ref);
193
193
  return true;
194
194
  }
195
195
  };
@@ -218,7 +218,7 @@ class EntityStore {
218
218
  }
219
219
  }
220
220
  if (seenReference && someNonReference !== undefined) {
221
- __DEV__ && invariant_1.invariant.warn(107, someNonReference);
221
+ __DEV__ && invariant_1.invariant.warn(108, someNonReference);
222
222
  break;
223
223
  }
224
224
  }
@@ -41,7 +41,7 @@ function keyFieldsFnFromSpecifier(specifier) {
41
41
  // context.readField for this extraction.
42
42
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
43
43
  }
44
- (0, invariant_1.invariant)(extracted !== void 0, 108, schemaKeyPath.join("."), object);
44
+ (0, invariant_1.invariant)(extracted !== void 0, 109, schemaKeyPath.join("."), object);
45
45
  return extracted;
46
46
  }));
47
47
  return `${context.typename}:${JSON.stringify(keyObject)}`;
@@ -251,7 +251,7 @@ class Policies {
251
251
  const rootId = "ROOT_" + which.toUpperCase();
252
252
  const old = this.rootTypenamesById[rootId];
253
253
  if (typename !== old) {
254
- (0, invariant_1.invariant)(!old || old === which, 109, which);
254
+ (0, invariant_1.invariant)(!old || old === which, 110, which);
255
255
  // First, delete any old __typename associated with this rootId from
256
256
  // rootIdsByTypename.
257
257
  if (old)
@@ -394,7 +394,7 @@ class Policies {
394
394
  if (supertypeSet.has(supertype)) {
395
395
  if (!typenameSupertypeSet.has(supertype)) {
396
396
  if (checkingFuzzySubtypes) {
397
- __DEV__ && invariant_1.invariant.warn(110, typename, supertype);
397
+ __DEV__ && invariant_1.invariant.warn(111, typename, supertype);
398
398
  }
399
399
  // Record positive results for faster future lookup.
400
400
  // Unfortunately, we cannot safely cache negative results,
@@ -651,7 +651,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
651
651
  }
652
652
  }
653
653
  if (environment_1.__DEV__ && options.from === void 0) {
654
- __DEV__ && invariant_1.invariant.warn(111, (0, internal_2.stringifyForDisplay)(Array.from(readFieldArgs)));
654
+ __DEV__ && invariant_1.invariant.warn(112, (0, internal_2.stringifyForDisplay)(Array.from(readFieldArgs)));
655
655
  }
656
656
  if (void 0 === options.variables) {
657
657
  options.variables = variables;
@@ -661,7 +661,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
661
661
  function makeMergeObjectsFunction(store) {
662
662
  return function mergeObjects(existing, incoming) {
663
663
  if ((0, internal_2.isArray)(existing) || (0, internal_2.isArray)(incoming)) {
664
- throw (0, invariant_1.newInvariantError)(112);
664
+ throw (0, invariant_1.newInvariantError)(113);
665
665
  }
666
666
  // These dynamic checks are necessary because the parameters of a
667
667
  // custom merge function can easily have the any type, so the type
@@ -698,6 +698,6 @@ function makeMergeObjectsFunction(store) {
698
698
  };
699
699
  }
700
700
  function warnAboutScalarConfig(typename, fieldName, scalar, kind) {
701
- __DEV__ && invariant_1.invariant.warn(113, `${typename}.${fieldName}`, scalar, kind);
701
+ __DEV__ && invariant_1.invariant.warn(114, `${typename}.${fieldName}`, scalar, kind);
702
702
  }
703
703
  //# sourceMappingURL=policies.cjs.map
@@ -289,7 +289,7 @@ class StoreReader {
289
289
  if (typename) {
290
290
  const policy = policies["getFieldPolicy"](typename, fieldName);
291
291
  if (policy?.scalar) {
292
- __DEV__ && invariant_1.invariant.warn(114, `${typename}.${fieldName}`, policy.scalar);
292
+ __DEV__ && invariant_1.invariant.warn(115, `${typename}.${fieldName}`, policy.scalar);
293
293
  }
294
294
  }
295
295
  }
@@ -326,7 +326,7 @@ class StoreReader {
326
326
  else {
327
327
  const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
328
328
  if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
329
- throw (0, invariant_1.newInvariantError)(115, selection.name.value);
329
+ throw (0, invariant_1.newInvariantError)(116, selection.name.value);
330
330
  }
331
331
  if (fragment && policies.fragmentMatches(fragment, typename)) {
332
332
  const isDeferBoundary = (0, internal_1.isDeferredFragment)(selection, context.variables);
@@ -624,7 +624,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
624
624
  if ((0, internal_1.isNonNullObject)(value)) {
625
625
  (0, invariant_1.invariant)(
626
626
  !(0, utilities_1.isReference)(value),
627
- 116,
627
+ 117,
628
628
  (0, helpers_js_1.getTypenameFromStoreObject)(store, value),
629
629
  field.name.value
630
630
  );
@@ -75,7 +75,7 @@ class StoreWriter {
75
75
  path: [],
76
76
  });
77
77
  if (!(0, utilities_1.isReference)(ref)) {
78
- throw (0, invariant_1.newInvariantError)(117, result);
78
+ throw (0, invariant_1.newInvariantError)(118, result);
79
79
  }
80
80
  // So far, the store has not been modified, so now it's time to process
81
81
  // context.incomingById and merge those incoming fields into context.store.
@@ -237,7 +237,7 @@ class StoreWriter {
237
237
  // provide a default value, so its absence from the written data should
238
238
  // not be cause for alarm.
239
239
  !policies.getReadFunction(typename, field.name.value)) {
240
- invariant_1.invariant.error(118, (0, internal_1.resultKeyNameFromField)(field), result);
240
+ invariant_1.invariant.error(119, (0, internal_1.resultKeyNameFromField)(field), result);
241
241
  }
242
242
  });
243
243
  // Identify the result object, even if dataId was already provided,
@@ -385,7 +385,7 @@ class StoreWriter {
385
385
  else {
386
386
  const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
387
387
  if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
388
- throw (0, invariant_1.newInvariantError)(119, selection.name.value);
388
+ throw (0, invariant_1.newInvariantError)(120, selection.name.value);
389
389
  }
390
390
  if (fragment &&
391
391
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
@@ -558,7 +558,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
558
558
  }
559
559
  });
560
560
  }
561
- __DEV__ && invariant_1.invariant.warn(120, fieldName, parentType, childTypenames.length ?
561
+ __DEV__ && invariant_1.invariant.warn(121, fieldName, parentType, childTypenames.length ?
562
562
  "either ensure all objects of type " +
563
563
  childTypenames.join(" and ") +
564
564
  " have an ID or a custom merge function, or "
@@ -29,16 +29,29 @@ const empty = {
29
29
  dataState: "empty",
30
30
  partial: true,
31
31
  };
32
+ const destructiveMethodCounts = new WeakMap();
33
+ function wrapDestructiveCacheMethod(cache, methodName) {
34
+ const original = cache[methodName];
35
+ if (typeof original === "function") {
36
+ // @ts-expect-error this is just too generic to be typed correctly
37
+ cache[methodName] = function () {
38
+ destructiveMethodCounts.set(cache,
39
+ // The %1e15 allows the count to wrap around to 0 safely every
40
+ // quadrillion evictions, so there's no risk of overflow. To be
41
+ // clear, this is more of a pedantic principle than something
42
+ // that matters in any conceivable practical scenario.
43
+ (destructiveMethodCounts.get(cache) + 1) % 1e15);
44
+ // @ts-expect-error this is just too generic to be typed correctly
45
+ return original.apply(this, arguments);
46
+ };
47
+ }
48
+ }
32
49
  class ObservableQuery {
33
50
  options;
34
51
  queryName;
35
52
  variablesUnknown = false;
36
- /**
37
- * @internal will be read and written from `QueryInfo`
38
- *
39
- * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
40
- */
41
- _lastWrite;
53
+ didWarnOnFeud = false;
54
+ lastMissing;
42
55
  // The `query` computed property will always reflect the document transformed
43
56
  // by the last run query. `this.options.query` will always reflect the raw
44
57
  // untransformed query to ensure document transforms with runtime conditionals
@@ -75,6 +88,18 @@ class ObservableQuery {
75
88
  }
76
89
  constructor({ queryManager, options, transformedQuery = queryManager.transform(options.query), }) {
77
90
  this.queryManager = queryManager;
91
+ // Track how often destructive cache methods are called, since we want
92
+ // eviction to override the feud-stopping logic in `shouldAutoRefetch`,
93
+ // by causing it to return true. Wrapping these cache methods is a bit of a
94
+ // hack, but it saves us from having to make eviction counting an official
95
+ // part of the ApolloCache API.
96
+ const { cache } = queryManager;
97
+ if (!destructiveMethodCounts.has(cache)) {
98
+ destructiveMethodCounts.set(cache, 0);
99
+ wrapDestructiveCacheMethod(cache, "evict");
100
+ wrapDestructiveCacheMethod(cache, "modify");
101
+ wrapDestructiveCacheMethod(cache, "reset");
102
+ }
78
103
  // active state
79
104
  this.waitForNetworkResult = options.fetchPolicy === "network-only";
80
105
  this.isTornDown = false;
@@ -402,7 +427,6 @@ class ObservableQuery {
402
427
  reobserveOptions.variables = this.options.variables =
403
428
  this.getVariablesWithDefaults({ ...this.variables, ...variables });
404
429
  }
405
- this._lastWrite = undefined;
406
430
  return this._reobserve(reobserveOptions, {
407
431
  newNetworkStatus: networkStatus_js_1.NetworkStatus.refetch,
408
432
  });
@@ -890,7 +914,6 @@ class ObservableQuery {
890
914
  if (this.pollingInfo) {
891
915
  if (!(0, utilities_1.isNetworkRequestInFlight)(this.networkStatus) &&
892
916
  !this.options.skipPollAttempt?.()) {
893
- this._lastWrite = undefined;
894
917
  this._reobserve({
895
918
  // Most fetchPolicy options don't make sense to use in a polling context, as
896
919
  // users wouldn't want to be polling the cache directly. However, network-only and
@@ -936,7 +959,10 @@ class ObservableQuery {
936
959
  }
937
960
  _reobserve(newOptions, internalOptions) {
938
961
  this.isTornDown = false;
939
- let { newNetworkStatus } = internalOptions || {};
962
+ let { newNetworkStatus, keepLastMissing } = internalOptions || {};
963
+ if (!keepLastMissing) {
964
+ this.lastMissing = undefined;
965
+ }
940
966
  this.queryManager.obsQueries.add(this);
941
967
  const useDisposableObservable =
942
968
  // Refetching uses a disposable Observable to allow refetches using different
@@ -1077,7 +1103,7 @@ class ObservableQuery {
1077
1103
  this.queryManager.obsQueries.delete(this);
1078
1104
  this.isTornDown = true;
1079
1105
  this.abortActiveOperations();
1080
- this._lastWrite = undefined;
1106
+ this.lastMissing = undefined;
1081
1107
  }
1082
1108
  transformDocument(document) {
1083
1109
  return this.queryManager.transform(document);
@@ -1135,51 +1161,126 @@ class ObservableQuery {
1135
1161
  return;
1136
1162
  }
1137
1163
  }
1138
- const { dirty } = this;
1164
+ const { dirty, lastMissing } = this;
1165
+ const { fetchPolicy } = this.options;
1139
1166
  this.resetNotifications();
1140
- if (dirty &&
1141
- (this.options.fetchPolicy === "cache-only" ||
1142
- this.options.fetchPolicy === "cache-and-network" ||
1143
- !this.activeOperations.size)) {
1144
- const diff = this.getCacheDiff();
1145
- if (
1146
- // `fromOptimisticTransaction` is not available through the `cache.diff`
1147
- // code path, so we need to check it this way
1148
- (0, equality_1.equal)(diff.result, this.getCacheDiff({ optimistic: false }).result)) {
1149
- //If this diff did not come from an optimistic transaction
1150
- // make the ObservableQuery "reobserve" the latest data
1151
- // using a temporary fetch policy of "cache-first", so complete cache
1152
- // results have a chance to be delivered without triggering additional
1153
- // network requests, even when options.fetchPolicy is "network-only"
1154
- // or "cache-and-network". All other fetch policies are preserved by
1155
- // this method, and are handled by calling oq.reobserve(). If this
1156
- // reobservation is spurious, distinctUntilChanged still has a
1157
- // chance to catch it before delivery to ObservableQuery subscribers.
1158
- this.reobserveCacheFirst();
1167
+ if (!dirty ||
1168
+ (fetchPolicy !== "cache-only" &&
1169
+ fetchPolicy !== "cache-and-network" &&
1170
+ this.activeOperations.size)) {
1171
+ return;
1172
+ }
1173
+ const diff = this.getCacheDiff();
1174
+ const current = this.getCurrentResult();
1175
+ // `fromOptimisticTransaction` is not available through the `cache.diff`
1176
+ // code path, so we need to check whether the cache result is an optimistic
1177
+ // result this way.
1178
+ const isOptimistic = !(0, equality_1.equal)(diff.result, this.getCacheDiff({ optimistic: false }).result);
1179
+ if (
1180
+ // When this diff came from an optimistic transaction, deliver the
1181
+ // current cache data to the ObservableQuery, but don't perform a
1182
+ // reobservation, since oq.reobserveCacheFirst might make a network
1183
+ // request, and we never want to trigger network requests in the
1184
+ // middle of optimistic updates.
1185
+ isOptimistic ||
1186
+ // If we get a cache update in the middle of streaming (possible with
1187
+ // cache-and-network fetch policy), just deliver the cache value without
1188
+ // going through the full reobserve which would otherwise trigger another
1189
+ // request (deduplication should kick in, but doing so replays any
1190
+ // previous emits from the link chain, which get rewritten into the cache
1191
+ // and might clobber this cache update)
1192
+ (!diff.complete && current.networkStatus === networkStatus_js_1.NetworkStatus.streaming)) {
1193
+ this.deliverCacheDiff(diff);
1194
+ return;
1195
+ }
1196
+ if (diff.complete) {
1197
+ this.lastMissing = undefined;
1198
+ }
1199
+ else if (!lastMissing ||
1200
+ // If a destructive cache method has been called since the last recorded
1201
+ // incomplete result, there's a chance fetching this data again will
1202
+ // restore what was evicted, even though the cache result looks the same
1203
+ // as before.
1204
+ lastMissing.dmCount !== destructiveMethodCounts.get(this.cache) ||
1205
+ !(0, equality_1.equal)(lastMissing.variables, this.variables) ||
1206
+ !(0, equality_1.equal)(lastMissing.missing, diff.missing?.missing)) {
1207
+ this.didWarnOnFeud = false;
1208
+ this.lastMissing = {
1209
+ variables: this.variables,
1210
+ missing: diff.missing?.missing,
1211
+ dmCount: destructiveMethodCounts.get(this.cache),
1212
+ };
1213
+ }
1214
+ else if (
1215
+ // reobserveCacheFirst with cache-only fetch policy only calls
1216
+ // reobserve which never fetches from the network so we are ok
1217
+ // allowing cache-only queries to fallthrough to reobserveCacheFirst.
1218
+ // This also prevents the feud warning which would be confusing for a
1219
+ // cache-only query anyways.
1220
+ fetchPolicy !== "cache-only") {
1221
+ // If we've fallen through to this case, a cache emit has returned the
1222
+ // same missing fields which means at least one value on the fields we've
1223
+ // already delivered have changed. We are ok delivering the updated
1224
+ // partial result in this case to keep the result as fresh as possible. We
1225
+ // NEVER want to downgrade this query from a complete query to a partial
1226
+ // query though, so we also make sure we only deliver if the previous
1227
+ // result was also partial.
1228
+ if (current.dataState === "partial") {
1229
+ this.deliverCacheDiff(diff);
1159
1230
  }
1160
- else {
1161
- // If this diff came from an optimistic transaction, deliver the
1162
- // current cache data to the ObservableQuery, but don't perform a
1163
- // reobservation, since oq.reobserveCacheFirst might make a network
1164
- // request, and we never want to trigger network requests in the
1165
- // middle of optimistic updates.
1166
- this.input.next({
1167
- kind: "N",
1168
- value: {
1169
- data: diff.result,
1170
- dataState: diff.dataState,
1171
- networkStatus: networkStatus_js_1.NetworkStatus.ready,
1172
- loading: false,
1173
- error: undefined,
1174
- partial: !diff.complete,
1175
- },
1176
- source: "cache",
1177
- query: this.query,
1178
- variables: this.variables,
1179
- meta: {},
1180
- });
1231
+ // If the (partial) result is the same as the last partial result
1232
+ // we recorded from a previous broadcast (and the variables match
1233
+ // too), avoid calling reobserveCacheFirst to refetch this query
1234
+ // again. If we allow refetching anytime this result becomes partial,
1235
+ // we risk feuds between queries competing to update the same data in
1236
+ // incompatible ways, which can lead to an endless cycle of cache
1237
+ // broadcasts and useless network requests. As with any
1238
+ // feud, eventually one side must step back from the brink,
1239
+ // letting the other side(s) have the last word(s). There may
1240
+ // be other points where we could break this cycle, such as
1241
+ // silencing the broadcast for cache.writeQuery (not a good
1242
+ // idea, since it just delays the feud a bit) or somehow
1243
+ // avoiding the network request that just happened (also bad,
1244
+ // because the server could return useful new data). All
1245
+ // options considered, returning early and stopping the
1246
+ // reobserveCacheFirst cycle seems to be the least damaging place to
1247
+ // break the cycle because it allows read functions/custom scalars to
1248
+ // be applied to the feuding query while avoiding the endless cycle of
1249
+ // requests.
1250
+ if (environment_1.__DEV__ && !this.didWarnOnFeud) {
1251
+ this.didWarnOnFeud = true;
1252
+ warnOnFeud(this.query, diff);
1181
1253
  }
1254
+ return;
1182
1255
  }
1256
+ //If this diff did not come from an optimistic transaction
1257
+ // make the ObservableQuery "reobserve" the latest data
1258
+ // using a temporary fetch policy of "cache-first", so complete cache
1259
+ // results have a chance to be delivered without triggering additional
1260
+ // network requests, even when options.fetchPolicy is "network-only"
1261
+ // or "cache-and-network". All other fetch policies are preserved by
1262
+ // this method, and are handled by calling oq.reobserve(). If this
1263
+ // reobservation is spurious, distinctUntilChanged still has a
1264
+ // chance to catch it before delivery to ObservableQuery subscribers.
1265
+ this.reobserveCacheFirst();
1266
+ }
1267
+ deliverCacheDiff(diff) {
1268
+ const current = this.getCurrentResult();
1269
+ this.input.next({
1270
+ kind: "N",
1271
+ value: {
1272
+ data: diff.result,
1273
+ dataState: diff.dataState,
1274
+ networkStatus: current.networkStatus,
1275
+ loading: current.loading,
1276
+ error: undefined,
1277
+ partial: !diff.complete,
1278
+ },
1279
+ source: "cache",
1280
+ query: this.query,
1281
+ variables: this.variables,
1282
+ meta: {},
1283
+ });
1183
1284
  }
1184
1285
  activeOperations = new Set();
1185
1286
  pushOperation(networkStatus) {
@@ -1242,6 +1343,7 @@ class ObservableQuery {
1242
1343
  // exception for cache-only queries - we reset them into a "ready" state
1243
1344
  // as we won't trigger a refetch for them
1244
1345
  const resetToEmpty = this.options.fetchPolicy === "cache-only";
1346
+ this.lastMissing = undefined;
1245
1347
  this.setResult(resetToEmpty ? empty : uninitialized, {
1246
1348
  shouldEmit: resetToEmpty ? 1 /* EmitBehavior.force */ : 2 /* EmitBehavior.never */,
1247
1349
  });
@@ -1386,7 +1488,10 @@ class ObservableQuery {
1386
1488
  reobserveCacheFirst() {
1387
1489
  const { fetchPolicy, nextFetchPolicy } = this.options;
1388
1490
  if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
1389
- this.reobserve({
1491
+ // Preserve this.lastMissing so a cache update that triggers this
1492
+ // reobserve doesn't reset feud detection. All user-initiated calls to
1493
+ // reobserve (refetch/poll/reobserve, etc) should clear it.
1494
+ this._reobserve({
1390
1495
  fetchPolicy: "cache-first",
1391
1496
  // Use a temporary nextFetchPolicy function that replaces itself with the
1392
1497
  // previous nextFetchPolicy value and returns the original fetchPolicy.
@@ -1402,10 +1507,10 @@ class ObservableQuery {
1402
1507
  // Otherwise go back to the original this.options.fetchPolicy.
1403
1508
  return fetchPolicy;
1404
1509
  },
1405
- });
1510
+ }, { keepLastMissing: true });
1406
1511
  }
1407
1512
  else {
1408
- this.reobserve();
1513
+ this._reobserve(undefined, { keepLastMissing: true });
1409
1514
  }
1410
1515
  }
1411
1516
  getVariablesWithDefaults(variables) {
@@ -1458,4 +1563,11 @@ function getTrackingOperatorPromise(defaultValue) {
1458
1563
  });
1459
1564
  return { promise, operator };
1460
1565
  }
1566
+ function warnOnFeud(query, diff) {
1567
+ __DEV__ && invariant_1.invariant.warn(
1568
+ 89,
1569
+ (0, internal_1.getOperationName)(query, "(anonymous)"),
1570
+ diff.missing?.missing
1571
+ );
1572
+ }
1461
1573
  //# sourceMappingURL=ObservableQuery.cjs.map