@apollo/client 3.9.0-alpha.1 → 3.9.0-alpha.3

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 (180) hide show
  1. package/apollo-client.cjs +221 -180
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +52 -40
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +52 -40
  7. package/cache/core/types/common.d.ts +2 -2
  8. package/cache/core/types/common.d.ts.map +1 -1
  9. package/cache/core/types/common.js.map +1 -1
  10. package/cache/index.d.ts +1 -2
  11. package/cache/index.d.ts.map +1 -1
  12. package/cache/index.js +1 -2
  13. package/cache/index.js.map +1 -1
  14. package/cache/inmemory/entityStore.d.ts.map +1 -1
  15. package/cache/inmemory/entityStore.js +35 -0
  16. package/cache/inmemory/entityStore.js.map +1 -1
  17. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  18. package/cache/inmemory/inMemoryCache.js +1 -2
  19. package/cache/inmemory/inMemoryCache.js.map +1 -1
  20. package/cache/inmemory/key-extractor.js +1 -1
  21. package/cache/inmemory/object-canon.d.ts +0 -5
  22. package/cache/inmemory/object-canon.d.ts.map +1 -1
  23. package/cache/inmemory/object-canon.js +0 -22
  24. package/cache/inmemory/object-canon.js.map +1 -1
  25. package/cache/inmemory/policies.d.ts.map +1 -1
  26. package/cache/inmemory/policies.js +4 -6
  27. package/cache/inmemory/policies.js.map +1 -1
  28. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  29. package/cache/inmemory/readFromStore.js +4 -4
  30. package/cache/inmemory/readFromStore.js.map +1 -1
  31. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  32. package/cache/inmemory/writeToStore.js +5 -6
  33. package/cache/inmemory/writeToStore.js.map +1 -1
  34. package/core/ApolloClient.d.ts +2 -0
  35. package/core/ApolloClient.d.ts.map +1 -1
  36. package/core/ApolloClient.js +12 -4
  37. package/core/ApolloClient.js.map +1 -1
  38. package/core/LocalState.js +2 -2
  39. package/core/ObservableQuery.d.ts.map +1 -1
  40. package/core/ObservableQuery.js +10 -11
  41. package/core/ObservableQuery.js.map +1 -1
  42. package/core/QueryInfo.d.ts +0 -2
  43. package/core/QueryInfo.d.ts.map +1 -1
  44. package/core/QueryInfo.js +0 -2
  45. package/core/QueryInfo.js.map +1 -1
  46. package/core/QueryManager.d.ts +4 -2
  47. package/core/QueryManager.d.ts.map +1 -1
  48. package/core/QueryManager.js +15 -14
  49. package/core/QueryManager.js.map +1 -1
  50. package/core/core.cjs +39 -33
  51. package/core/core.cjs.map +1 -1
  52. package/core/core.cjs.native.js +39 -33
  53. package/dev/dev.cjs +125 -101
  54. package/dev/dev.cjs.map +1 -1
  55. package/dev/dev.cjs.native.js +125 -101
  56. package/dev/loadErrorMessageHandler.js +2 -2
  57. package/dev/loadErrorMessageHandler.js.map +1 -1
  58. package/invariantErrorCodes.js +96 -81
  59. package/link/core/ApolloLink.js +2 -2
  60. package/link/core/core.cjs +2 -2
  61. package/link/core/core.cjs.map +1 -1
  62. package/link/core/core.cjs.native.js +2 -2
  63. package/link/http/checkFetcher.js +1 -1
  64. package/link/http/createHttpLink.js +1 -1
  65. package/link/http/http.cjs +3 -3
  66. package/link/http/http.cjs.map +1 -1
  67. package/link/http/http.cjs.native.js +3 -3
  68. package/link/http/serializeFetchParameter.js +1 -1
  69. package/link/persisted-queries/index.js +2 -2
  70. package/link/persisted-queries/persisted-queries.cjs +2 -2
  71. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  72. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  73. package/link/utils/toPromise.js +1 -1
  74. package/link/utils/utils.cjs +2 -2
  75. package/link/utils/utils.cjs.map +1 -1
  76. package/link/utils/utils.cjs.native.js +2 -2
  77. package/link/utils/validateOperation.js +1 -1
  78. package/package.json +27 -26
  79. package/react/cache/QueryReference.d.ts.map +1 -1
  80. package/react/cache/QueryReference.js +7 -2
  81. package/react/cache/QueryReference.js.map +1 -1
  82. package/react/context/ApolloConsumer.js +1 -1
  83. package/react/context/ApolloContext.js +1 -1
  84. package/react/context/ApolloProvider.js +1 -1
  85. package/react/context/context.cjs +3 -3
  86. package/react/context/context.cjs.map +1 -1
  87. package/react/context/context.cjs.native.js +3 -3
  88. package/react/hoc/hoc-utils.js +1 -1
  89. package/react/hoc/hoc.cjs +2 -2
  90. package/react/hoc/hoc.cjs.map +1 -1
  91. package/react/hoc/hoc.cjs.native.js +2 -2
  92. package/react/hoc/withApollo.js +1 -1
  93. package/react/hooks/hooks.cjs +15 -10
  94. package/react/hooks/hooks.cjs.map +1 -1
  95. package/react/hooks/hooks.cjs.native.js +15 -10
  96. package/react/hooks/index.d.ts +1 -0
  97. package/react/hooks/index.d.ts.map +1 -1
  98. package/react/hooks/index.js.map +1 -1
  99. package/react/hooks/useApolloClient.js +1 -1
  100. package/react/hooks/useQuery.js +1 -1
  101. package/react/hooks/useReadQuery.d.ts +7 -4
  102. package/react/hooks/useReadQuery.d.ts.map +1 -1
  103. package/react/hooks/useReadQuery.js +1 -1
  104. package/react/hooks/useReadQuery.js.map +1 -1
  105. package/react/hooks/useSubscription.js +2 -2
  106. package/react/hooks/useSuspenseQuery.js +2 -2
  107. package/react/hooks/useSyncExternalStore.js +1 -1
  108. package/react/parser/index.js +5 -5
  109. package/react/parser/parser.cjs +5 -5
  110. package/react/parser/parser.cjs.map +1 -1
  111. package/react/parser/parser.cjs.native.js +5 -5
  112. package/testing/core/core.cjs +2 -2
  113. package/testing/core/core.cjs.map +1 -1
  114. package/testing/core/core.cjs.native.js +2 -2
  115. package/testing/core/mocking/mockLink.js +2 -2
  116. package/testing/internal/ObservableStream.d.ts +26 -0
  117. package/testing/internal/ObservableStream.d.ts.map +1 -0
  118. package/testing/internal/ObservableStream.js +101 -0
  119. package/testing/internal/ObservableStream.js.map +1 -0
  120. package/testing/internal/index.d.ts +1 -0
  121. package/testing/internal/index.d.ts.map +1 -1
  122. package/testing/internal/index.js +1 -0
  123. package/testing/internal/index.js.map +1 -1
  124. package/testing/react/MockedProvider.d.ts +1 -0
  125. package/testing/react/MockedProvider.d.ts.map +1 -1
  126. package/testing/react/MockedProvider.js +2 -1
  127. package/testing/react/MockedProvider.js.map +1 -1
  128. package/testing/testing.cjs +2 -1
  129. package/testing/testing.cjs.map +1 -1
  130. package/testing/testing.cjs.native.js +2 -1
  131. package/utilities/common/canonicalStringify.d.ts +4 -0
  132. package/utilities/common/canonicalStringify.d.ts.map +1 -0
  133. package/utilities/common/canonicalStringify.js +37 -0
  134. package/utilities/common/canonicalStringify.js.map +1 -0
  135. package/utilities/globals/globals.cjs +29 -19
  136. package/utilities/globals/globals.cjs.map +1 -1
  137. package/utilities/globals/globals.cjs.native.js +29 -19
  138. package/utilities/globals/invariantWrappers.d.ts.map +1 -1
  139. package/utilities/globals/invariantWrappers.js +28 -18
  140. package/utilities/globals/invariantWrappers.js.map +1 -1
  141. package/utilities/graphql/DocumentTransform.js +1 -1
  142. package/utilities/graphql/directives.js +4 -4
  143. package/utilities/graphql/fragments.js +3 -3
  144. package/utilities/graphql/getFromAST.js +8 -8
  145. package/utilities/graphql/storeUtils.d.ts +7 -2
  146. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  147. package/utilities/graphql/storeUtils.js +8 -20
  148. package/utilities/graphql/storeUtils.js.map +1 -1
  149. package/utilities/graphql/transform.js +2 -2
  150. package/utilities/index.d.ts +2 -1
  151. package/utilities/index.d.ts.map +1 -1
  152. package/utilities/index.js +1 -0
  153. package/utilities/index.js.map +1 -1
  154. package/utilities/observables/asyncMap.d.ts.map +1 -1
  155. package/utilities/observables/asyncMap.js +17 -34
  156. package/utilities/observables/asyncMap.js.map +1 -1
  157. package/utilities/subscriptions/relay/index.d.ts +6 -0
  158. package/utilities/subscriptions/relay/index.d.ts.map +1 -0
  159. package/utilities/subscriptions/relay/index.js +43 -0
  160. package/utilities/subscriptions/relay/index.js.map +1 -0
  161. package/utilities/subscriptions/relay/package.json +8 -0
  162. package/utilities/subscriptions/relay/relay.cjs +368 -0
  163. package/utilities/subscriptions/relay/relay.cjs.map +1 -0
  164. package/utilities/subscriptions/relay/relay.cjs.native.js +368 -0
  165. package/utilities/subscriptions/shared.d.ts +9 -0
  166. package/utilities/subscriptions/shared.d.ts.map +1 -0
  167. package/utilities/subscriptions/shared.js +7 -0
  168. package/utilities/subscriptions/shared.js.map +1 -0
  169. package/utilities/subscriptions/urql/index.d.ts +7 -0
  170. package/utilities/subscriptions/urql/index.d.ts.map +1 -0
  171. package/utilities/subscriptions/urql/index.js +40 -0
  172. package/utilities/subscriptions/urql/index.js.map +1 -0
  173. package/utilities/subscriptions/urql/package.json +8 -0
  174. package/utilities/subscriptions/urql/urql.cjs +364 -0
  175. package/utilities/subscriptions/urql/urql.cjs.map +1 -0
  176. package/utilities/subscriptions/urql/urql.cjs.native.js +364 -0
  177. package/utilities/utilities.cjs +80 -72
  178. package/utilities/utilities.cjs.map +1 -1
  179. package/utilities/utilities.cjs.native.js +80 -72
  180. package/version.js +1 -1
