@apollo/client 3.5.0-beta.13 → 3.5.0-beta.17

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 (131) hide show
  1. package/apollo-client.cjs +216 -160
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -0
  4. package/cache/cache.cjs +132 -101
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/core/cache.d.ts +4 -4
  7. package/cache/core/cache.d.ts.map +1 -1
  8. package/cache/core/cache.js +24 -13
  9. package/cache/core/cache.js.map +1 -1
  10. package/cache/core/types/Cache.d.ts +10 -10
  11. package/cache/core/types/Cache.d.ts.map +1 -1
  12. package/cache/core/types/Cache.js.map +1 -1
  13. package/cache/core/types/DataProxy.js.map +1 -1
  14. package/cache/core/types/common.d.ts +8 -5
  15. package/cache/core/types/common.d.ts.map +1 -1
  16. package/cache/core/types/common.js +6 -11
  17. package/cache/core/types/common.js.map +1 -1
  18. package/cache/index.d.ts +3 -3
  19. package/cache/index.d.ts.map +1 -1
  20. package/cache/index.js +2 -2
  21. package/cache/index.js.map +1 -1
  22. package/cache/inmemory/entityStore.d.ts +1 -1
  23. package/cache/inmemory/entityStore.d.ts.map +1 -1
  24. package/cache/inmemory/entityStore.js +3 -3
  25. package/cache/inmemory/entityStore.js.map +1 -1
  26. package/cache/inmemory/helpers.d.ts +10 -1
  27. package/cache/inmemory/helpers.d.ts.map +1 -1
  28. package/cache/inmemory/helpers.js +31 -1
  29. package/cache/inmemory/helpers.js.map +1 -1
  30. package/cache/inmemory/inMemoryCache.d.ts +6 -12
  31. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  32. package/cache/inmemory/inMemoryCache.js +13 -17
  33. package/cache/inmemory/inMemoryCache.js.map +1 -1
  34. package/cache/inmemory/policies.d.ts +1 -2
  35. package/cache/inmemory/policies.d.ts.map +1 -1
  36. package/cache/inmemory/policies.js +1 -18
  37. package/cache/inmemory/policies.js.map +1 -1
  38. package/cache/inmemory/readFromStore.d.ts +3 -2
  39. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  40. package/cache/inmemory/readFromStore.js +60 -45
  41. package/cache/inmemory/readFromStore.js.map +1 -1
  42. package/cache/inmemory/types.d.ts +8 -1
  43. package/cache/inmemory/types.d.ts.map +1 -1
  44. package/cache/inmemory/types.js.map +1 -1
  45. package/cache/inmemory/writeToStore.js +1 -1
  46. package/core/ApolloClient.js +2 -2
  47. package/core/ApolloClient.js.map +1 -1
  48. package/core/LocalState.js +1 -1
  49. package/core/ObservableQuery.d.ts +2 -1
  50. package/core/ObservableQuery.d.ts.map +1 -1
  51. package/core/ObservableQuery.js +3 -3
  52. package/core/ObservableQuery.js.map +1 -1
  53. package/core/QueryInfo.d.ts.map +1 -1
  54. package/core/QueryInfo.js +2 -2
  55. package/core/QueryInfo.js.map +1 -1
  56. package/core/QueryManager.d.ts.map +1 -1
  57. package/core/QueryManager.js +10 -9
  58. package/core/QueryManager.js.map +1 -1
  59. package/core/core.cjs +19 -18
  60. package/core/core.cjs.map +1 -1
  61. package/core/watchQueryOptions.js.map +1 -1
  62. package/invariantErrorCodes.js +48 -61
  63. package/link/core/ApolloLink.js +1 -1
  64. package/link/core/core.cjs +1 -1
  65. package/link/core/core.cjs.map +1 -1
  66. package/link/http/checkFetcher.js +1 -1
  67. package/link/http/http.cjs +2 -2
  68. package/link/http/http.cjs.map +1 -1
  69. package/link/http/serializeFetchParameter.js +1 -1
  70. package/link/persisted-queries/index.js +2 -2
  71. package/link/persisted-queries/persisted-queries.cjs +2 -2
  72. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  73. package/link/utils/utils.cjs +1 -1
  74. package/link/utils/utils.cjs.map +1 -1
  75. package/link/utils/validateOperation.js +1 -1
  76. package/package.json +9 -9
  77. package/react/context/ApolloConsumer.js +1 -1
  78. package/react/context/ApolloContext.d.ts.map +1 -1
  79. package/react/context/ApolloContext.js +11 -5
  80. package/react/context/ApolloContext.js.map +1 -1
  81. package/react/context/ApolloProvider.js +1 -1
  82. package/react/context/context.cjs +12 -6
  83. package/react/context/context.cjs.map +1 -1
  84. package/react/hoc/hoc-utils.js +1 -1
  85. package/react/hoc/hoc.cjs +10 -7
  86. package/react/hoc/hoc.cjs.map +1 -1
  87. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  88. package/react/hoc/subscription-hoc.js +8 -5
  89. package/react/hoc/subscription-hoc.js.map +1 -1
  90. package/react/hoc/withApollo.js +1 -1
  91. package/react/hooks/hooks.cjs +1 -1
  92. package/react/hooks/hooks.cjs.map +1 -1
  93. package/react/hooks/useApolloClient.js +1 -1
  94. package/react/hooks/useQuery.d.ts +1 -1
  95. package/react/hooks/useQuery.d.ts.map +1 -1
  96. package/react/hooks/useQuery.js.map +1 -1
  97. package/react/parser/index.js +5 -5
  98. package/react/parser/index.js.map +1 -1
  99. package/react/parser/parser.cjs +5 -5
  100. package/react/parser/parser.cjs.map +1 -1
  101. package/testing/core/core.cjs +1 -1
  102. package/testing/core/core.cjs.map +1 -1
  103. package/testing/core/mocking/mockFetch.js.map +1 -1
  104. package/testing/core/mocking/mockLink.js +1 -1
  105. package/utilities/common/canUse.d.ts +1 -0
  106. package/utilities/common/canUse.d.ts.map +1 -1
  107. package/utilities/common/canUse.js +2 -0
  108. package/utilities/common/canUse.js.map +1 -1
  109. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
  110. package/utilities/common/maybeDeepFreeze.js +14 -3
  111. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  112. package/utilities/common/mergeDeep.d.ts.map +1 -1
  113. package/utilities/common/mergeDeep.js +6 -1
  114. package/utilities/common/mergeDeep.js.map +1 -1
  115. package/utilities/globals/globals.cjs +1 -1
  116. package/utilities/globals/globals.cjs.map +1 -1
  117. package/utilities/globals/index.js +1 -1
  118. package/utilities/graphql/directives.js +4 -4
  119. package/utilities/graphql/fragments.js +3 -3
  120. package/utilities/graphql/getFromAST.js +8 -8
  121. package/utilities/graphql/storeUtils.js +1 -1
  122. package/utilities/observables/subclassing.d.ts.map +1 -1
  123. package/utilities/observables/subclassing.js +2 -1
  124. package/utilities/observables/subclassing.js.map +1 -1
  125. package/utilities/policies/pagination.d.ts +1 -1
  126. package/utilities/policies/pagination.d.ts.map +1 -1
  127. package/utilities/policies/pagination.js +7 -2
  128. package/utilities/policies/pagination.js.map +1 -1
  129. package/utilities/utilities.cjs +51 -27
  130. package/utilities/utilities.cjs.map +1 -1
  131. package/version.js +1 -1
