@apollo/client 4.3.0-alpha.5 → 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 (52) hide show
  1. package/CHANGELOG.md +22 -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 +28 -6
  6. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  8. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  10. package/__cjs/core/ObservableQuery.cjs +175 -62
  11. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  12. package/__cjs/core/ObservableQuery.d.cts +4 -7
  13. package/__cjs/core/QueryInfo.cjs +13 -136
  14. package/__cjs/core/QueryInfo.cjs.map +1 -1
  15. package/__cjs/core/QueryInfo.d.cts +2 -26
  16. package/__cjs/core/QueryManager.cjs +26 -25
  17. package/__cjs/core/QueryManager.cjs.map +1 -1
  18. package/__cjs/core/RefetchEventManager.cjs +3 -3
  19. package/__cjs/invariantErrorCodes.cjs +57 -32
  20. package/__cjs/utilities/internal/index.cjs +3 -1
  21. package/__cjs/utilities/internal/index.cjs.map +1 -1
  22. package/__cjs/utilities/internal/index.d.cts +1 -0
  23. package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
  24. package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
  25. package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
  26. package/__cjs/version.cjs +1 -1
  27. package/cache/core/cache.js +1 -1
  28. package/cache/inmemory/entityStore.js +3 -3
  29. package/cache/inmemory/key-extractor.js +1 -1
  30. package/cache/inmemory/policies.js +28 -6
  31. package/cache/inmemory/policies.js.map +1 -1
  32. package/cache/inmemory/readFromStore.js +3 -3
  33. package/cache/inmemory/readFromStore.js.map +1 -1
  34. package/cache/inmemory/writeToStore.js +4 -4
  35. package/core/ObservableQuery.d.ts +4 -7
  36. package/core/ObservableQuery.js +172 -63
  37. package/core/ObservableQuery.js.map +1 -1
  38. package/core/QueryInfo.d.ts +3 -27
  39. package/core/QueryInfo.js +14 -137
  40. package/core/QueryInfo.js.map +1 -1
  41. package/core/QueryManager.js +26 -25
  42. package/core/QueryManager.js.map +1 -1
  43. package/core/RefetchEventManager.js +3 -3
  44. package/invariantErrorCodes.js +57 -32
  45. package/package.json +1 -1
  46. package/utilities/internal/index.d.ts +1 -0
  47. package/utilities/internal/index.js +1 -0
  48. package/utilities/internal/index.js.map +1 -1
  49. package/utilities/internal/toDiffWithDataState.d.ts +8 -0
  50. package/utilities/internal/toDiffWithDataState.js +17 -0
  51. package/utilities/internal/toDiffWithDataState.js.map +1 -0
  52. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
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
+
15
+ ## 4.3.0-alpha.6
16
+
17
+ ### Minor Changes
18
+
19
+ - [#13405](https://github.com/apollographql/apollo-client/pull/13405) [`f923ab4`](https://github.com/apollographql/apollo-client/commit/f923ab422e1bcd35c1bcd2939f58dc3723508b55) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Field policy `read` and `merge` functions are now ignored when the field policy configures the `scalar` option. If a `read` or `merge` function is provided alongside `scalar`, a development-only warning is emitted.
20
+
21
+ ### Patch Changes
22
+
23
+ - [#13408](https://github.com/apollographql/apollo-client/pull/13408) [`7a5164d`](https://github.com/apollographql/apollo-client/commit/7a5164d3ce21b7f88f625588ec72dbce8ea33810) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix `dataState` to report `"streaming"` instead of `"partial"` when `returnPartialData` is `true` and the cache result is missing only `@defer` fields.
24
+
3
25
  ## 4.3.0-alpha.5
4
26
 
5
27
  ### 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(120, 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)}`;
@@ -194,13 +194,32 @@ class Policies {
194
194
  }
195
195
  const incoming = fields[fieldName];
196
196
  if (typeof incoming === "function") {
197
- existing.read = incoming;
197
+ if (existing.scalar) {
198
+ if (environment_1.__DEV__) {
199
+ warnAboutScalarConfig(typename, fieldName, existing.scalar, "read");
200
+ }
201
+ }
202
+ else {
203
+ existing.read = incoming;
204
+ }
198
205
  }
199
206
  else {
200
- const { keyArgs, read, merge, scalar } = incoming;
207
+ let { keyArgs, read, merge, scalar } = incoming;
201
208
  if (scalar) {
202
209
  existing.scalar = scalar;
203
210
  }
211
+ if (existing.scalar) {
212
+ if (environment_1.__DEV__) {
213
+ if (read !== undefined || existing.read !== undefined) {
214
+ warnAboutScalarConfig(typename, fieldName, existing.scalar, "read");
215
+ }
216
+ if (merge !== undefined || existing.merge !== undefined) {
217
+ warnAboutScalarConfig(typename, fieldName, existing.scalar, "merge");
218
+ }
219
+ }
220
+ existing.read = read = undefined;
221
+ existing.merge = merge = undefined;
222
+ }
204
223
  existing.keyFn =
205
224
  // Pass false to disable argument-based differentiation of
206
225
  // field identities.
@@ -232,7 +251,7 @@ class Policies {
232
251
  const rootId = "ROOT_" + which.toUpperCase();
233
252
  const old = this.rootTypenamesById[rootId];
234
253
  if (typename !== old) {
235
- (0, invariant_1.invariant)(!old || old === which, 109, which);
254
+ (0, invariant_1.invariant)(!old || old === which, 110, which);
236
255
  // First, delete any old __typename associated with this rootId from
237
256
  // rootIdsByTypename.
238
257
  if (old)
@@ -375,7 +394,7 @@ class Policies {
375
394
  if (supertypeSet.has(supertype)) {
376
395
  if (!typenameSupertypeSet.has(supertype)) {
377
396
  if (checkingFuzzySubtypes) {
378
- __DEV__ && invariant_1.invariant.warn(110, typename, supertype);
397
+ __DEV__ && invariant_1.invariant.warn(111, typename, supertype);
379
398
  }
380
399
  // Record positive results for faster future lookup.
381
400
  // Unfortunately, we cannot safely cache negative results,
@@ -632,7 +651,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
632
651
  }
633
652
  }
634
653
  if (environment_1.__DEV__ && options.from === void 0) {
635
- __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)));
636
655
  }
637
656
  if (void 0 === options.variables) {
638
657
  options.variables = variables;
@@ -642,7 +661,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
642
661
  function makeMergeObjectsFunction(store) {
643
662
  return function mergeObjects(existing, incoming) {
644
663
  if ((0, internal_2.isArray)(existing) || (0, internal_2.isArray)(incoming)) {
645
- throw (0, invariant_1.newInvariantError)(112);
664
+ throw (0, invariant_1.newInvariantError)(113);
646
665
  }
647
666
  // These dynamic checks are necessary because the parameters of a
648
667
  // custom merge function can easily have the any type, so the type
@@ -678,4 +697,7 @@ function makeMergeObjectsFunction(store) {
678
697
  return incoming;
679
698
  };
680
699
  }
700
+ function warnAboutScalarConfig(typename, fieldName, scalar, kind) {
701
+ __DEV__ && invariant_1.invariant.warn(114, `${typename}.${fieldName}`, scalar, kind);
702
+ }
681
703
  //# sourceMappingURL=policies.cjs.map