package/cache/cache.cjs CHANGED
@@ -370,6 +370,41 @@ exports.EntityStore = (function () {
370
370
  changedFields_1[storeFieldName] = newValue;
371
371
  needToMerge_1 = true;
372
372
  fieldValue = newValue;
373
+ if (globalThis.__DEV__ !== false) {
374
+ var checkReference = function (ref) {
375
+ if (_this.lookup(ref.__ref) === undefined) {
376
+ globalThis.__DEV__ !== false && globals.invariant.warn(2, ref);
377
+ return true;
378
+ }
379
+ };
380
+ if (utilities.isReference(newValue)) {
381
+ checkReference(newValue);
382
+ }
383
+ else if (Array.isArray(newValue)) {
384
+ var seenReference = false;
385
+ var someNonReference = void 0;
386
+ for (var _i = 0, newValue_1 = newValue; _i < newValue_1.length; _i++) {
387
+ var value = newValue_1[_i];
388
+ if (utilities.isReference(value)) {
389
+ seenReference = true;
390
+ if (checkReference(value))
391
+ break;
392
+ }
393
+ else {
394
+ if (typeof value === "object" && !!value) {
395
+ var id = _this.policies.identify(value)[0];
396
+ if (id) {
397
+ someNonReference = value;
398
+ }
399
+ }
400
+ }
401
+ if (seenReference && someNonReference !== undefined) {
402
+ globalThis.__DEV__ !== false && globals.invariant.warn(3, someNonReference);
403
+ break;
404
+ }
405
+ }
406
+ }
407
+ }
373
408
  }
374
409
  }