package/cache/cache.cjs CHANGED
@@ -15,9 +15,12 @@ var ApolloCache = (function () {
15
15
  this.getFragmentDoc = optimism.wrap(utilities.getFragmentQueryDocument);
16
16
  }
17
17
  ApolloCache.prototype.batch = function (options) {
18
+ var _this = this;
18
19
  var optimisticId = typeof options.optimistic === "string" ? options.optimistic :
19
20
  options.optimistic === false ? null : void 0;
20
- this.performTransaction(options.update, optimisticId);
21
+ var updateResult;
22
+ this.performTransaction(function () { return updateResult = options.update(_this); }, optimisticId);
23
+ return updateResult;
21
24
  };
22
25
  ApolloCache.prototype.recordOptimisticTransaction = function (transaction, optimisticId) {
23
26
  this.performTransaction(transaction, optimisticId);
@@ -61,20 +64,28 @@ var ApolloCache = (function () {
61
64
  }));
62
65
  };
63
66
  ApolloCache.prototype.updateQuery = function (options, update) {
64
- var value = this.readQuery(options);
65
- var data = update(value);
66
- if (data === void 0 || data === null)
67
- return value;
68
- this.writeQuery(tslib.__assign(tslib.__assign({}, options), { data: data }));
69
- return data;
67
+ return this.batch({
68
+ update: function (cache) {
69
+ var value = cache.readQuery(options);
70
+ var data = update(value);
71
+ if (data === void 0 || data === null)
72
+ return value;
73
+ cache.writeQuery(tslib.__assign(tslib.__assign({}, options), { data: data }));
74
+ return data;
75
+ },
76
+ });
70
77
  };
