@apollo/client 3.4.0-rc.7 → 3.4.1

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 (234) hide show
  1. package/apollo-client.cjs.js +300 -263
  2. package/apollo-client.cjs.js.map +1 -1
  3. package/apollo-client.cjs.min.js +1 -1
  4. package/cache/cache.cjs.js +105 -41
  5. package/cache/cache.cjs.js.map +1 -1
  6. package/cache/core/types/DataProxy.js +1 -0
  7. package/cache/index.d.ts +0 -1
  8. package/cache/index.d.ts.map +1 -1
  9. package/cache/index.js +3 -1
  10. package/cache/index.js.map +1 -1
  11. package/cache/inmemory/entityStore.d.ts +3 -2
  12. package/cache/inmemory/entityStore.d.ts.map +1 -1
  13. package/cache/inmemory/entityStore.js +22 -10
  14. package/cache/inmemory/entityStore.js.map +1 -1
  15. package/cache/inmemory/fixPolyfills.native.js +1 -0
  16. package/cache/inmemory/helpers.d.ts +1 -1
  17. package/cache/inmemory/helpers.d.ts.map +1 -1
  18. package/cache/inmemory/inMemoryCache.d.ts +5 -1
  19. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  20. package/cache/inmemory/inMemoryCache.js +24 -3
  21. package/cache/inmemory/inMemoryCache.js.map +1 -1
  22. package/cache/inmemory/object-canon.d.ts +3 -1
  23. package/cache/inmemory/object-canon.d.ts.map +1 -1
  24. package/cache/inmemory/object-canon.js +12 -7
  25. package/cache/inmemory/object-canon.js.map +1 -1
  26. package/cache/inmemory/policies.d.ts.map +1 -1
  27. package/cache/inmemory/policies.js +23 -10
  28. package/cache/inmemory/policies.js.map +1 -1
  29. package/cache/inmemory/readFromStore.d.ts +5 -2
  30. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  31. package/cache/inmemory/readFromStore.js +9 -6
  32. package/cache/inmemory/readFromStore.js.map +1 -1
  33. package/cache/inmemory/types.js +1 -0
  34. package/cache/inmemory/writeToStore.d.ts +1 -0
  35. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  36. package/cache/inmemory/writeToStore.js +16 -7
  37. package/cache/inmemory/writeToStore.js.map +1 -1
  38. package/core/ApolloClient.d.ts.map +1 -1
  39. package/core/ApolloClient.js +3 -0
  40. package/core/ApolloClient.js.map +1 -1
  41. package/core/LocalState.js +2 -4
  42. package/core/LocalState.js.map +1 -1
  43. package/core/ObservableQuery.d.ts +7 -6
  44. package/core/ObservableQuery.d.ts.map +1 -1
  45. package/core/ObservableQuery.js +116 -78
  46. package/core/ObservableQuery.js.map +1 -1
  47. package/core/QueryInfo.d.ts +0 -1
  48. package/core/QueryInfo.d.ts.map +1 -1
  49. package/core/QueryInfo.js +3 -6
  50. package/core/QueryInfo.js.map +1 -1
  51. package/core/QueryManager.d.ts +3 -3
  52. package/core/QueryManager.d.ts.map +1 -1
  53. package/core/QueryManager.js +13 -10
  54. package/core/QueryManager.js.map +1 -1
  55. package/core/core.cjs.js +137 -181
  56. package/core/core.cjs.js.map +1 -1
  57. package/core/index.d.ts +0 -1
  58. package/core/index.d.ts.map +1 -1
  59. package/core/index.js +2 -2
  60. package/core/index.js.map +1 -1
  61. package/core/types.d.ts +4 -1
  62. package/core/types.d.ts.map +1 -1
  63. package/core/types.js +1 -0
  64. package/core/types.js.map +1 -1
  65. package/core/watchQueryOptions.js +1 -0
  66. package/errors/errors.cjs.js +2 -0
  67. package/errors/errors.cjs.js.map +1 -1
  68. package/errors/index.d.ts.map +1 -1
  69. package/errors/index.js +3 -0
  70. package/errors/index.js.map +1 -1
  71. package/invariantErrorCodes.js +82 -57
  72. package/link/context/context.cjs.js +4 -0
  73. package/link/context/context.cjs.js.map +1 -1
  74. package/link/context/index.d.ts.map +1 -1
  75. package/link/context/index.js +4 -0
  76. package/link/context/index.js.map +1 -1
  77. package/link/core/ApolloLink.js +1 -1
  78. package/link/core/core.cjs.js +4 -2
  79. package/link/core/core.cjs.js.map +1 -1
  80. package/link/core/index.d.ts.map +1 -1
  81. package/link/core/index.js +3 -0
  82. package/link/core/index.js.map +1 -1
  83. package/link/core/types.js +1 -0
  84. package/link/http/checkFetcher.js +1 -1
  85. package/link/http/http.cjs.js +13 -3
  86. package/link/http/http.cjs.js.map +1 -1
  87. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  88. package/link/http/selectHttpOptionsAndBody.js +11 -1
  89. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  90. package/link/http/serializeFetchParameter.js +1 -1
  91. package/link/persisted-queries/index.d.ts.map +1 -1
  92. package/link/persisted-queries/index.js +2 -2
  93. package/link/persisted-queries/persisted-queries.cjs.js +2 -2
  94. package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
  95. package/link/utils/utils.cjs.js +1 -1
  96. package/link/utils/utils.cjs.js.map +1 -1
  97. package/link/utils/validateOperation.js +1 -1
  98. package/package.json +20 -20
  99. package/react/components/Mutation.d.ts +1 -1
  100. package/react/components/Query.js +1 -1
  101. package/react/components/Query.js.map +1 -1
  102. package/react/components/components.cjs.js +45 -31
  103. package/react/components/components.cjs.js.map +1 -1
  104. package/react/components/types.js +1 -0
  105. package/react/context/ApolloConsumer.js +1 -1
  106. package/react/context/ApolloProvider.js +1 -1
  107. package/react/context/context.cjs.js +22 -8
  108. package/react/context/context.cjs.js.map +1 -1
  109. package/react/data/OperationData.js +2 -2
  110. package/react/data/QueryData.d.ts +1 -2
  111. package/react/data/QueryData.d.ts.map +1 -1
  112. package/react/data/QueryData.js +65 -72
  113. package/react/data/QueryData.js.map +1 -1
  114. package/react/data/data.cjs.js +65 -71
  115. package/react/data/data.cjs.js.map +1 -1
  116. package/react/hoc/hoc-utils.d.ts +2 -1
  117. package/react/hoc/hoc-utils.d.ts.map +1 -1
  118. package/react/hoc/hoc-utils.js +1 -1
  119. package/react/hoc/hoc.cjs.js +35 -18
  120. package/react/hoc/hoc.cjs.js.map +1 -1
  121. package/react/hoc/mutation-hoc.d.ts.map +1 -1
  122. package/react/hoc/query-hoc.d.ts.map +1 -1
  123. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  124. package/react/hoc/types.js +1 -0
  125. package/react/hoc/withApollo.js +1 -1
  126. package/react/hooks/hooks.cjs.js +56 -10
  127. package/react/hooks/hooks.cjs.js.map +1 -1
  128. package/react/hooks/useApolloClient.js +1 -1
  129. package/react/hooks/useSubscription.d.ts.map +1 -1
  130. package/react/hooks/useSubscription.js +16 -6
  131. package/react/hooks/useSubscription.js.map +1 -1
  132. package/react/hooks/utils/useAfterFastRefresh.d.ts +2 -0
  133. package/react/hooks/utils/useAfterFastRefresh.d.ts.map +1 -0
  134. package/react/hooks/utils/useAfterFastRefresh.js +18 -0
  135. package/react/hooks/utils/useAfterFastRefresh.js.map +1 -0
  136. package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
  137. package/react/hooks/utils/useBaseQuery.js +10 -3
  138. package/react/hooks/utils/useBaseQuery.js.map +1 -1
  139. package/react/index.d.ts +0 -1
  140. package/react/index.d.ts.map +1 -1
  141. package/react/index.js +3 -1
  142. package/react/index.js.map +1 -1
  143. package/react/parser/index.js +4 -4
  144. package/react/parser/parser.cjs.js +4 -4
  145. package/react/parser/parser.cjs.js.map +1 -1
  146. package/react/react.cjs.js +2 -2
  147. package/react/react.cjs.js.map +1 -1
  148. package/react/ssr/ssr.cjs.js +15 -1
  149. package/react/ssr/ssr.cjs.js.map +1 -1
  150. package/react/types/types.d.ts +9 -3
  151. package/react/types/types.d.ts.map +1 -1
  152. package/react/types/types.js +1 -0
  153. package/react/types/types.js.map +1 -1
  154. package/testing/index.d.ts.map +1 -1
  155. package/testing/index.js +3 -0
  156. package/testing/index.js.map +1 -1
  157. package/testing/testing.cjs.js +68 -17
  158. package/testing/testing.cjs.js.map +1 -1
  159. package/utilities/common/canUse.d.ts +1 -0
  160. package/utilities/common/canUse.d.ts.map +1 -1
  161. package/utilities/common/canUse.js +1 -0
  162. package/utilities/common/canUse.js.map +1 -1
  163. package/utilities/common/global.d.ts.map +1 -1
  164. package/utilities/common/mergeDeep.js +2 -2
  165. package/utilities/common/mergeDeep.js.map +1 -1
  166. package/utilities/common/stringifyForDisplay.d.ts +2 -0
  167. package/utilities/common/stringifyForDisplay.d.ts.map +1 -0
  168. package/utilities/common/stringifyForDisplay.js +8 -0
  169. package/utilities/common/stringifyForDisplay.js.map +1 -0
  170. package/utilities/globals/DEV.d.ts +3 -0
  171. package/utilities/globals/DEV.d.ts.map +1 -0
  172. package/utilities/globals/DEV.js +20 -0
  173. package/utilities/globals/DEV.js.map +1 -0
  174. package/utilities/globals/graphql.d.ts +1 -1
  175. package/utilities/globals/graphql.d.ts.map +1 -1
  176. package/utilities/globals/graphql.js +3 -3
  177. package/utilities/globals/graphql.js.map +1 -1
  178. package/utilities/globals/index.d.ts +4 -2
  179. package/utilities/globals/index.d.ts.map +1 -1
  180. package/utilities/globals/index.js +5 -4
  181. package/utilities/globals/index.js.map +1 -1
  182. package/utilities/graphql/directives.js +4 -4
  183. package/utilities/graphql/fragments.js +5 -5
  184. package/utilities/graphql/getFromAST.js +8 -8
  185. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  186. package/utilities/graphql/storeUtils.js +1 -1
  187. package/utilities/graphql/transform.js +2 -2
  188. package/utilities/graphql/transform.js.map +1 -1
  189. package/utilities/index.d.ts +3 -1
  190. package/utilities/index.d.ts.map +1 -1
  191. package/utilities/index.js +5 -1
  192. package/utilities/index.js.map +1 -1
  193. package/utilities/package.json +3 -1
  194. package/utilities/policies/pagination.d.ts.map +1 -1
  195. package/utilities/policies/pagination.js +10 -11
  196. package/utilities/policies/pagination.js.map +1 -1
  197. package/utilities/testing/index.d.ts +1 -0
  198. package/utilities/testing/index.d.ts.map +1 -1
  199. package/utilities/testing/index.js +1 -0
  200. package/utilities/testing/index.js.map +1 -1
  201. package/utilities/testing/itAsync.d.ts +5 -8
  202. package/utilities/testing/itAsync.d.ts.map +1 -1
  203. package/utilities/testing/itAsync.js +6 -7
  204. package/utilities/testing/itAsync.js.map +1 -1
  205. package/utilities/testing/mocking/mockFetch.js +2 -2
  206. package/utilities/testing/mocking/mockFetch.js.map +1 -1
  207. package/utilities/testing/mocking/mockLink.d.ts.map +1 -1
  208. package/utilities/testing/mocking/mockLink.js +2 -8
  209. package/utilities/testing/mocking/mockLink.js.map +1 -1
  210. package/utilities/testing/mocking/mockWatchQuery.d.ts.map +1 -1
  211. package/utilities/testing/mocking/mockWatchQuery.js +2 -2
  212. package/utilities/testing/mocking/mockWatchQuery.js.map +1 -1
  213. package/utilities/testing/observableToPromise.js +2 -2
  214. package/utilities/testing/observableToPromise.js.map +1 -1
  215. package/utilities/testing/withConsoleSpy.d.ts +4 -0
  216. package/utilities/testing/withConsoleSpy.d.ts.map +1 -0
  217. package/utilities/testing/withConsoleSpy.js +39 -0
  218. package/utilities/testing/withConsoleSpy.js.map +1 -0
  219. package/utilities/types/IsStrictlyAny.js +1 -0
  220. package/utilities/utilities.cjs.js +56 -48
  221. package/utilities/utilities.cjs.js.map +1 -1
  222. package/version.js +1 -1
  223. package/core/Reobserver.d.ts +0 -18
  224. package/core/Reobserver.d.ts.map +0 -1
  225. package/core/Reobserver.js +0 -87
  226. package/core/Reobserver.js.map +0 -1
  227. package/utilities/globals/__DEV__.d.ts +0 -3
  228. package/utilities/globals/__DEV__.d.ts.map +0 -1
  229. package/utilities/globals/__DEV__.js +0 -32
  230. package/utilities/globals/__DEV__.js.map +0 -1
  231. package/utilities/globals/process.d.ts +0 -2
  232. package/utilities/globals/process.d.ts.map +0 -1
  233. package/utilities/globals/process.js +0 -31
  234. package/utilities/globals/process.js.map +0 -1
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var tsInvariant = require('ts-invariant');
5
6
  var utilities = require('../utilities');
