@apollo/client 3.7.0-alpha.3 → 3.7.0-alpha.6

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 (70) hide show
  1. package/apollo-client.cjs +68 -60
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +9 -10
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +2288 -0
  7. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  8. package/cache/inmemory/readFromStore.js +10 -11
  9. package/cache/inmemory/readFromStore.js.map +1 -1
  10. package/core/ObservableQuery.d.ts.map +1 -1
  11. package/core/ObservableQuery.js +3 -3
  12. package/core/ObservableQuery.js.map +1 -1
  13. package/core/QueryManager.d.ts.map +1 -1
  14. package/core/QueryManager.js +4 -3
  15. package/core/QueryManager.js.map +1 -1
  16. package/core/core.cjs +6 -5
  17. package/core/core.cjs.map +1 -1
  18. package/core/core.cjs.native.js +2142 -0
  19. package/errors/errors.cjs.native.js +48 -0
  20. package/invariantErrorCodes.js +1 -1
  21. package/link/batch/batch.cjs.native.js +161 -0
  22. package/link/batch-http/batch-http.cjs.native.js +127 -0
  23. package/link/context/context.cjs.native.js +38 -0
  24. package/link/core/core.cjs.native.js +121 -0
  25. package/link/error/error.cjs.native.js +90 -0
  26. package/link/http/http.cjs.native.js +320 -0
  27. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  28. package/link/retry/retry.cjs.native.js +170 -0
  29. package/link/schema/schema.cjs.native.js +56 -0
  30. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  31. package/link/utils/utils.cjs.native.js +115 -0
  32. package/link/ws/ws.cjs.native.js +28 -0
  33. package/main.cjs.native.js +16 -0
  34. package/package.json +12 -12
  35. package/react/components/components.cjs.native.js +79 -0
  36. package/react/context/context.cjs.native.js +67 -0
  37. package/react/hoc/hoc.cjs.native.js +325 -0
  38. package/react/hooks/hooks.cjs +28 -15
  39. package/react/hooks/hooks.cjs.map +1 -1
  40. package/react/hooks/hooks.cjs.native.js +609 -0
  41. package/react/hooks/useQuery.d.ts +1 -1
  42. package/react/hooks/useQuery.d.ts.map +1 -1
  43. package/react/hooks/useQuery.js +7 -2
  44. package/react/hooks/useQuery.js.map +1 -1
  45. package/react/hooks/useSubscription.d.ts.map +1 -1
  46. package/react/hooks/useSubscription.js +17 -7
  47. package/react/hooks/useSubscription.js.map +1 -1
  48. package/react/hooks/useSyncExternalStore.d.ts.map +1 -1
  49. package/react/hooks/useSyncExternalStore.js +4 -6
  50. package/react/hooks/useSyncExternalStore.js.map +1 -1
  51. package/react/parser/parser.cjs.native.js +103 -0
  52. package/react/react.cjs.native.js +22 -0
  53. package/react/ssr/ssr.cjs.native.js +150 -0
  54. package/testing/core/core.cjs.native.js +288 -0
  55. package/testing/testing.cjs.native.js +58 -0
  56. package/utilities/common/mergeDeep.d.ts.map +1 -1
  57. package/utilities/common/mergeDeep.js +8 -11
  58. package/utilities/common/mergeDeep.js.map +1 -1
  59. package/utilities/globals/globals.cjs.native.js +56 -0
  60. package/utilities/observables/Concast.d.ts +5 -3
  61. package/utilities/observables/Concast.d.ts.map +1 -1
  62. package/utilities/observables/Concast.js +17 -19
  63. package/utilities/observables/Concast.js.map +1 -1
  64. package/utilities/policies/pagination.d.ts.map +1 -1
  65. package/utilities/policies/pagination.js +9 -7
  66. package/utilities/policies/pagination.js.map +1 -1
  67. package/utilities/utilities.cjs +34 -37
  68. package/utilities/utilities.cjs.map +1 -1
  69. package/utilities/utilities.cjs.native.js +1279 -0
  70. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -761,18 +761,15 @@ var DeepMerger = (function () {
761
761
  };
762
762
  DeepMerger.prototype.shallowCopyForMerge = function (value) {
763
763
  if (isNonNullObject(value)) {
764
- if (this.pastCopies.has(value)) {
765
- if (!Object.isFrozen(value))
766
- return value;
767
- this.pastCopies.delete(value);
768
- }
769
- if (Array.isArray(value)) {
770
- value = value.slice(0);
771
- }
772
- else {
773
- value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
764
+ if (!this.pastCopies.has(value)) {
765
+ if (Array.isArray(value)) {
766
+ value = value.slice(0);
767
+ }
768
+ else {
769
+ value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
770
+ }
771
+ this.pastCopies.add(value);
774
772
  }
775
- this.pastCopies.add(value);
776
773
  }
777
774
  return value;
778
775
  };
@@ -929,7 +926,6 @@ var Concast = (function (_super) {
929
926
  return function () { return _this.removeObserver(observer); };
930
927
  }) || this;
931
928
  _this.observers = new Set();
932
- _this.addCount = 0;
933
929
  _this.promise = new Promise(function (resolve, reject) {
934
930
  _this.resolve = resolve;
935
931
  _this.reject = reject;
@@ -938,6 +934,7 @@ var Concast = (function (_super) {
938
934
  next: function (result) {
939
935
  if (_this.sub !== null) {
940
936
  _this.latest = ["next", result];
937
+ _this.notify("next", result);
941
938
  iterateObserversSafely(_this.observers, "next", result);
942
939
  }
943
940
  },
@@ -949,6 +946,7 @@ var Concast = (function (_super) {
949
946
  _this.sub = null;
950
947
  _this.latest = ["error", error];
951
948
  _this.reject(error);
949
+ _this.notify("error", error);
952
950
  iterateObserversSafely(_this.observers, "error", error);
953
951
  }
954
952
  },
@@ -967,6 +965,7 @@ var Concast = (function (_super) {
967
965
  else {
968
966
  _this.resolve();
969
967
  }
968
+ _this.notify("complete");
970
969
  iterateObserversSafely(_this.observers, "complete");
971
970
  }
972
971
  else if (isPromiseLike(value)) {
@@ -978,6 +977,7 @@ var Concast = (function (_super) {
978
977
  }
979
978
  },
980
979
  };
980
+ _this.nextResultListeners = new Set();
981
981
  _this.cancel = function (reason) {
982
982
  _this.reject(reason);
983
983
  _this.sources = [];
@@ -1019,34 +1019,29 @@ var Concast = (function (_super) {
1019
1019
  if (!this.observers.has(observer)) {
1020
1020
  this.deliverLastMessage(observer);
1021
1021
  this.observers.add(observer);
1022
- ++this.addCount;
1023
1022
  }
1024
1023
  };
1025
- Concast.prototype.removeObserver = function (observer, quietly) {
1024
+ Concast.prototype.removeObserver = function (observer) {
1026
1025
  if (this.observers.delete(observer) &&
1027
- --this.addCount < 1 &&
1028
- !quietly) {
1026
+ this.observers.size < 1) {
1029
1027
  this.handlers.complete();
1030
1028
  }
1031
1029
  };
1032
- Concast.prototype.cleanup = function (callback) {
1033
- var _this = this;
1030
+ Concast.prototype.notify = function (method, arg) {
1031
+ var nextResultListeners = this.nextResultListeners;
1032
+ if (nextResultListeners.size) {
1033
+ this.nextResultListeners = new Set;
1034
+ nextResultListeners.forEach(function (listener) { return listener(method, arg); });
1035
+ }
1036
+ };
1037
+ Concast.prototype.beforeNext = function (callback) {
1034
1038
  var called = false;
1035
- var once = function () {
1039
+ this.nextResultListeners.add(function (method, arg) {
1036
1040
  if (!called) {
1037
1041
  called = true;
1038
- _this.observers.delete(observer);
1039
- callback();
1042
+ callback(method, arg);
1040
1043
  }
1041
- };
1042
- var observer = {
1043
- next: once,
1044
- error: once,
1045
- complete: once,
1046
- };
1047
- var count = this.addCount;
1048
- this.addObserver(observer);
1049
- this.addCount = count;
1044
+ });
1050
1045
  };
1051
1046
  return Concast;
1052
1047
  }(zenObservableTs.Observable));
@@ -1303,7 +1298,7 @@ var concat = ApolloLink.concat;
1303
1298
 
1304
1299
  var execute = ApolloLink.execute;
1305
1300
 
1306
- var version = '3.7.0-alpha.3';
1301
+ var version = '3.7.0-alpha.6';
1307
1302
 
1308
1303
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1309
1304
  function parseAndCheckHttpResponse(operations) {
@@ -2396,7 +2391,6 @@ var StoreReader = (function () {
2396
2391
  var policies = this.config.cache.policies;
2397
2392
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2398
2393
  var rootRef = makeReference(rootId);
2399
- var merger = new DeepMerger;
2400
2394
  var execResult = this.executeSelectionSet({
2401
2395
  selectionSet: getMainDefinition(query).selectionSet,
2402
2396
  objectOrReference: rootRef,
@@ -2409,9 +2403,6 @@ var StoreReader = (function () {
2409
2403
  varString: canonicalStringify(variables),
2410
2404
  canonizeResults: canonizeResults,
2411
2405
  fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
2412
- merge: function (a, b) {
2413
- return merger.merge(a, b);
2414
- },
2415
2406
  },
2416
2407
  });
2417
2408
  var missing;
@@ -2450,17 +2441,18 @@ var StoreReader = (function () {
2450
2441
  }
2451
2442
  var variables = context.variables, policies = context.policies, store = context.store;
2452
2443
  var typename = store.getFieldValue(objectOrReference, "__typename");
2453
- var result = {};
2444
+ var objectsToMerge = [];
2454
2445
  var missing;
2446
+ var missingMerger = new DeepMerger();
2455
2447
  if (this.config.addTypename &&
2456
2448
  typeof typename === "string" &&
2457
2449
  !policies.rootIdsByTypename[typename]) {
2458
- result = { __typename: typename };
2450
+ objectsToMerge.push({ __typename: typename });
2459
2451
  }
2460
2452
  function handleMissing(result, resultName) {
2461
2453
  var _a;
2462
2454
  if (result.missing) {
2463
- missing = context.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2455
+ missing = missingMerger.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2464
2456
  }
2465
2457
  return result.result;
2466
2458
  }
@@ -2479,7 +2471,7 @@ var StoreReader = (function () {
2479
2471
  var resultName = resultKeyNameFromField(selection);
2480
2472
  if (fieldValue === void 0) {
2481
2473
  if (!addTypenameToDocument.added(selection)) {
2482
- missing = context.merge(missing, (_a = {},
2474
+ missing = missingMerger.merge(missing, (_a = {},
2483
2475
  _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(isReference(objectOrReference)
2484
2476
  ? objectOrReference.__ref + " object"
2485
2477
  : "object " + JSON.stringify(objectOrReference, null, 2)),
@@ -2508,7 +2500,7 @@ var StoreReader = (function () {
2508
2500
  }), resultName);
2509
2501
  }
2510
2502
  if (fieldValue !== void 0) {
2511
- result = context.merge(result, (_b = {}, _b[resultName] = fieldValue, _b));
2503
+ objectsToMerge.push((_b = {}, _b[resultName] = fieldValue, _b));
2512
2504
  }
2513
2505
  }
2514
2506
  else {
@@ -2518,6 +2510,7 @@ var StoreReader = (function () {
2518
2510
  }
2519
2511
  }
2520
2512
  });
2513
+ var result = mergeDeepArray(objectsToMerge);
2521
2514
  var finalResult = { result: result, missing: missing };
2522
2515
  var frozen = context.canonizeResults
2523
2516
  ? this.canon.admit(finalResult)
@@ -2531,10 +2524,11 @@ var StoreReader = (function () {
2531
2524
  var _this = this;
2532
2525
  var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
2533
2526
  var missing;
2527
+ var missingMerger = new DeepMerger();
2534
2528
  function handleMissing(childResult, i) {
2535
2529
  var _a;
2536
2530
  if (childResult.missing) {
2537
- missing = context.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2531
+ missing = missingMerger.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2538
2532
  }
2539
2533
  return childResult.result;
2540
2534
  }
@@ -4307,7 +4301,7 @@ var ObservableQuery = (function (_super) {
4307
4301
  newNetworkStatus === exports.NetworkStatus.poll;
4308
4302
  var oldVariables = this.options.variables;
4309
4303
  var oldFetchPolicy = this.options.fetchPolicy;
4310
- var mergedOptions = mergeOptions(this.options, newOptions || {});
4304
+ var mergedOptions = compact(this.options, newOptions || {});
4311
4305
  var options = useDisposableConcast
4312
4306
  ? mergedOptions
4313
4307
  : assign(this.options, mergedOptions);
@@ -4335,7 +4329,7 @@ var ObservableQuery = (function (_super) {
4335
4329
  };
4336
4330
  if (!useDisposableConcast) {
4337
4331
  if (this.concast && this.observer) {
4338
- this.concast.removeObserver(this.observer, true);
4332
+ this.concast.removeObserver(this.observer);
4339
4333
  }
4340
4334
  this.concast = concast;
4341
4335
  this.observer = observer;
@@ -5480,7 +5474,7 @@ var QueryManager = (function () {
5480
5474
  execute(link, operation)
5481
5475
  ]);
5482
5476
  byVariables_1.set(varJson_1, observable = concast);
5483
- concast.cleanup(function () {
5477
+ concast.beforeNext(function () {
5484
5478
  if (byVariables_1.delete(varJson_1) &&
5485
5479
  byVariables_1.size < 1) {
5486
5480
  inFlightLinkObservables_1.delete(serverQuery);
@@ -5515,6 +5509,7 @@ var QueryManager = (function () {
5515
5509
  };
5516
5510
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
5517
5511
  var requestId = queryInfo.lastRequestId = this.generateRequestId();
5512
+ options = cloneDeep(options);
5518
5513
  return asyncMap(this.getObservableFromLink(queryInfo.document, options.context, options.variables), function (result) {
5519
5514
  var hasErrors = isNonEmptyArray(result.errors);
5520
5515
  if (requestId >= queryInfo.lastRequestId) {
@@ -5573,7 +5568,7 @@ var QueryManager = (function () {
5573
5568
  var concast = new Concast(this.transform(normalized.query).hasClientExports
5574
5569
  ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
5575
5570
  : fromVariables(normalized.variables));
5576
- concast.cleanup(function () {
5571
+ concast.beforeNext(function () {
5577
5572
  _this.fetchCancelFns.delete(queryId);
5578
5573
  if (queryInfo.observableQuery) {
5579
5574
  queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
@@ -6042,11 +6037,9 @@ function useApolloClient(override) {
6042
6037
  }
6043
6038
 
6044
6039
  var didWarnUncachedGetSnapshot = false;
6045
- var useSyncExternalStore = function (subscribe, getSnapshot, getServerSnapshot) {
6046
- var realHook = React__namespace.useSyncExternalStore;
6047
- if (realHook) {
6048
- return realHook(subscribe, getSnapshot, getServerSnapshot);
6049
- }
6040
+ var uSESKey = "useSyncExternalStore";
6041
+ var realHook = React__namespace[uSESKey];
6042
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
6050
6043
  var value = getSnapshot();
6051
6044
  if (__DEV__ &&
6052
6045
  !didWarnUncachedGetSnapshot &&
@@ -6077,7 +6070,7 @@ var useSyncExternalStore = function (subscribe, getSnapshot, getServerSnapshot)
6077
6070
  });
6078
6071
  }, [subscribe]);
6079
6072
  return value;
6080
- };
6073
+ });
6081
6074
  function checkIfSnapshotChanged(_a) {
6082
6075
  var value = _a.value, getSnapshot = _a.getSnapshot;
6083
6076
  try {
@@ -6191,7 +6184,7 @@ function useInternalState(client, query) {
6191
6184
  if (!stateRef.current ||
6192
6185
  client !== stateRef.current.client ||
6193
6186
  query !== stateRef.current.query) {
6194
- stateRef.current = new InternalState(client, query);
6187
+ stateRef.current = new InternalState(client, query, stateRef.current);
6195
6188
  }
6196
6189
  var state = stateRef.current;
6197
6190
  var _a = React.useState(0); _a[0]; var setTick = _a[1];
@@ -6201,7 +6194,7 @@ function useInternalState(client, query) {
6201
6194
  return state;
6202
6195
  }
6203
6196
  var InternalState = (function () {
6204
- function InternalState(client, query) {
6197
+ function InternalState(client, query, previous) {
6205
6198
  this.client = client;
6206
6199
  this.query = query;
6207
6200
  this.asyncResolveFns = new Set();
@@ -6220,6 +6213,11 @@ var InternalState = (function () {
6220
6213
  });
6221
6214
  this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6222
6215
  verifyDocumentType(query, exports.DocumentType.Query);
6216
+ var previousResult = previous && previous.result;
6217
+ var previousData = previousResult && previousResult.data;
6218
+ if (previousData) {
6219
+ this.previousData = previousData;
6220
+ }
6223
6221
  }
6224
6222
  InternalState.prototype.forceUpdate = function () {
6225
6223
  __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
@@ -6594,6 +6592,12 @@ function useSubscription(subscription, options) {
6594
6592
  context: options === null || options === void 0 ? void 0 : options.context,
6595
6593
  });
6596
6594
  }), observable = _b[0], setObservable = _b[1];
6595
+ var canResetObservableRef = React.useRef(false);
6596
+ React.useEffect(function () {
6597
+ return function () {
6598
+ canResetObservableRef.current = true;
6599
+ };
6600
+ }, []);
6597
6601
  var ref = React.useRef({ client: client, subscription: subscription, options: options });
6598
6602
  React.useEffect(function () {
6599
6603
  var _a, _b, _c, _d;
@@ -6602,7 +6606,7 @@ function useSubscription(subscription, options) {
6602
6606
  shouldResubscribe = !!shouldResubscribe(options);
6603
6607
  }
6604
6608
  if (options === null || options === void 0 ? void 0 : options.skip) {
6605
- if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6609
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
6606
6610
  setResult({
6607
6611
  loading: false,
6608
6612
  data: void 0,
@@ -6610,13 +6614,16 @@ function useSubscription(subscription, options) {
6610
6614
  variables: options === null || options === void 0 ? void 0 : options.variables,
6611
6615
  });
6612
6616
  setObservable(null);
6617
+ canResetObservableRef.current = false;
6613
6618
  }
6614
6619
  }
6615
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
6616
- subscription !== ref.current.subscription ||
6617
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6618
- !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6619
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6620
+ else if ((shouldResubscribe !== false &&
6621
+ (client !== ref.current.client ||
6622
+ subscription !== ref.current.subscription ||
6623
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6624
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6625
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
6626
+ canResetObservableRef.current) {
6620
6627
  setResult({
6621
6628
  loading: true,
6622
6629
  data: void 0,
@@ -6629,9 +6636,10 @@ function useSubscription(subscription, options) {
6629
6636
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6630
6637
  context: options === null || options === void 0 ? void 0 : options.context,
6631
6638
  }));
6639
+ canResetObservableRef.current = false;
6632
6640
  }
6633
6641
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
6634
- }, [client, subscription, options]);
6642
+ }, [client, subscription, options, canResetObservableRef.current]);
6635
6643
  React.useEffect(function () {
6636
6644
  if (!observable) {
6637
6645
  return;