71
78
  ApolloCache.prototype.updateFragment = function (options, update) {
72
- var value = this.readFragment(options);
73
- var data = update(value);
74
- if (data === void 0 || data === null)
75
- return value;
76
- this.writeFragment(tslib.__assign(tslib.__assign({}, options), { data: data }));
77
- return data;
79
+ return this.batch({
80
+ update: function (cache) {
81
+ var value = cache.readFragment(options);
82
+ var data = update(value);
83
+ if (data === void 0 || data === null)
84
+ return value;
85
+ cache.writeFragment(tslib.__assign(tslib.__assign({}, options), { data: data }));
86
+ return data;
87
+ },
88
+ });
78
89
  };
79
90
  return ApolloCache;
80
91
  }());
@@ -83,21 +94,47 @@ exports.Cache = void 0;
83
94
  (function (Cache) {
84
95
  })(exports.Cache || (exports.Cache = {}));
85
96
 
86
- var MissingFieldError = (function (_super) {
87
- tslib.__extends(MissingFieldError, _super);
97
+ var MissingFieldError = (function () {
88
98
  function MissingFieldError(message, path, query, variables) {
89
- var _this = _super.call(this, message) || this;
90
- _this.message = message;
91
- _this.path = path;
92
- _this.query = query;
93
- _this.variables = variables;
94
- _this.__proto__ = MissingFieldError.prototype;
95
- return _this;
99
+ this.message = message;
100
+ this.path = path;
101
+ this.query = query;
102
+ this.variables = variables;
96
103
  }
97
104
  return MissingFieldError;
98
- }(Error));
105
+ }());
99
106
 
100
107
  var hasOwn = Object.prototype.hasOwnProperty;