375
410
  }
@@ -766,28 +801,6 @@ var ObjectCanon = (function () {
766
801
  };
767
802
  return ObjectCanon;
768
803
  }());
769
- var canonicalStringify = Object.assign(function (value) {
770
- if (utilities.isNonNullObject(value)) {
771
- if (stringifyCanon === void 0) {
772
- resetCanonicalStringify();
773
- }
774
- var canonical = stringifyCanon.admit(value);
775
- var json = stringifyCache.get(canonical);
776
- if (json === void 0) {
777
- stringifyCache.set(canonical, (json = JSON.stringify(canonical)));
778
- }
779
- return json;
780
- }
781
- return JSON.stringify(value);
782
- }, {
783
- reset: resetCanonicalStringify,
784
- });
785
- var stringifyCanon;
786
- var stringifyCache;
787
- function resetCanonicalStringify() {
788
- stringifyCanon = new ObjectCanon();
789
- stringifyCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
790
- }
791
804
 
792
805
  function execSelectionSetKeyArgs(options) {
793
806
  return [
@@ -854,7 +867,7 @@ var StoreReader = (function () {
854
867
  selectionSet: utilities.getMainDefinition(query).selectionSet,
855
868
  objectOrReference: rootRef,
856
869
  enclosingRef: rootRef,
857
- context: tslib.__assign({ store: store, query: query, policies: policies, variables: variables, varString: canonicalStringify(variables), canonizeResults: canonizeResults }, extractFragmentContext(query, this.config.fragments)),
870
+ context: tslib.__assign({ store: store, query: query, policies: policies, variables: variables, varString: utilities.canonicalStringify(variables), canonizeResults: canonizeResults }, extractFragmentContext(query, this.config.fragments)),
858
871
  });
859
872
  var missing;
860
873
  if (execResult.missing) {
@@ -961,7 +974,7 @@ var StoreReader = (function () {
961
974
  else {
962
975
  var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
963
976
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
964
- throw globals.newInvariantError(7, selection.name.value);
977
+ throw globals.newInvariantError(9, selection.name.value);
965
978
  }
966
979
  if (fragment && policies.fragmentMatches(fragment, typename)) {
967
980
  fragment.selectionSet.selections.forEach(workSet.add, workSet);
@@ -1045,7 +1058,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
1045
1058
  if (utilities.isNonNullObject(value)) {
1046
1059
  globals.invariant(
1047
1060
  !utilities.isReference(value),
1048
- 8,
1061
+ 10,
1049
1062
  getTypenameFromStoreObject(store, value),
1050
1063
  field.name.value
1051
1064
  );
@@ -1137,7 +1150,7 @@ function keyFieldsFnFromSpecifier(specifier) {
1137
1150
  hasOwn.call(object, schemaKeyPath[0])) {
1138
1151
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
1139
1152
  }
1140
- globals.invariant(extracted !== void 0, 2, schemaKeyPath.join("."), object);
1153
+ globals.invariant(extracted !== void 0, 4, schemaKeyPath.join("."), object);
1141
1154
  return extracted;
1142
1155
  }));
1143
1156
  return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
@@ -1239,7 +1252,6 @@ function normalize(value) {
1239
1252
  return value;
1240
1253
  }
1241
1254
 
1242
- utilities.getStoreKeyName.setStringify(canonicalStringify);
1243
1255
  function argsFromFieldSpecifier(spec) {
1244
1256
  return spec.args !== void 0
1245
1257
  ? spec.args
@@ -1392,7 +1404,7 @@ var Policies = (function () {
1392
1404
  var rootId = "ROOT_" + which.toUpperCase();
1393
1405
  var old = this.rootTypenamesById[rootId];
1394
1406
  if (typename !== old) {
1395
- globals.invariant(!old || old === which, 3, which);
1407
+ globals.invariant(!old || old === which, 5, which);
1396
1408
  if (old)
1397
1409
  delete this.rootIdsByTypename[old];
1398
1410
  this.rootIdsByTypename[typename] = rootId;
@@ -1489,7 +1501,7 @@ var Policies = (function () {
1489
1501
  if (supertypeSet.has(supertype)) {
1490
1502
  if (!typenameSupertypeSet.has(supertype)) {
1491
1503
  if (checkingFuzzySubtypes) {
1492
- globalThis.__DEV__ !== false && globals.invariant.warn(4, typename, supertype);
1504
+ globalThis.__DEV__ !== false && globals.invariant.warn(6, typename, supertype);
1493
1505
  }
1494
1506
  typenameSupertypeSet.add(supertype);
1495
1507
  }
@@ -1651,7 +1663,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
1651
1663
  }
1652
1664
  }
1653
1665
  if (globalThis.__DEV__ !== false && options.from === void 0) {
1654
- globalThis.__DEV__ !== false && globals.invariant.warn(5, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
1666
+ globalThis.__DEV__ !== false && globals.invariant.warn(7, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
1655
1667
  }
1656
1668
  if (void 0 === options.variables) {
1657
1669
  options.variables = variables;
@@ -1661,7 +1673,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
1661
1673
  function makeMergeObjectsFunction(store) {
1662
1674
  return function mergeObjects(existing, incoming) {
1663
1675
  if (utilities.isArray(existing) || utilities.isArray(incoming)) {
1664
- throw globals.newInvariantError(6);
1676
+ throw globals.newInvariantError(8);
1665
1677
  }
1666
1678
  if (utilities.isNonNullObject(existing) && utilities.isNonNullObject(incoming)) {
1667
1679
  var eType = store.getFieldValue(existing, "__typename");
@@ -1712,7 +1724,7 @@ var StoreWriter = (function () {
1712
1724
  variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(operationDefinition)), variables);
1713
1725
  var context = tslib.__assign(tslib.__assign({ store: store, written: Object.create(null), merge: function (existing, incoming) {
1714
1726
  return merger.merge(existing, incoming);
1715
- }, variables: variables, varString: canonicalStringify(variables) }, extractFragmentContext(query, this.fragments)), { overwrite: !!overwrite, incomingById: new Map(), clientOnly: false, deferred: false, flavors: new Map() });
1727
+ }, variables: variables, varString: utilities.canonicalStringify(variables) }, extractFragmentContext(query, this.fragments)), { overwrite: !!overwrite, incomingById: new Map(), clientOnly: false, deferred: false, flavors: new Map() });
1716
1728
  var ref = this.processSelectionSet({
1717
1729
  result: result || Object.create(null),
1718
1730
  dataId: dataId,
@@ -1721,7 +1733,7 @@ var StoreWriter = (function () {
1721
1733
  context: context,
1722
1734
  });
1723
1735
  if (!utilities.isReference(ref)) {
1724
- throw globals.newInvariantError(9, result);
1736
+ throw globals.newInvariantError(11, result);
1725
1737
  }
1726
1738
  context.incomingById.forEach(function (_a, dataId) {
1727
1739
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -1826,7 +1838,7 @@ var StoreWriter = (function () {
1826
1838
  !context.deferred &&
1827
1839
  !utilities.addTypenameToDocument.added(field) &&
1828
1840
  !policies.getReadFunction(typename, field.name.value)) {
1829
- globalThis.__DEV__ !== false && globals.invariant.error(10, utilities.resultKeyNameFromField(field), result);
1841
+ globalThis.__DEV__ !== false && globals.invariant.error(12, utilities.resultKeyNameFromField(field), result);
1830
1842
  }
1831
1843
  });
1832
1844
  try {
@@ -1931,7 +1943,7 @@ var StoreWriter = (function () {
1931
1943
  else {
1932
1944
  var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
1933
1945
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
1934
- throw globals.newInvariantError(11, selection.name.value);
1946
+ throw globals.newInvariantError(13, selection.name.value);
1935
1947
  }
1936
1948
  if (fragment &&
1937
1949
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
@@ -2073,7 +2085,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
2073
2085
  }
2074
2086
  });
2075
2087
  }
2076
- globalThis.__DEV__ !== false && globals.invariant.warn(12, fieldName, parentType, childTypenames.length
2088
+ globalThis.__DEV__ !== false && globals.invariant.warn(14, fieldName, parentType, childTypenames.length
2077
2089
  ? "either ensure all objects of type " +
2078
2090
  childTypenames.join(" and ") +
2079
2091
  " have an ID or a custom merge function, or "
@@ -2131,7 +2143,7 @@ var InMemoryCache = (function (_super) {
2131
2143
  var store = c.optimistic ? _this.optimisticData : _this.data;
2132
2144
  if (supportsResultCaching(store)) {
2133
2145
  var optimistic = c.optimistic, id = c.id, variables = c.variables;
2134
- return store.makeCacheKey(c.query, c.callback, canonicalStringify({ optimistic: optimistic, id: id, variables: variables }));
2146
+ return store.makeCacheKey(c.query, c.callback, utilities.canonicalStringify({ optimistic: optimistic, id: id, variables: variables }));
2135
2147
  }
2136
2148
  },
2137
2149
  });
@@ -2209,7 +2221,7 @@ var InMemoryCache = (function (_super) {
2209
2221
  };
2210
2222
  };
2211
2223
  InMemoryCache.prototype.gc = function (options) {
2212
- canonicalStringify.reset();
2224
+ utilities.canonicalStringify.reset();
2213
2225
  var ids = this.optimisticData.gc();
2214
2226
  if (options && !this.txCount) {
2215
2227
  if (options.resetResultCache) {
@@ -2257,7 +2269,7 @@ var InMemoryCache = (function (_super) {
2257
2269
  InMemoryCache.prototype.reset = function (options) {
2258
2270
  var _this = this;
2259
2271
  this.init();
2260
- canonicalStringify.reset();
2272
+ utilities.canonicalStringify.reset();
2261
2273
  if (options && options.discardWatches) {
2262
2274
  this.watches.forEach(function (watch) { return _this.maybeBroadcastWatch.forget(watch); });
2263
2275
  this.watches.clear();
@@ -2485,6 +2497,7 @@ var FragmentRegistry = (function () {
2485
2497
  return FragmentRegistry;
2486
2498
  }());
2487
2499
 
2500
+ exports.canonicalStringify = utilities.canonicalStringify;
2488
2501
  exports.isReference = utilities.isReference;
2489
2502
  exports.makeReference = utilities.makeReference;
2490
2503
  exports.ApolloCache = ApolloCache;
@@ -2492,7 +2505,6 @@ exports.InMemoryCache = InMemoryCache;
2492
2505
  exports.MissingFieldError = MissingFieldError;
2493
2506
  exports.Policies = Policies;
2494
2507
  exports.cacheSlot = cacheSlot;
2495
- exports.canonicalStringify = canonicalStringify;
2496
2508
  exports.createFragmentRegistry = createFragmentRegistry;
2497
2509
  exports.defaultDataIdFromObject = defaultDataIdFromObject;
2498
2510
  exports.fieldNameFromStoreName = fieldNameFromStoreName;