6
7
  var tslib = require('tslib');
7
8
  var optimism = require('optimism');
8
- var tsInvariant = require('ts-invariant');
9
9
  var equality = require('@wry/equality');
10
10
  var trie = require('@wry/trie');
11
11
  var context = require('@wry/context');
@@ -191,6 +191,10 @@ exports.EntityStore = (function () {
191
191
  EntityStore.prototype.merge = function (older, newer) {
192
192
  var _this = this;
193
193
  var dataId;
194
+ if (utilities.isReference(older))
195
+ older = older.__ref;
196
+ if (utilities.isReference(newer))
197
+ newer = newer.__ref;
194
198
  var existing = typeof older === "string"
195
199
  ? this.lookup(dataId = older)
196
200
  : older;
@@ -199,7 +203,7 @@ exports.EntityStore = (function () {
199
203
  : newer;
200
204
  if (!incoming)
201
205
  return;
202
- __DEV__ ? tsInvariant.invariant(typeof dataId === "string", "store.merge expects a string ID") : tsInvariant.invariant(typeof dataId === "string", 1);
206
+ __DEV__ ? tsInvariant.invariant(typeof dataId === "string", "store.merge expects a string ID") : tsInvariant.invariant(typeof dataId === "string", 2);
203
207
  var merged = new utilities.DeepMerger(storeObjectReconciler).merge(existing, incoming);
204
208
  this.data[dataId] = merged;
205
209
  if (merged !== existing) {
@@ -258,8 +262,7 @@ exports.EntityStore = (function () {
258
262
  : fields[storeFieldName] || fields[fieldName];
259
263
  if (modify) {
260
264
  var newValue = modify === delModifier ? DELETE :
261
- modify(utilities.maybeDeepFreeze(fieldValue), tslib.__assign(tslib.__assign({}, sharedDetails_1), { fieldName: fieldName,
262
- storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
265
+ modify(utilities.maybeDeepFreeze(fieldValue), tslib.__assign(tslib.__assign({}, sharedDetails_1), { fieldName: fieldName, storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
263
266
  if (newValue === INVALIDATE) {
264
267
  _this.group.dirty(dataId, storeFieldName);
265
268
  }
@@ -401,15 +404,21 @@ exports.EntityStore = (function () {
401
404
  EntityStore.prototype.findChildRefIds = function (dataId) {
402
405
  if (!hasOwn.call(this.refs, dataId)) {
403
406
  var found_1 = this.refs[dataId] = Object.create(null);
404
- var workSet_1 = new Set([this.data[dataId]]);
407
+ var root = this.data[dataId];
408
+ if (!root)
409
+ return found_1;
410
+ var workSet_1 = new Set([root]);
405
411
  workSet_1.forEach(function (obj) {
406
412
  if (utilities.isReference(obj)) {
407
413
  found_1[obj.__ref] = true;
408
414
  }
409
- else if (utilities.isNonNullObject(obj)) {
410
- Object.values(obj)
411
- .filter(utilities.isNonNullObject)
412
- .forEach(workSet_1.add, workSet_1);
415
+ if (utilities.isNonNullObject(obj)) {
416
+ Object.keys(obj).forEach(function (key) {
417
+ var child = obj[key];
418
+ if (utilities.isNonNullObject(child)) {
419
+ workSet_1.add(child);
420
+ }
421
+ });
413
422
  }
414
423
  });
415
424
  }
@@ -426,9 +435,12 @@ var CacheGroup = (function () {
426
435
  this.caching = caching;
427
436
  this.parent = parent;
428
437
  this.d = null;
429
- this.keyMaker = new trie.Trie(utilities.canUseWeakMap);
430
- this.d = caching ? optimism.dep() : null;
438
+ this.resetCaching();
431
439
  }
440
+ CacheGroup.prototype.resetCaching = function () {
441
+ this.d = this.caching ? optimism.dep() : null;
442
+ this.keyMaker = new trie.Trie(utilities.canUseWeakMap);
443
+ };
432
444
  CacheGroup.prototype.depend = function (dataId, storeFieldName) {
433
445
  if (this.d) {
434
446
  this.d(makeDepKey(dataId, storeFieldName));
@@ -574,7 +586,7 @@ function shallowCopy(value) {
574
586
  }
575
587
  var ObjectCanon = (function () {
576
588
  function ObjectCanon() {
577
- this.known = new (utilities.canUseWeakMap ? WeakSet : Set)();
589
+ this.known = new (utilities.canUseWeakSet ? WeakSet : Set)();
578
590
  this.pool = new trie.Trie(utilities.canUseWeakMap);
579
591
  this.passes = new WeakMap();
580
592
  this.keysByJSON = new Map();
@@ -657,6 +669,9 @@ var ObjectCanon = (function () {
657
669
  }());
658
670
  var canonicalStringify = Object.assign(function (value) {
659
671
  if (utilities.isNonNullObject(value)) {
672
+ if (stringifyCanon === void 0) {
673
+ resetCanonicalStringify();
674
+ }
660
675
  var canonical = stringifyCanon.admit(value);
661
676
  var json = stringifyCache.get(canonical);
662
677
  if (json === void 0) {
@@ -666,12 +681,14 @@ var canonicalStringify = Object.assign(function (value) {
666
681
  }
667
682
  return JSON.stringify(value);
668
683
  }, {
669
- reset: function () {
670
- stringifyCanon = new ObjectCanon;
671
- },
684
+ reset: resetCanonicalStringify,
672
685
  });
673
- var stringifyCanon = new ObjectCanon;
674
- var stringifyCache = new WeakMap();
686
+ var stringifyCanon;
687
+ var stringifyCache;
688
+ function resetCanonicalStringify() {
689
+ stringifyCanon = new ObjectCanon;
690
+ stringifyCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
691
+ }
675
692
 
676
693
  function missingFromInvariant(err, context) {
677
694
  return new MissingFieldError(err.message, context.path.slice(), context.query, context.variables);
@@ -687,9 +704,9 @@ function execSelectionSetKeyArgs(options) {
687
704
  var StoreReader = (function () {
688
705
  function StoreReader(config) {
689
706
  var _this = this;
690
- this.canon = new ObjectCanon;
691
- this.knownResults = new WeakMap();
707
+ this.knownResults = new (utilities.canUseWeakMap ? WeakMap : Map)();
692
708
  this.config = tslib.__assign(tslib.__assign({}, config), { addTypename: config.addTypename !== false });
709
+ this.canon = config.canon || new ObjectCanon;
693
710
  this.executeSelectionSet = optimism.wrap(function (options) {
694
711
  var _a;
695
712
  var canonizeResults = options.context.canonizeResults;
@@ -726,6 +743,9 @@ var StoreReader = (function () {
726
743
  }
727
744
  });
728
745
  }
746
+ StoreReader.prototype.resetCanon = function () {
747
+ this.canon = new ObjectCanon;
748
+ };
729
749
  StoreReader.prototype.diffQueryAgainstStore = function (_a) {
730
750
  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;
731
751
  var policies = this.config.cache.policies;
@@ -774,7 +794,7 @@ var StoreReader = (function () {
774
794
  !context.store.has(objectOrReference.__ref)) {
775
795
  return {
776
796
  result: this.canon.empty,
777
- missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(5), context)],
797
+ missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(6), context)],
778
798
  };
779
799
  }
780
800
  var variables = context.variables, policies = context.policies, store = context.store;
@@ -813,7 +833,7 @@ var StoreReader = (function () {
813
833
  if (!utilities.addTypenameToDocument.added(selection)) {
814
834
  getMissing().push(missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Can't find field '" + selection.name.value + "' on " + (utilities.isReference(objectOrReference)
815
835
  ? objectOrReference.__ref + " object"
816
- : "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(6), context));
836
+ : "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(7), context));
817
837
  }
818
838
  }
819
839
  else if (Array.isArray(fieldValue)) {
@@ -910,7 +930,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
910
930
  var workSet_1 = new Set([fieldValue]);
911
931
  workSet_1.forEach(function (value) {
912
932
  if (utilities.isNonNullObject(value)) {
913
- __DEV__ ? tsInvariant.invariant(!utilities.isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!utilities.isReference(value), 7);
933
+ __DEV__ ? tsInvariant.invariant(!utilities.isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!utilities.isReference(value), 8);
914
934
  Object.values(value).forEach(workSet_1.add, workSet_1);
915
935
  }
916
936
  });
@@ -939,6 +959,7 @@ var StoreWriter = (function () {
939
959
  fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(query)),
940
960
  overwrite: !!overwrite,
941
961
  incomingById: new Map,
962
+ clientOnly: false,
942
963
  };
943
964
  var ref = this.processSelectionSet({
944
965
  result: result || Object.create(null),
@@ -948,13 +969,17 @@ var StoreWriter = (function () {
948
969
  context: context,
949
970
  });
950
971
  if (!utilities.isReference(ref)) {
951
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(8);
972
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(9);
952
973
  }
953
974
  context.incomingById.forEach(function (_a, dataId) {
954
975
  var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
955
976
  var entityRef = utilities.makeReference(dataId);
956
977
  if (mergeTree.map.size) {
957
- fields = _this.applyMerges(mergeTree, entityRef, fields, context);
978
+ var applied = _this.applyMerges(mergeTree, entityRef, fields, context);
979
+ if (utilities.isReference(applied)) {
980
+ return;
981
+ }
982
+ fields = applied;
958
983
  }
959
984
  if (__DEV__ && !context.overwrite) {
960
985
  var hasSelectionSet_1 = function (storeFieldName) {
@@ -1016,7 +1041,10 @@ var StoreWriter = (function () {
1016
1041
  if (utilities.isField(selection)) {
1017
1042
  var resultFieldKey = utilities.resultKeyNameFromField(selection);
1018
1043
  var value = result[resultFieldKey];
1019
- if (typeof value !== 'undefined') {
1044
+ var wasClientOnly = context.clientOnly;
1045
+ context.clientOnly = wasClientOnly || !!(selection.directives &&
1046
+ selection.directives.some(function (d) { return d.name.value === "client"; }));
1047
+ if (value !== void 0) {
1020
1048
  var storeFieldName = policies.getStoreFieldName({
1021
1049
  typename: typename,
1022
1050
  fieldName: selection.name.value,
@@ -1048,10 +1076,11 @@ var StoreWriter = (function () {
1048
1076
  _a[storeFieldName] = incomingValue,
1049
1077
  _a));
1050
1078
  }
1051
- else if (policies.usingPossibleTypes &&
1052
- !utilities.hasDirectives(["defer", "client"], selection)) {
1053
- throw __DEV__ ? new tsInvariant.InvariantError("Missing field '" + resultFieldKey + "' in " + JSON.stringify(result, null, 2).substring(0, 100)) : new tsInvariant.InvariantError(9);
1079
+ else if (!context.clientOnly &&
1080
+ !utilities.addTypenameToDocument.added(selection)) {
1081
+ __DEV__ && tsInvariant.invariant.error(("Missing field '" + utilities.resultKeyNameFromField(selection) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
1054
1082
  }
1083
+ context.clientOnly = wasClientOnly;
1055
1084
  }
1056
1085
  else {
1057
1086
  var fragment = utilities.getFragmentFromSelection(selection, context.fragmentMap);
@@ -1437,7 +1466,7 @@ var Policies = (function () {
1437
1466
  var rootId = "ROOT_" + which.toUpperCase();
1438
1467
  var old = this.rootTypenamesById[rootId];
1439
1468
  if (typename !== old) {
1440
- __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 2);
1469
+ __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 3);
1441
1470
  if (old)
1442
1471
  delete this.rootIdsByTypename[old];
1443
1472
  this.rootIdsByTypename[typename] = rootId;
@@ -1650,12 +1679,25 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
1650
1679
  cache: policies.cache,
1651
1680
  canRead: canRead,
1652
1681
  readField: function (fieldNameOrOptions, from) {
1653
- var options = typeof fieldNameOrOptions === "string" ? {
1654
- fieldName: fieldNameOrOptions,
1655
- from: from,
1656
- } : tslib.__assign({}, fieldNameOrOptions);
1657
- if (void 0 === options.from) {
1658
- options.from = objectOrReference;
1682
+ var options;
1683
+ if (typeof fieldNameOrOptions === "string") {
1684
+ options = {
1685
+ fieldName: fieldNameOrOptions,
1686
+ from: arguments.length > 1 ? from : objectOrReference,
1687
+ };
1688
+ }
1689
+ else if (utilities.isNonNullObject(fieldNameOrOptions)) {
1690
+ options = tslib.__assign({}, fieldNameOrOptions);
1691
+ if (!hasOwn.call(fieldNameOrOptions, "from")) {
1692
+ options.from = objectOrReference;
1693
+ }
1694
+ }
1695
+ else {
1696
+ __DEV__ && tsInvariant.invariant.warn("Unexpected readField arguments: " + utilities.stringifyForDisplay(Array.from(arguments)));
1697
+ return;
1698
+ }
1699
+ if (__DEV__ && options.from === void 0) {
1700
+ __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + utilities.stringifyForDisplay(Array.from(arguments)));
1659
1701
  }
1660
1702
  if (void 0 === options.variables) {
1661
1703
  options.variables = variables;
@@ -1668,7 +1710,7 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
1668
1710
  function makeMergeObjectsFunction(store) {
1669
1711
  return function mergeObjects(existing, incoming) {
1670
1712
  if (Array.isArray(existing) || Array.isArray(incoming)) {
1671
- throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(3);
1713
+ throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
1672
1714
  }
1673
1715
  if (utilities.isNonNullObject(existing) &&
1674
1716
  utilities.isNonNullObject(incoming)) {
@@ -1765,7 +1807,7 @@ function computeKeyObject(response, specifier, strict, aliasMap) {
1765
1807
  keyObj[prevKey = s] = response[responseName];
1766
1808
  }
1767
1809
  else {
1768
- __DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 4);
1810
+ __DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 5);
1769
1811
  prevKey = void 0;
1770
1812
  }
1771
1813
  }
@@ -1800,16 +1842,23 @@ var InMemoryCache = (function (_super) {
1800
1842
  return _this;
1801
1843
  }
1802
1844
  InMemoryCache.prototype.init = function () {
1803
- var _this = this;
1804
1845
  var rootStore = this.data = new exports.EntityStore.Root({
1805
1846
  policies: this.policies,
1806
1847
  resultCaching: this.config.resultCaching,
1807
1848
  });
1808
1849
  this.optimisticData = rootStore.stump;
1850
+ this.resetResultCache();
1851
+ };
1852
+ InMemoryCache.prototype.resetResultCache = function (resetResultIdentities) {
1853
+ var _this = this;
1854
+ var previousReader = this.storeReader;
1809
1855
  this.storeWriter = new StoreWriter(this, this.storeReader = new StoreReader({
1810
1856
  cache: this,
1811
1857
  addTypename: this.addTypename,
1812
1858
  resultCacheMaxSize: this.config.resultCacheMaxSize,
1859
+ canon: resetResultIdentities
1860
+ ? void 0
1861
+ : previousReader && previousReader.canon,
1813
1862
  }));
1814
1863
  this.maybeBroadcastWatch = optimism.wrap(function (c, options) {
1815
1864
  return _this.broadcastWatch(c, options);
@@ -1823,8 +1872,13 @@ var InMemoryCache = (function (_super) {
1823
1872
  }
1824
1873
  }
1825
1874
  });
1875
+ new Set([
1876
+ this.data.group,
1877
+ this.optimisticData.group,
1878
+ ]).forEach(function (group) { return group.resetCaching(); });
1826
1879
  };
1827
1880
  InMemoryCache.prototype.restore = function (data) {
1881
+ this.init();
1828
1882
  if (data)
1829
1883
  this.data.replace(data);
1830
1884
  return this;
@@ -1892,9 +1946,18 @@ var InMemoryCache = (function (_super) {
1892
1946
  _this.maybeBroadcastWatch.forget(watch);
1893
1947
  };
1894
1948
  };
1895
- InMemoryCache.prototype.gc = function () {
1949
+ InMemoryCache.prototype.gc = function (options) {
1896
1950
  canonicalStringify.reset();
1897
- return this.optimisticData.gc();
1951
+ var ids = this.optimisticData.gc();
1952
+ if (options && !this.txCount) {
1953
+ if (options.resetResultCache) {
1954
+ this.resetResultCache(options.resetResultIdentities);
1955
+ }
1956
+ else if (options.resetResultIdentities) {
1957
+ this.storeReader.resetCanon();
1958
+ }
1959
+ }
1960
+ return ids;
1898
1961
  };
1899
1962
  InMemoryCache.prototype.retain = function (rootId, optimistic) {
1900
1963
  return (optimistic ? this.optimisticData : this.data).retain(rootId);
@@ -2037,7 +2100,8 @@ var InMemoryCache = (function (_super) {
2037
2100
  return InMemoryCache;
2038
2101
  }(ApolloCache));
2039
2102
 
2040
- exports.__DEV__ = utilities.__DEV__;
2103
+ __DEV__ ? tsInvariant.invariant("boolean" === typeof utilities.DEV, utilities.DEV) : tsInvariant.invariant("boolean" === typeof utilities.DEV, 1);
2104
+
2041
2105
  exports.isReference = utilities.isReference;
2042
2106
  exports.makeReference = utilities.makeReference;
2043
2107
  exports.ApolloCache = ApolloCache;