@apollo/client 3.6.4 → 3.6.5

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.
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
  };
@@ -1303,7 +1300,7 @@ var concat = ApolloLink.concat;
1303
1300
 
1304
1301
  var execute = ApolloLink.execute;
1305
1302
 
1306
- var version = '3.6.4';
1303
+ var version = '3.6.5';
1307
1304
 
1308
1305
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1309
1306
  function parseAndCheckHttpResponse(operations) {
@@ -2396,7 +2393,6 @@ var StoreReader = (function () {
2396
2393
  var policies = this.config.cache.policies;
2397
2394
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2398
2395
  var rootRef = makeReference(rootId);
2399
- var merger = new DeepMerger;
2400
2396
  var execResult = this.executeSelectionSet({
2401
2397
  selectionSet: getMainDefinition(query).selectionSet,
2402
2398
  objectOrReference: rootRef,
@@ -2409,9 +2405,6 @@ var StoreReader = (function () {
2409
2405
  varString: canonicalStringify(variables),
2410
2406
  canonizeResults: canonizeResults,
2411
2407
  fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
2412
- merge: function (a, b) {
2413
- return merger.merge(a, b);
2414
- },
2415
2408
  },
2416
2409
  });
2417
2410
  var missing;
@@ -2450,17 +2443,18 @@ var StoreReader = (function () {
2450
2443
  }
2451
2444
  var variables = context.variables, policies = context.policies, store = context.store;
2452
2445
  var typename = store.getFieldValue(objectOrReference, "__typename");
2453
- var result = {};
2446
+ var objectsToMerge = [];
2454
2447
  var missing;
2448
+ var missingMerger = new DeepMerger();
2455
2449
  if (this.config.addTypename &&
2456
2450
  typeof typename === "string" &&
2457
2451
  !policies.rootIdsByTypename[typename]) {
2458
- result = { __typename: typename };
2452
+ objectsToMerge.push({ __typename: typename });
2459
2453
  }
2460
2454
  function handleMissing(result, resultName) {
2461
2455
  var _a;
2462
2456
  if (result.missing) {
2463
- missing = context.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2457
+ missing = missingMerger.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2464
2458
  }
2465
2459
  return result.result;
2466
2460
  }
@@ -2479,7 +2473,7 @@ var StoreReader = (function () {
2479
2473
  var resultName = resultKeyNameFromField(selection);
2480
2474
  if (fieldValue === void 0) {
2481
2475
  if (!addTypenameToDocument.added(selection)) {
2482
- missing = context.merge(missing, (_a = {},
2476
+ missing = missingMerger.merge(missing, (_a = {},
2483
2477
  _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(isReference(objectOrReference)
2484
2478
  ? objectOrReference.__ref + " object"
2485
2479
  : "object " + JSON.stringify(objectOrReference, null, 2)),
@@ -2508,7 +2502,7 @@ var StoreReader = (function () {
2508
2502
  }), resultName);
2509
2503
  }
2510
2504
  if (fieldValue !== void 0) {
2511
- result = context.merge(result, (_b = {}, _b[resultName] = fieldValue, _b));
2505
+ objectsToMerge.push((_b = {}, _b[resultName] = fieldValue, _b));
2512
2506
  }
2513
2507
  }
2514
2508
  else {
@@ -2518,6 +2512,7 @@ var StoreReader = (function () {
2518
2512
  }
2519
2513
  }
2520
2514
  });
2515
+ var result = mergeDeepArray(objectsToMerge);
2521
2516
  var finalResult = { result: result, missing: missing };
2522
2517
  var frozen = context.canonizeResults
2523
2518
  ? this.canon.admit(finalResult)
@@ -2531,10 +2526,11 @@ var StoreReader = (function () {
2531
2526
  var _this = this;
2532
2527
  var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
2533
2528
  var missing;
2529
+ var missingMerger = new DeepMerger();
2534
2530
  function handleMissing(childResult, i) {
2535
2531
  var _a;
2536
2532
  if (childResult.missing) {
2537
- missing = context.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2533
+ missing = missingMerger.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2538
2534
  }
2539
2535
  return childResult.result;
2540
2536
  }
@@ -4307,7 +4303,7 @@ var ObservableQuery = (function (_super) {
4307
4303
  newNetworkStatus === exports.NetworkStatus.poll;
4308
4304
  var oldVariables = this.options.variables;
4309
4305
  var oldFetchPolicy = this.options.fetchPolicy;
4310
- var mergedOptions = mergeOptions(this.options, newOptions || {});
4306
+ var mergedOptions = compact(this.options, newOptions || {});
4311
4307
  var options = useDisposableConcast
4312
4308
  ? mergedOptions
4313
4309
  : assign(this.options, mergedOptions);
@@ -6189,7 +6185,7 @@ function useInternalState(client, query) {
6189
6185
  if (!stateRef.current ||
6190
6186
  client !== stateRef.current.client ||
6191
6187
  query !== stateRef.current.query) {
6192
- stateRef.current = new InternalState(client, query);
6188
+ stateRef.current = new InternalState(client, query, stateRef.current);
6193
6189
  }
6194
6190
  var state = stateRef.current;
6195
6191
  var _a = React.useState(0); _a[0]; var setTick = _a[1];
@@ -6199,7 +6195,7 @@ function useInternalState(client, query) {
6199
6195
  return state;
6200
6196
  }
6201
6197
  var InternalState = (function () {
6202
- function InternalState(client, query) {
6198
+ function InternalState(client, query, previous) {
6203
6199
  this.client = client;
6204
6200
  this.query = query;
6205
6201
  this.asyncResolveFns = new Set();
@@ -6218,6 +6214,11 @@ var InternalState = (function () {
6218
6214
  });
6219
6215
  this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6220
6216
  verifyDocumentType(query, exports.DocumentType.Query);
6217
+ var previousResult = previous && previous.result;
6218
+ var previousData = previousResult && previousResult.data;
6219
+ if (previousData) {
6220
+ this.previousData = previousData;
6221
+ }
6221
6222
  }
6222
6223
  InternalState.prototype.forceUpdate = function () {
6223
6224
  __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
@@ -6443,7 +6444,10 @@ var EAGER_METHODS = [
6443
6444
  function useLazyQuery(query, options) {
6444
6445
  var internalState = useInternalState(useApolloClient(options && options.client), query);
6445
6446
  var execOptionsRef = React.useRef();
6446
- var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
6447
+ var merged = execOptionsRef.current
6448
+ ? mergeOptions(options, execOptionsRef.current)
6449
+ : options;
6450
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
6447
6451
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
6448
6452
  internalState.getDefaultFetchPolicy();
6449
6453
  var result = Object.assign(useQueryResult, {
@@ -6516,7 +6520,7 @@ function useMutation(mutation, options) {
6516
6520
  var mutationId = ++ref.current.mutationId;
6517
6521
  var clientOptions = mergeOptions(baseOptions, executeOptions);
6518
6522
  return client.mutate(clientOptions).then(function (response) {
6519
- var _a, _b;
6523
+ var _a, _b, _c;
6520
6524
  var data = response.data, errors = response.errors;
6521
6525
  var error = errors && errors.length > 0
6522
6526
  ? new ApolloError({ graphQLErrors: errors })
@@ -6534,11 +6538,11 @@ function useMutation(mutation, options) {
6534
6538
  setResult(ref.current.result = result_1);
6535
6539
  }
6536
6540
  }
6537
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6538
- (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
6541
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
6542
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
6539
6543
  return response;
6540
6544
  }).catch(function (error) {
6541
- var _a, _b;
6545
+ var _a, _b, _c, _d;
6542
6546
  if (mutationId === ref.current.mutationId &&
6543
6547
  ref.current.isMounted) {
6544
6548
  var result_2 = {
@@ -6552,9 +6556,9 @@ function useMutation(mutation, options) {
6552
6556
  setResult(ref.current.result = result_2);
6553
6557
  }
6554
6558
  }
6555
- if (baseOptions.onError || clientOptions.onError) {
6556
- (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
6557
- (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
6559
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
6560
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
6561
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
6558
6562
  return { data: void 0, errors: error };
6559
6563
  }
6560
6564
  throw error;