108
+ function defaultDataIdFromObject(_a, context) {
109
+ var __typename = _a.__typename, id = _a.id, _id = _a._id;
110
+ if (typeof __typename === "string") {
111
+ if (context) {
112
+ context.keyObject =
113
+ id !== void 0 ? { id: id } :
114
+ _id !== void 0 ? { _id: _id } :
115
+ void 0;
116
+ }
117
+ if (id === void 0)
118
+ id = _id;
119
+ if (id !== void 0) {
120
+ return __typename + ":" + ((typeof id === "number" ||
121
+ typeof id === "string") ? id : JSON.stringify(id));
122
+ }
123
+ }
124
+ }
125
+ var defaultConfig = {
126
+ dataIdFromObject: defaultDataIdFromObject,
127
+ addTypename: true,
128
+ resultCaching: true,
129
+ canonizeResults: false,
130
+ };
131
+ function normalizeConfig(config) {
132
+ return utilities.compact(defaultConfig, config);
133
+ }
134
+ function shouldCanonizeResults(config) {
135
+ var value = config.canonizeResults;
136
+ return value === void 0 ? defaultConfig.canonizeResults : value;
137
+ }
101
138
  function getTypenameFromStoreObject(store, objectOrReference) {
102
139
  return utilities.isReference(objectOrReference)
103
140
  ? store.get(objectOrReference.__ref, "__typename")
@@ -326,14 +363,14 @@ exports.EntityStore = (function () {
326
363
  }
327
364
  return false;
328
365
  };
329
- EntityStore.prototype.evict = function (options) {
366
+ EntityStore.prototype.evict = function (options, limit) {
330
367
  var evicted = false;
331
368
  if (options.id) {
332
369
  if (hasOwn.call(this.data, options.id)) {
333
370
  evicted = this.delete(options.id, options.fieldName, options.args);
334
371
  }
335
- if (this instanceof Layer) {
336
- evicted = this.parent.evict(options) || evicted;
372
+ if (this instanceof Layer && this !== limit) {
373
+ evicted = this.parent.evict(options, limit) || evicted;
337
374
  }
338
375
  if (options.fieldName || evicted) {
339
376
  this.group.dirty(options.id, options.fieldName || "__exists");
@@ -706,9 +743,6 @@ function resetCanonicalStringify() {
706
743
  stringifyCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
707
744
  }
708
745
 
709
- function missingFromInvariant(err, context) {
710
- return new MissingFieldError(err.message, context.path.slice(), context.query, context.variables);
711
- }
712
746
  function execSelectionSetKeyArgs(options) {
713
747
  return [
714
748
  options.selectionSet,
@@ -721,7 +755,10 @@ var StoreReader = (function () {
721
755
  function StoreReader(config) {
722
756
  var _this = this;
723
757
  this.knownResults = new (utilities.canUseWeakMap ? WeakMap : Map)();
724
- this.config = tslib.__assign(tslib.__assign({}, config), { addTypename: config.addTypename !== false });
758
+ this.config = utilities.compact(config, {
759
+ addTypename: config.addTypename !== false,
760
+ canonizeResults: shouldCanonizeResults(config),
761
+ });
725
762
  this.canon = config.canon || new ObjectCanon;
726
763
  this.executeSelectionSet = optimism.wrap(function (options) {
727
764
  var _a;
@@ -763,10 +800,11 @@ var StoreReader = (function () {
763
800
  this.canon = new ObjectCanon;
764
801
  };
765
802
  StoreReader.prototype.diffQueryAgainstStore = function (_a) {
766
- var store = _a.store, query = _a.query, _b = _a.rootId, rootId = _b === void 0 ? 'ROOT_QUERY' : _b, variables = _a.variables, _c = _a.returnPartialData, returnPartialData = _c === void 0 ? true : _c, _d = _a.canonizeResults, canonizeResults = _d === void 0 ? true : _d;
803
+ var store = _a.store, query = _a.query, _b = _a.rootId, rootId = _b === void 0 ? 'ROOT_QUERY' : _b, variables = _a.variables, _c = _a.returnPartialData, returnPartialData = _c === void 0 ? true : _c, _d = _a.canonizeResults, canonizeResults = _d === void 0 ? this.config.canonizeResults : _d;
767
804
  var policies = this.config.cache.policies;
768
805
  variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(utilities.getQueryDefinition(query))), variables);
769
806
  var rootRef = utilities.makeReference(rootId);
807
+ var merger = new utilities.DeepMerger;
770
808
  var execResult = this.executeSelectionSet({
771
809
  selectionSet: utilities.getMainDefinition(query).selectionSet,
772
810
  objectOrReference: rootRef,
@@ -779,17 +817,22 @@ var StoreReader = (function () {
779
817
  varString: canonicalStringify(variables),
780
818
  canonizeResults: canonizeResults,
781
819
  fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(query)),
782
- path: [],
820
+ merge: function (a, b) {
821
+ return merger.merge(a, b);
822
+ },
783
823
  },
784
824
  });
785
- var hasMissingFields = execResult.missing && execResult.missing.length > 0;
786
- if (hasMissingFields && !returnPartialData) {
787
- throw execResult.missing[0];
825
+ var missing;
826
+ if (execResult.missing) {
827
+ missing = [new MissingFieldError(firstMissing(execResult.missing), execResult.missing, query, variables)];
828
+ if (!returnPartialData) {
829
+ throw missing[0];
830
+ }
788
831
  }
789
832
  return {
790
833
  result: execResult.result,
791
- missing: execResult.missing,
792
- complete: !hasMissingFields,
834
+ complete: !missing,
835
+ missing: missing,
793
836
  };
794
837
  };
795
838
  StoreReader.prototype.isFresh = function (result, parent, selectionSet, context) {
@@ -810,30 +853,28 @@ var StoreReader = (function () {
810
853
  !context.store.has(objectOrReference.__ref)) {
811
854
  return {
812
855
  result: this.canon.empty,
813
- missing: [missingFromInvariant(__DEV__ ? new globals.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new globals.InvariantError(5), context)],
856
+ missing: "Dangling reference to missing " + objectOrReference.__ref + " object",
814
857
  };
815
858
  }
816
859
  var variables = context.variables, policies = context.policies, store = context.store;
817
- var objectsToMerge = [];
818
- var finalResult = { result: null };
819
860
  var typename = store.getFieldValue(objectOrReference, "__typename");
861
+ var result = {};
862
+ var missing;
820
863
  if (this.config.addTypename &&
821
864
  typeof typename === "string" &&
822
865
  !policies.rootIdsByTypename[typename]) {
823
- objectsToMerge.push({ __typename: typename });
866
+ result = { __typename: typename };
824
867
  }
825
- function getMissing() {
826
- return finalResult.missing || (finalResult.missing = []);
827
- }
828
- function handleMissing(result) {
868
+ function handleMissing(result, resultName) {
829
869
  var _a;
830
- if (result.missing)
831
- (_a = getMissing()).push.apply(_a, result.missing);
870
+ if (result.missing) {
871
+ missing = context.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
872
+ }
832
873
  return result.result;
833
874
  }
834
875
  var workSet = new Set(selectionSet.selections);
835
876
  workSet.forEach(function (selection) {
836
- var _a;
877
+ var _a, _b;
837
878
  if (!utilities.shouldInclude(selection, variables))
838
879
  return;
839
880
  if (utilities.isField(selection)) {
@@ -844,12 +885,13 @@ var StoreReader = (function () {
844
885
  from: objectOrReference,
845
886
  }, context);
846
887
  var resultName = utilities.resultKeyNameFromField(selection);
847
- context.path.push(resultName);
848
888
  if (fieldValue === void 0) {
849
889
  if (!utilities.addTypenameToDocument.added(selection)) {
850
- getMissing().push(missingFromInvariant(__DEV__ ? new globals.InvariantError("Can't find field '" + selection.name.value + "' on " + (utilities.isReference(objectOrReference)
851
- ? objectOrReference.__ref + " object"
852
- : "object " + JSON.stringify(objectOrReference, null, 2))) : new globals.InvariantError(6), context));
890
+ missing = context.merge(missing, (_a = {},
891
+ _a[resultName] = "Can't find field '" + selection.name.value + "' on " + (utilities.isReference(objectOrReference)
892
+ ? objectOrReference.__ref + " object"
893
+ : "object " + JSON.stringify(objectOrReference, null, 2)),
894
+ _a));
853
895
  }
854
896
  }
855
897
  else if (Array.isArray(fieldValue)) {
@@ -858,7 +900,7 @@ var StoreReader = (function () {
858
900
  array: fieldValue,
859
901
  enclosingRef: enclosingRef,
860
902
  context: context,
861
- }));
903
+ }), resultName);
862
904
  }
863
905
  else if (!selection.selectionSet) {
864
906
  if (context.canonizeResults) {
@@ -871,12 +913,11 @@ var StoreReader = (function () {
871
913
  objectOrReference: fieldValue,
872
914
  enclosingRef: utilities.isReference(fieldValue) ? fieldValue : enclosingRef,
873
915
  context: context,
874
- }));
916
+ }), resultName);
875
917
  }
876
918
  if (fieldValue !== void 0) {
877
- objectsToMerge.push((_a = {}, _a[resultName] = fieldValue, _a));
919
+ result = context.merge(result, (_b = {}, _b[resultName] = fieldValue, _b));
878
920
  }
879
- globals.invariant(context.path.pop() === resultName);
880
921
  }
881
922
  else {
882
923
  var fragment = utilities.getFragmentFromSelection(selection, context.fragmentMap);
@@ -885,23 +926,24 @@ var StoreReader = (function () {
885
926
  }
886
927
  }
887
928
  });
888
- var merged = utilities.mergeDeepArray(objectsToMerge);
889
- finalResult.result = context.canonizeResults
890
- ? this.canon.admit(merged)
891
- : utilities.maybeDeepFreeze(merged);
892
- this.knownResults.set(finalResult.result, selectionSet);
893
- return finalResult;
929
+ var finalResult = { result: result, missing: missing };
930
+ var frozen = context.canonizeResults
931
+ ? this.canon.admit(finalResult)
932
+ : utilities.maybeDeepFreeze(finalResult);
933
+ if (frozen.result) {
934
+ this.knownResults.set(frozen.result, selectionSet);
935
+ }
936
+ return frozen;
894
937
  };
895
938
  StoreReader.prototype.execSubSelectedArrayImpl = function (_a) {
896
939
  var _this = this;
897
940
  var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
898
941
  var missing;
899
942
  function handleMissing(childResult, i) {
943
+ var _a;
900
944
  if (childResult.missing) {
901
- missing = missing || [];
902
- missing.push.apply(missing, childResult.missing);
945
+ missing = context.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
903
946
  }
904
- globals.invariant(context.path.pop() === i);
905
947
  return childResult.result;
906
948
  }
907
949
  if (field.selectionSet) {
@@ -911,7 +953,6 @@ var StoreReader = (function () {
911
953
  if (item === null) {
912
954
  return null;
913
955
  }
914
- context.path.push(i);
915
956
  if (Array.isArray(item)) {
916
957
  return handleMissing(_this.executeSubSelectedArray({
917
958
  field: field,
@@ -931,7 +972,6 @@ var StoreReader = (function () {
931
972
  if (__DEV__) {
932
973
  assertSelectionSetForIdValue(context.store, field, item);
933
974
  }
934
- globals.invariant(context.path.pop() === i);
935
975
  return item;
936
976
  });
937
977
  return {
@@ -941,12 +981,24 @@ var StoreReader = (function () {
941
981
  };
942
982
  return StoreReader;
943
983
  }());
984
+ function firstMissing(tree) {
985
+ try {
986
+ JSON.stringify(tree, function (_, value) {
987
+ if (typeof value === "string")
988
+ throw value;
989
+ return value;
990
+ });
991
+ }
992
+ catch (result) {
993
+ return result;
994
+ }
995
+ }
944
996
  function assertSelectionSetForIdValue(store, field, fieldValue) {
945
997
  if (!field.selectionSet) {
946
998
  var workSet_1 = new Set([fieldValue]);
947
999
  workSet_1.forEach(function (value) {
948
1000
  if (utilities.isNonNullObject(value)) {
949
- __DEV__ ? globals.invariant(!utilities.isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : globals.invariant(!utilities.isReference(value), 7);
1001
+ __DEV__ ? globals.invariant(!utilities.isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : globals.invariant(!utilities.isReference(value), 5);
950
1002
  Object.values(value).forEach(workSet_1.add, workSet_1);
951
1003
  }
952
1004
  });
@@ -985,7 +1037,7 @@ var StoreWriter = (function () {
985
1037
  context: context,
986
1038
  });
987
1039
  if (!utilities.isReference(ref)) {
988
- throw __DEV__ ? new globals.InvariantError("Could not identify object " + JSON.stringify(result)) : new globals.InvariantError(8);
1040
+ throw __DEV__ ? new globals.InvariantError("Could not identify object " + JSON.stringify(result)) : new globals.InvariantError(6);
989
1041
  }
990
1042
  context.incomingById.forEach(function (_a, dataId) {
991
1043
  var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
@@ -1345,23 +1397,6 @@ function argsFromFieldSpecifier(spec) {
1345
1397
  return spec.args !== void 0 ? spec.args :
1346
1398
  spec.field ? utilities.argumentsObjectFromField(spec.field, spec.variables) : null;
1347
1399
  }
1348
- var defaultDataIdFromObject = function (_a, context) {
1349
- var __typename = _a.__typename, id = _a.id, _id = _a._id;
1350
- if (typeof __typename === "string") {
1351
- if (context) {
1352
- context.keyObject =
1353
- id !== void 0 ? { id: id } :
1354
- _id !== void 0 ? { _id: _id } :
1355
- void 0;
1356
- }
1357
- if (id === void 0)
1358
- id = _id;
1359
- if (id !== void 0) {
1360
- return __typename + ":" + ((typeof id === "number" ||
1361
- typeof id === "string") ? id : JSON.stringify(id));
1362
- }
1363
- }
1364
- };
1365
1400
  var nullKeyFieldsFn = function () { return void 0; };
1366
1401
  var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
1367
1402
  var mergeTrueFn = function (existing, incoming, _a) {
@@ -1879,12 +1914,6 @@ function computeKeyArgsObject(specifier, field, source, variables) {
1879
1914
  return keyObj;
1880
1915
  }
1881
1916
 
1882
- var defaultConfig = {
1883
- dataIdFromObject: defaultDataIdFromObject,
1884
- addTypename: true,
1885
- resultCaching: true,
1886
- typePolicies: {},
1887
- };
1888
1917
  var InMemoryCache = (function (_super) {
1889
1918
  tslib.__extends(InMemoryCache, _super);
1890
1919
  function InMemoryCache(config) {
@@ -1894,7 +1923,7 @@ var InMemoryCache = (function (_super) {
1894
1923
  _this.typenameDocumentCache = new Map();
1895
1924
  _this.makeVar = makeVar;
1896
1925
  _this.txCount = 0;
1897
- _this.config = tslib.__assign(tslib.__assign({}, defaultConfig), config);
1926
+ _this.config = normalizeConfig(config);
1898
1927
  _this.addTypename = !!_this.config.addTypename;
1899
1928
  _this.policies = new Policies({
1900
1929
  cache: _this,
@@ -1920,6 +1949,7 @@ var InMemoryCache = (function (_super) {
1920
1949
  cache: this,
1921
1950
  addTypename: this.addTypename,
1922
1951
  resultCacheMaxSize: this.config.resultCacheMaxSize,
1952
+ canonizeResults: shouldCanonizeResults(this.config),
1923
1953
  canon: resetResultIdentities
1924
1954
  ? void 0
1925
1955
  : previousReader && previousReader.canon,
@@ -2048,7 +2078,7 @@ var InMemoryCache = (function (_super) {
2048
2078
  }
2049
2079
  try {
2050
2080
  ++this.txCount;
2051
- return this.optimisticData.evict(options);
2081
+ return this.optimisticData.evict(options, this.data);
2052
2082
  }
2053
2083
  finally {
2054
2084
  if (!--this.txCount && options.broadcast !== false) {
@@ -2057,8 +2087,11 @@ var InMemoryCache = (function (_super) {
2057
2087
  }
2058
2088
  };
2059
2089
  InMemoryCache.prototype.reset = function () {
2090
+ var _this = this;
2060
2091
  this.init();
2061
- this.broadcastWatches();
2092
+ this.watches.forEach(function (watch) { return _this.maybeBroadcastWatch.forget(watch); });
2093
+ this.watches.clear();
2094
+ forgetCache(this);
2062
2095
  canonicalStringify.reset();
2063
2096
  return Promise.resolve();
2064
2097
  };
@@ -2072,6 +2105,7 @@ var InMemoryCache = (function (_super) {
2072
2105
  InMemoryCache.prototype.batch = function (options) {
2073
2106
  var _this = this;
2074
2107
  var update = options.update, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, removeOptimistic = options.removeOptimistic, onWatchUpdated = options.onWatchUpdated;
2108
+ var updateResult;
2075
2109
  var perform = function (layer) {
2076
2110
  var _a = _this, data = _a.data, optimisticData = _a.optimisticData;
2077
2111
  ++_this.txCount;
@@ -2079,7 +2113,7 @@ var InMemoryCache = (function (_super) {
2079
2113
  _this.data = _this.optimisticData = layer;
2080
2114
  }
2081
2115
  try {
2082
- update(_this);
2116
+ return updateResult = update(_this);
2083
2117
  }
2084
2118
  finally {
2085
2119
  --_this.txCount;
@@ -2121,6 +2155,7 @@ var InMemoryCache = (function (_super) {
2121
2155
  else {
2122
2156
  this.broadcastWatches(options);
2123
2157
  }
2158
+ return updateResult;
2124
2159
  };
2125
2160
  InMemoryCache.prototype.performTransaction = function (update, optimisticId) {
2126
2161
  return this.batch({
@@ -2148,11 +2183,7 @@ var InMemoryCache = (function (_super) {
2148
2183
  };
2149
2184
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
2150
2185
  var lastDiff = c.lastDiff;
2151
- var diff = this.diff({
2152
- query: c.query,
2153
- variables: c.variables,
2154
- optimistic: c.optimistic,
2155
- });
2186
+ var diff = this.diff(c);
2156
2187
  if (options) {
2157
2188
  if (c.optimistic &&
2158
2189
  typeof options.optimistic === "string") {