@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/apollo-client.cjs CHANGED
@@ -45,7 +45,7 @@ function shouldInclude(_a, variables) {
45
45
  var evaledValue = false;
46
46
  if (ifArgument.value.kind === 'Variable') {
47
47
  evaledValue = variables && variables[ifArgument.value.name.value];
48
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 39);
48
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 37);
49
49
  }
50
50
  else {
51
51
  evaledValue = ifArgument.value.value;
@@ -82,13 +82,13 @@ function getInclusionDirectives(directives) {
82
82
  return;
83
83
  var directiveArguments = directive.arguments;
84
84
  var directiveName = directive.name.value;
85
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 40);
85
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
86
86
  var ifArgument = directiveArguments[0];
87
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 41);
87
+ __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
88
88
  var ifValue = ifArgument.value;
89
89
  __DEV__ ? tsInvariant.invariant(ifValue &&
90
90
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.") : tsInvariant.invariant(ifValue &&
91
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 42);
91
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
92
92
  result.push({ directive: directive, ifArgument: ifArgument });
93
93
  });
94
94
  }
@@ -101,14 +101,14 @@ function getFragmentQueryDocument(document, fragmentName) {
101
101
  document.definitions.forEach(function (definition) {
102
102
  if (definition.kind === 'OperationDefinition') {
103
103
  throw __DEV__ ? new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
104
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(43);
104
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(41);
105
105
  }
106
106
  if (definition.kind === 'FragmentDefinition') {
107
107
  fragments.push(definition);
108
108
  }
109
109
  });
110
110
  if (typeof actualFragmentName === 'undefined') {
111
- __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.") : tsInvariant.invariant(fragments.length === 1, 44);
111
+ __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.") : tsInvariant.invariant(fragments.length === 1, 42);
112
112
  actualFragmentName = fragments[0].name.value;
113
113
  }
114
114
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -145,7 +145,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
145
145
  return selection;
146
146
  case 'FragmentSpread': {
147
147
  var fragment = fragmentMap && fragmentMap[selection.name.value];
148
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 45);
148
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 43);
149
149
  return fragment;
150
150
  }
151
151
  default:
@@ -229,7 +229,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
229
229
  else {
230
230
  throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
231
231
  'is not supported. Use variables instead of inline arguments to ' +
232
- 'overcome this limitation.') : new tsInvariant.InvariantError(54);
232
+ 'overcome this limitation.') : new tsInvariant.InvariantError(52);
233
233
  }
234
234
  }
235
235
  function storeKeyNameFromField(field, variables) {
@@ -363,16 +363,16 @@ function isInlineFragment(selection) {
363
363
  }
364
364
 
365
365
  function checkDocument(doc) {
366
- __DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 46);
366
+ __DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 44);
367
367
  var operations = doc.definitions
368
368
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
369
369
  .map(function (definition) {
370
370
  if (definition.kind !== 'OperationDefinition') {
371
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(47);
371
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(45);
372
372
  }
373
373
  return definition;
374
374
  });
375
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 48);
375
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 46);
376
376
  return doc;
377
377
  }
378
378
  function getOperationDefinition(doc) {
@@ -391,14 +391,14 @@ function getFragmentDefinitions(doc) {
391
391
  }
392
392
  function getQueryDefinition(doc) {
393
393
  var queryDef = getOperationDefinition(doc);
394
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 49);
394
+ __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 47);
395
395
  return queryDef;
396
396
  }
397
397
  function getFragmentDefinition(doc) {
398
- __DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 50);
399
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 51);
398
+ __DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 48);
399
+ __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 49);
400
400
  var fragmentDef = doc.definitions[0];
401
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 52);
401
+ __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 50);
402
402
  return fragmentDef;
403
403
  }
404
404
  function getMainDefinition(queryDoc) {
@@ -421,7 +421,7 @@ function getMainDefinition(queryDoc) {
421
421
  if (fragmentDefinition) {
422
422
  return fragmentDefinition;
423
423
  }
424
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(53);
424
+ throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(51);
425
425
  }
426
426
  function getDefaultValues(definition) {
427
427
  var defaultValues = Object.create(null);
@@ -760,7 +760,12 @@ var DeepMerger = (function () {
760
760
  return source;
761
761
  };
762
762
  DeepMerger.prototype.shallowCopyForMerge = function (value) {
763
- if (isNonNullObject(value) && !this.pastCopies.has(value)) {
763
+ if (isNonNullObject(value)) {
764
+ if (this.pastCopies.has(value)) {
765
+ if (!Object.isFrozen(value))
766
+ return value;
767
+ this.pastCopies.delete(value);
768
+ }
764
769
  if (Array.isArray(value)) {
765
770
  value = value.slice(0);
766
771
  }
@@ -810,9 +815,7 @@ function cloneDeepHelper(val, seen) {
810
815
  function deepFreeze(value) {
811
816
  var workSet = new Set([value]);
812
817
  workSet.forEach(function (obj) {
813
- if (isNonNullObject(obj)) {
814
- if (!Object.isFrozen(obj))
815
- Object.freeze(obj);
818
+ if (isNonNullObject(obj) && shallowFreeze(obj) === obj) {
816
819
  Object.getOwnPropertyNames(obj).forEach(function (name) {
817
820
  if (isNonNullObject(obj[name]))
818
821
  workSet.add(obj[name]);
@@ -821,6 +824,19 @@ function deepFreeze(value) {
821
824
  });
822
825
  return value;
823
826
  }
827
+ function shallowFreeze(obj) {
828
+ if (__DEV__ && !Object.isFrozen(obj)) {
829
+ try {
830
+ Object.freeze(obj);
831
+ }
832
+ catch (e) {
833
+ if (e instanceof TypeError)
834
+ return null;
835
+ throw e;
836
+ }
837
+ }
838
+ return obj;
839
+ }
824
840
  function maybeDeepFreeze(obj) {
825
841
  if (__DEV__) {
826
842
  deepFreeze(obj);
@@ -882,11 +898,17 @@ function asyncMap(observable, mapFn, catchFn) {
882
898
  });
883
899
  }
884
900
 
901
+ var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
902
+ navigator.product === 'ReactNative');
903
+ var canUseWeakSet = typeof WeakSet === 'function';
904
+ var canUseSymbol = typeof Symbol === 'function' &&
905
+ typeof Symbol.for === 'function';
906
+
885
907
  function fixObservableSubclass(subclass) {
886
908
  function set(key) {
887
909
  Object.defineProperty(subclass, key, { value: zenObservableTs.Observable });
888
910
  }
889
- if (typeof Symbol === "function" && Symbol.species) {
911
+ if (canUseSymbol && Symbol.species) {
890
912
  set(Symbol.species);
891
913
  }
892
914
  set("@@species");
@@ -1032,10 +1054,6 @@ function graphQLResultHasError(result) {
1032
1054
  return (result.errors && result.errors.length > 0) || false;
1033
1055
  }
1034
1056
 
1035
- var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
1036
- navigator.product === 'ReactNative');
1037
- var canUseWeakSet = typeof WeakSet === 'function';
1038
-
1039
1057
  function compact() {
1040
1058
  var objects = [];
1041
1059
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -1124,7 +1142,7 @@ function validateOperation(operation) {
1124
1142
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1125
1143
  var key = _a[_i];
1126
1144
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1127
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(26);
1145
+ throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(24);
1128
1146
  }
1129
1147
  }
1130
1148
  return operation;
@@ -1247,7 +1265,7 @@ var ApolloLink = (function () {
1247
1265
  return ApolloLink.concat(this, next);
1248
1266
  };
1249
1267
  ApolloLink.prototype.request = function (operation, forward) {
1250
- throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(21);
1268
+ throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(19);
1251
1269
  };
1252
1270
  ApolloLink.prototype.onError = function (error, observer) {
1253
1271
  if (observer && observer.error) {
@@ -1273,7 +1291,7 @@ var concat = ApolloLink.concat;
1273
1291
 
1274
1292
  var execute = ApolloLink.execute;
1275
1293
 
1276
- var version = '3.5.0-beta.13';
1294
+ var version = '3.5.0-beta.17';
1277
1295
 
1278
1296
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1279
1297
  function parseAndCheckHttpResponse(operations) {
@@ -1313,7 +1331,7 @@ var serializeFetchParameter = function (p, label) {
1313
1331
  serialized = JSON.stringify(p);
1314
1332
  }
1315
1333
  catch (e) {
1316
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(23);
1334
+ var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(21);
1317
1335
  parseError.parseError = e;
1318
1336
  throw parseError;
1319
1337
  }
@@ -1374,7 +1392,7 @@ function headersToLowerCase(headers) {
1374
1392
 
1375
1393
  var checkFetcher = function (fetcher) {
1376
1394
  if (!fetcher && typeof fetch === 'undefined') {
1377
- throw __DEV__ ? new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ") : new tsInvariant.InvariantError(22);
1395
+ throw __DEV__ ? new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ") : new tsInvariant.InvariantError(20);
1378
1396
  }
1379
1397
  };
1380
1398
 
@@ -1566,9 +1584,12 @@ var ApolloCache = (function () {
1566
1584
  this.getFragmentDoc = optimism.wrap(getFragmentQueryDocument);
1567
1585
  }
1568
1586
  ApolloCache.prototype.batch = function (options) {
1587
+ var _this = this;
1569
1588
  var optimisticId = typeof options.optimistic === "string" ? options.optimistic :
1570
1589
  options.optimistic === false ? null : void 0;
1571
- this.performTransaction(options.update, optimisticId);
1590
+ var updateResult;
1591
+ this.performTransaction(function () { return updateResult = options.update(_this); }, optimisticId);
1592
+ return updateResult;
1572
1593
  };
1573
1594
  ApolloCache.prototype.recordOptimisticTransaction = function (transaction, optimisticId) {
1574
1595
  this.performTransaction(transaction, optimisticId);
@@ -1612,20 +1633,28 @@ var ApolloCache = (function () {
1612
1633
  }));
1613
1634
  };
1614
1635
  ApolloCache.prototype.updateQuery = function (options, update) {
1615
- var value = this.readQuery(options);
1616
- var data = update(value);
1617
- if (data === void 0 || data === null)
1618
- return value;
1619
- this.writeQuery(tslib.__assign(tslib.__assign({}, options), { data: data }));
1620
- return data;
1636
+ return this.batch({
1637
+ update: function (cache) {
1638
+ var value = cache.readQuery(options);
1639
+ var data = update(value);
1640
+ if (data === void 0 || data === null)
1641
+ return value;
1642
+ cache.writeQuery(tslib.__assign(tslib.__assign({}, options), { data: data }));
1643
+ return data;
1644
+ },
1645
+ });
1621
1646
  };
1622
1647
  ApolloCache.prototype.updateFragment = function (options, update) {
1623
- var value = this.readFragment(options);
1624
- var data = update(value);
1625
- if (data === void 0 || data === null)
1626
- return value;
1627
- this.writeFragment(tslib.__assign(tslib.__assign({}, options), { data: data }));
1628
- return data;
1648
+ return this.batch({
1649
+ update: function (cache) {
1650
+ var value = cache.readFragment(options);
1651
+ var data = update(value);
1652
+ if (data === void 0 || data === null)
1653
+ return value;
1654
+ cache.writeFragment(tslib.__assign(tslib.__assign({}, options), { data: data }));
1655
+ return data;
1656
+ },
1657
+ });
1629
1658
  };
1630
1659
  return ApolloCache;
1631
1660
  }());
@@ -1634,21 +1663,47 @@ exports.Cache = void 0;
1634
1663
  (function (Cache) {
1635
1664
  })(exports.Cache || (exports.Cache = {}));
1636
1665
 
1637
- var MissingFieldError = (function (_super) {
1638
- tslib.__extends(MissingFieldError, _super);
1666
+ var MissingFieldError = (function () {
1639
1667
  function MissingFieldError(message, path, query, variables) {
1640
- var _this = _super.call(this, message) || this;
1641
- _this.message = message;
1642
- _this.path = path;
1643
- _this.query = query;
1644
- _this.variables = variables;
1645
- _this.__proto__ = MissingFieldError.prototype;
1646
- return _this;
1668
+ this.message = message;
1669
+ this.path = path;
1670
+ this.query = query;
1671
+ this.variables = variables;
1647
1672
  }
1648
1673
  return MissingFieldError;
1649
- }(Error));
1674
+ }());
1650
1675
 
1651
1676
  var hasOwn = Object.prototype.hasOwnProperty;
1677
+ function defaultDataIdFromObject(_a, context) {
1678
+ var __typename = _a.__typename, id = _a.id, _id = _a._id;
1679
+ if (typeof __typename === "string") {
1680
+ if (context) {
1681
+ context.keyObject =
1682
+ id !== void 0 ? { id: id } :
1683
+ _id !== void 0 ? { _id: _id } :
1684
+ void 0;
1685
+ }
1686
+ if (id === void 0)
1687
+ id = _id;
1688
+ if (id !== void 0) {
1689
+ return __typename + ":" + ((typeof id === "number" ||
1690
+ typeof id === "string") ? id : JSON.stringify(id));
1691
+ }
1692
+ }
1693
+ }
1694
+ var defaultConfig = {
1695
+ dataIdFromObject: defaultDataIdFromObject,
1696
+ addTypename: true,
1697
+ resultCaching: true,
1698
+ canonizeResults: false,
1699
+ };
1700
+ function normalizeConfig(config) {
1701
+ return compact(defaultConfig, config);
1702
+ }
1703
+ function shouldCanonizeResults(config) {
1704
+ var value = config.canonizeResults;
1705
+ return value === void 0 ? defaultConfig.canonizeResults : value;
1706
+ }
1652
1707
  function getTypenameFromStoreObject(store, objectOrReference) {
1653
1708
  return isReference(objectOrReference)
1654
1709
  ? store.get(objectOrReference.__ref, "__typename")
@@ -1877,14 +1932,14 @@ var EntityStore = (function () {
1877
1932
  }
1878
1933
  return false;
1879
1934
  };
1880
- EntityStore.prototype.evict = function (options) {
1935
+ EntityStore.prototype.evict = function (options, limit) {
1881
1936
  var evicted = false;
1882
1937
  if (options.id) {
1883
1938
  if (hasOwn.call(this.data, options.id)) {
1884
1939
  evicted = this.delete(options.id, options.fieldName, options.args);
1885
1940
  }
1886
- if (this instanceof Layer) {
1887
- evicted = this.parent.evict(options) || evicted;
1941
+ if (this instanceof Layer && this !== limit) {
1942
+ evicted = this.parent.evict(options, limit) || evicted;
1888
1943
  }
1889
1944
  if (options.fieldName || evicted) {
1890
1945
  this.group.dirty(options.id, options.fieldName || "__exists");
@@ -2257,9 +2312,6 @@ function resetCanonicalStringify() {
2257
2312
  stringifyCache = new (canUseWeakMap ? WeakMap : Map)();
2258
2313
  }
2259
2314
 
2260
- function missingFromInvariant(err, context) {
2261
- return new MissingFieldError(err.message, context.path.slice(), context.query, context.variables);
2262
- }
2263
2315
  function execSelectionSetKeyArgs(options) {
2264
2316
  return [
2265
2317
  options.selectionSet,
@@ -2272,7 +2324,10 @@ var StoreReader = (function () {
2272
2324
  function StoreReader(config) {
2273
2325
  var _this = this;
2274
2326
  this.knownResults = new (canUseWeakMap ? WeakMap : Map)();
2275
- this.config = tslib.__assign(tslib.__assign({}, config), { addTypename: config.addTypename !== false });
2327
+ this.config = compact(config, {
2328
+ addTypename: config.addTypename !== false,
2329
+ canonizeResults: shouldCanonizeResults(config),
2330
+ });
2276
2331
  this.canon = config.canon || new ObjectCanon;
2277
2332
  this.executeSelectionSet = optimism.wrap(function (options) {
2278
2333
  var _a;
@@ -2314,10 +2369,11 @@ var StoreReader = (function () {
2314
2369
  this.canon = new ObjectCanon;
2315
2370
  };
2316
2371
  StoreReader.prototype.diffQueryAgainstStore = function (_a) {
2317
- 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;
2372
+ 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;
2318
2373
  var policies = this.config.cache.policies;
2319
2374
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2320
2375
  var rootRef = makeReference(rootId);
2376
+ var merger = new DeepMerger;
2321
2377
  var execResult = this.executeSelectionSet({
2322
2378
  selectionSet: getMainDefinition(query).selectionSet,
2323
2379
  objectOrReference: rootRef,
@@ -2330,17 +2386,22 @@ var StoreReader = (function () {
2330
2386
  varString: canonicalStringify(variables),
2331
2387
  canonizeResults: canonizeResults,
2332
2388
  fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
2333
- path: [],
2389
+ merge: function (a, b) {
2390
+ return merger.merge(a, b);
2391
+ },
2334
2392
  },
2335
2393
  });
2336
- var hasMissingFields = execResult.missing && execResult.missing.length > 0;
2337
- if (hasMissingFields && !returnPartialData) {
2338
- throw execResult.missing[0];
2394
+ var missing;
2395
+ if (execResult.missing) {
2396
+ missing = [new MissingFieldError(firstMissing(execResult.missing), execResult.missing, query, variables)];
2397
+ if (!returnPartialData) {
2398
+ throw missing[0];
2399
+ }
2339
2400
  }
2340
2401
  return {
2341
2402
  result: execResult.result,
2342
- missing: execResult.missing,
2343
- complete: !hasMissingFields,
2403
+ complete: !missing,
2404
+ missing: missing,
2344
2405
  };
2345
2406
  };
2346
2407
  StoreReader.prototype.isFresh = function (result, parent, selectionSet, context) {
@@ -2361,30 +2422,28 @@ var StoreReader = (function () {
2361
2422
  !context.store.has(objectOrReference.__ref)) {
2362
2423
  return {
2363
2424
  result: this.canon.empty,
2364
- missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(5), context)],
2425
+ missing: "Dangling reference to missing " + objectOrReference.__ref + " object",
2365
2426
  };
2366
2427
  }
2367
2428
  var variables = context.variables, policies = context.policies, store = context.store;
2368
- var objectsToMerge = [];
2369
- var finalResult = { result: null };
2370
2429
  var typename = store.getFieldValue(objectOrReference, "__typename");
2430
+ var result = {};
2431
+ var missing;
2371
2432
  if (this.config.addTypename &&
2372
2433
  typeof typename === "string" &&
2373
2434
  !policies.rootIdsByTypename[typename]) {
2374
- objectsToMerge.push({ __typename: typename });
2435
+ result = { __typename: typename };
2375
2436
  }
2376
- function getMissing() {
2377
- return finalResult.missing || (finalResult.missing = []);
2378
- }
2379
- function handleMissing(result) {
2437
+ function handleMissing(result, resultName) {
2380
2438
  var _a;
2381
- if (result.missing)
2382
- (_a = getMissing()).push.apply(_a, result.missing);
2439
+ if (result.missing) {
2440
+ missing = context.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2441
+ }
2383
2442
  return result.result;
2384
2443
  }
2385
2444
  var workSet = new Set(selectionSet.selections);
2386
2445
  workSet.forEach(function (selection) {
2387
- var _a;
2446
+ var _a, _b;
2388
2447
  if (!shouldInclude(selection, variables))
2389
2448
  return;
2390
2449
  if (isField(selection)) {
@@ -2395,12 +2454,13 @@ var StoreReader = (function () {
2395
2454
  from: objectOrReference,
2396
2455
  }, context);
2397
2456
  var resultName = resultKeyNameFromField(selection);
2398
- context.path.push(resultName);
2399
2457
  if (fieldValue === void 0) {
2400
2458
  if (!addTypenameToDocument.added(selection)) {
2401
- getMissing().push(missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
2402
- ? objectOrReference.__ref + " object"
2403
- : "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(6), context));
2459
+ missing = context.merge(missing, (_a = {},
2460
+ _a[resultName] = "Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
2461
+ ? objectOrReference.__ref + " object"
2462
+ : "object " + JSON.stringify(objectOrReference, null, 2)),
2463
+ _a));
2404
2464
  }
2405
2465
  }
2406
2466
  else if (Array.isArray(fieldValue)) {
@@ -2409,7 +2469,7 @@ var StoreReader = (function () {
2409
2469
  array: fieldValue,
2410
2470
  enclosingRef: enclosingRef,
2411
2471
  context: context,
2412
- }));
2472
+ }), resultName);
2413
2473
  }
2414
2474
  else if (!selection.selectionSet) {
2415
2475
  if (context.canonizeResults) {
@@ -2422,12 +2482,11 @@ var StoreReader = (function () {
2422
2482
  objectOrReference: fieldValue,
2423
2483
  enclosingRef: isReference(fieldValue) ? fieldValue : enclosingRef,
2424
2484
  context: context,
2425
- }));
2485
+ }), resultName);
2426
2486
  }
2427
2487
  if (fieldValue !== void 0) {
2428
- objectsToMerge.push((_a = {}, _a[resultName] = fieldValue, _a));
2488
+ result = context.merge(result, (_b = {}, _b[resultName] = fieldValue, _b));
2429
2489
  }
2430
- tsInvariant.invariant(context.path.pop() === resultName);
2431
2490
  }
2432
2491
  else {
2433
2492
  var fragment = getFragmentFromSelection(selection, context.fragmentMap);
@@ -2436,23 +2495,24 @@ var StoreReader = (function () {
2436
2495
  }
2437
2496
  }
2438
2497
  });
2439
- var merged = mergeDeepArray(objectsToMerge);
2440
- finalResult.result = context.canonizeResults
2441
- ? this.canon.admit(merged)
2442
- : maybeDeepFreeze(merged);
2443
- this.knownResults.set(finalResult.result, selectionSet);
2444
- return finalResult;
2498
+ var finalResult = { result: result, missing: missing };
2499
+ var frozen = context.canonizeResults
2500
+ ? this.canon.admit(finalResult)
2501
+ : maybeDeepFreeze(finalResult);
2502
+ if (frozen.result) {
2503
+ this.knownResults.set(frozen.result, selectionSet);
2504
+ }
2505
+ return frozen;
2445
2506
  };
2446
2507
  StoreReader.prototype.execSubSelectedArrayImpl = function (_a) {
2447
2508
  var _this = this;
2448
2509
  var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
2449
2510
  var missing;
2450
2511
  function handleMissing(childResult, i) {
2512
+ var _a;
2451
2513
  if (childResult.missing) {
2452
- missing = missing || [];
2453
- missing.push.apply(missing, childResult.missing);
2514
+ missing = context.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2454
2515
  }
2455
- tsInvariant.invariant(context.path.pop() === i);
2456
2516
  return childResult.result;
2457
2517
  }
2458
2518
  if (field.selectionSet) {
@@ -2462,7 +2522,6 @@ var StoreReader = (function () {
2462
2522
  if (item === null) {
2463
2523
  return null;
2464
2524
  }
2465
- context.path.push(i);
2466
2525
  if (Array.isArray(item)) {
2467
2526
  return handleMissing(_this.executeSubSelectedArray({
2468
2527
  field: field,
@@ -2482,7 +2541,6 @@ var StoreReader = (function () {
2482
2541
  if (__DEV__) {
2483
2542
  assertSelectionSetForIdValue(context.store, field, item);
2484
2543
  }
2485
- tsInvariant.invariant(context.path.pop() === i);
2486
2544
  return item;
2487
2545
  });
2488
2546
  return {
@@ -2492,12 +2550,24 @@ var StoreReader = (function () {
2492
2550
  };
2493
2551
  return StoreReader;
2494
2552
  }());
2553
+ function firstMissing(tree) {
2554
+ try {
2555
+ JSON.stringify(tree, function (_, value) {
2556
+ if (typeof value === "string")
2557
+ throw value;
2558
+ return value;
2559
+ });
2560
+ }
2561
+ catch (result) {
2562
+ return result;
2563
+ }
2564
+ }
2495
2565
  function assertSelectionSetForIdValue(store, field, fieldValue) {
2496
2566
  if (!field.selectionSet) {
2497
2567
  var workSet_1 = new Set([fieldValue]);
2498
2568
  workSet_1.forEach(function (value) {
2499
2569
  if (isNonNullObject(value)) {
2500
- __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!isReference(value), 7);
2570
+ __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!isReference(value), 5);
2501
2571
  Object.values(value).forEach(workSet_1.add, workSet_1);
2502
2572
  }
2503
2573
  });
@@ -2536,7 +2606,7 @@ var StoreWriter = (function () {
2536
2606
  context: context,
2537
2607
  });
2538
2608
  if (!isReference(ref)) {
2539
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(8);
2609
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(6);
2540
2610
  }
2541
2611
  context.incomingById.forEach(function (_a, dataId) {
2542
2612
  var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
@@ -2896,23 +2966,6 @@ function argsFromFieldSpecifier(spec) {
2896
2966
  return spec.args !== void 0 ? spec.args :
2897
2967
  spec.field ? argumentsObjectFromField(spec.field, spec.variables) : null;
2898
2968
  }
2899
- var defaultDataIdFromObject = function (_a, context) {
2900
- var __typename = _a.__typename, id = _a.id, _id = _a._id;
2901
- if (typeof __typename === "string") {
2902
- if (context) {
2903
- context.keyObject =
2904
- id !== void 0 ? { id: id } :
2905
- _id !== void 0 ? { _id: _id } :
2906
- void 0;
2907
- }
2908
- if (id === void 0)
2909
- id = _id;
2910
- if (id !== void 0) {
2911
- return __typename + ":" + ((typeof id === "number" ||
2912
- typeof id === "string") ? id : JSON.stringify(id));
2913
- }
2914
- }
2915
- };
2916
2969
  var nullKeyFieldsFn = function () { return void 0; };
2917
2970
  var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
2918
2971
  var mergeTrueFn = function (existing, incoming, _a) {
@@ -3430,12 +3483,6 @@ function computeKeyArgsObject(specifier, field, source, variables) {
3430
3483
  return keyObj;
3431
3484
  }
3432
3485
 
3433
- var defaultConfig = {
3434
- dataIdFromObject: defaultDataIdFromObject,
3435
- addTypename: true,
3436
- resultCaching: true,
3437
- typePolicies: {},
3438
- };
3439
3486
  var InMemoryCache = (function (_super) {
3440
3487
  tslib.__extends(InMemoryCache, _super);
3441
3488
  function InMemoryCache(config) {
@@ -3445,7 +3492,7 @@ var InMemoryCache = (function (_super) {
3445
3492
  _this.typenameDocumentCache = new Map();
3446
3493
  _this.makeVar = makeVar;
3447
3494
  _this.txCount = 0;
3448
- _this.config = tslib.__assign(tslib.__assign({}, defaultConfig), config);
3495
+ _this.config = normalizeConfig(config);
3449
3496
  _this.addTypename = !!_this.config.addTypename;
3450
3497
  _this.policies = new Policies({
3451
3498
  cache: _this,
@@ -3471,6 +3518,7 @@ var InMemoryCache = (function (_super) {
3471
3518
  cache: this,
3472
3519
  addTypename: this.addTypename,
3473
3520
  resultCacheMaxSize: this.config.resultCacheMaxSize,
3521
+ canonizeResults: shouldCanonizeResults(this.config),
3474
3522
  canon: resetResultIdentities
3475
3523
  ? void 0
3476
3524
  : previousReader && previousReader.canon,
@@ -3599,7 +3647,7 @@ var InMemoryCache = (function (_super) {
3599
3647
  }
3600
3648
  try {
3601
3649
  ++this.txCount;
3602
- return this.optimisticData.evict(options);
3650
+ return this.optimisticData.evict(options, this.data);
3603
3651
  }
3604
3652
  finally {
3605
3653
  if (!--this.txCount && options.broadcast !== false) {
@@ -3608,8 +3656,11 @@ var InMemoryCache = (function (_super) {
3608
3656
  }
3609
3657
  };
3610
3658
  InMemoryCache.prototype.reset = function () {
3659
+ var _this = this;
3611
3660
  this.init();
3612
- this.broadcastWatches();
3661
+ this.watches.forEach(function (watch) { return _this.maybeBroadcastWatch.forget(watch); });
3662
+ this.watches.clear();
3663
+ forgetCache(this);
3613
3664
  canonicalStringify.reset();
3614
3665
  return Promise.resolve();
3615
3666
  };
@@ -3623,6 +3674,7 @@ var InMemoryCache = (function (_super) {
3623
3674
  InMemoryCache.prototype.batch = function (options) {
3624
3675
  var _this = this;
3625
3676
  var update = options.update, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, removeOptimistic = options.removeOptimistic, onWatchUpdated = options.onWatchUpdated;
3677
+ var updateResult;
3626
3678
  var perform = function (layer) {
3627
3679
  var _a = _this, data = _a.data, optimisticData = _a.optimisticData;
3628
3680
  ++_this.txCount;
@@ -3630,7 +3682,7 @@ var InMemoryCache = (function (_super) {
3630
3682
  _this.data = _this.optimisticData = layer;
3631
3683
  }
3632
3684
  try {
3633
- update(_this);
3685
+ return updateResult = update(_this);
3634
3686
  }
3635
3687
  finally {
3636
3688
  --_this.txCount;
@@ -3672,6 +3724,7 @@ var InMemoryCache = (function (_super) {
3672
3724
  else {
3673
3725
  this.broadcastWatches(options);
3674
3726
  }
3727
+ return updateResult;
3675
3728
  };
3676
3729
  InMemoryCache.prototype.performTransaction = function (update, optimisticId) {
3677
3730
  return this.batch({
@@ -3699,11 +3752,7 @@ var InMemoryCache = (function (_super) {
3699
3752
  };
3700
3753
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
3701
3754
  var lastDiff = c.lastDiff;
3702
- var diff = this.diff({
3703
- query: c.query,
3704
- variables: c.variables,
3705
- optimistic: c.optimistic,
3706
- });
3755
+ var diff = this.diff(c);
3707
3756
  if (options) {
3708
3757
  if (c.optimistic &&
3709
3758
  typeof options.optimistic === "string") {
@@ -4079,7 +4128,7 @@ var ObservableQuery = (function (_super) {
4079
4128
  pollingInfo.interval === pollInterval) {
4080
4129
  return;
4081
4130
  }
4082
- __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 12);
4131
+ __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 10);
4083
4132
  var info = pollingInfo || (this.pollingInfo = {});
4084
4133
  info.interval = pollInterval;
4085
4134
  var maybeFetch = function () {
@@ -4194,8 +4243,8 @@ function defaultSubscriptionObserverErrorCallback(error) {
4194
4243
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4195
4244
  }
4196
4245
  function logMissingFieldErrors(missing) {
4197
- if (__DEV__ && isNonEmptyArray(missing)) {
4198
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
4246
+ if (__DEV__ && missing) {
4247
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + JSON.stringify(missing), missing);
4199
4248
  }
4200
4249
  }
4201
4250
  function applyNextFetchPolicy(options) {
@@ -4376,7 +4425,7 @@ var LocalState = (function () {
4376
4425
  }
4377
4426
  else {
4378
4427
  fragment = fragmentMap[selection.name.value];
4379
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 11);
4428
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 9);
4380
4429
  }
4381
4430
  if (fragment && fragment.typeCondition) {
4382
4431
  typeCondition = fragment.typeCondition.name.value;
@@ -4555,14 +4604,14 @@ var QueryInfo = (function () {
4555
4604
  } : void 0;
4556
4605
  };
4557
4606
  QueryInfo.prototype.getDiffOptions = function (variables) {
4607
+ var _a;
4558
4608
  if (variables === void 0) { variables = this.variables; }
4559
- var oq = this.observableQuery;
4560
4609
  return {
4561
4610
  query: this.document,
4562
4611
  variables: variables,
4563
4612
  returnPartialData: true,
4564
4613
  optimistic: true,
4565
- canonizeResults: !oq || oq.options.canonizeResults !== false,
4614
+ canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
4566
4615
  };
4567
4616
  };
4568
4617
  QueryInfo.prototype.setDiff = function (diff) {
@@ -4762,7 +4811,7 @@ var QueryManager = (function () {
4762
4811
  this.queries.forEach(function (_info, queryId) {
4763
4812
  _this.stopQueryNoBroadcast(queryId);
4764
4813
  });
4765
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(13));
4814
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(11));
4766
4815
  };
4767
4816
  QueryManager.prototype.cancelPendingFetches = function (error) {
4768
4817
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -4775,10 +4824,10 @@ var QueryManager = (function () {
4775
4824
  return tslib.__generator(this, function (_f) {
4776
4825
  switch (_f.label) {
4777
4826
  case 0:
4778
- __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 14);
4827
+ __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4779
4828
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
4780
4829
  fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : tsInvariant.invariant(fetchPolicy === 'network-only' ||
4781
- fetchPolicy === 'no-cache', 15);
4830
+ fetchPolicy === 'no-cache', 13);
4782
4831
  mutationId = this.generateMutationId();
4783
4832
  mutation = this.transform(mutation).document;
4784
4833
  variables = this.getVariables(mutation, variables);
@@ -5063,10 +5112,10 @@ var QueryManager = (function () {
5063
5112
  var _this = this;
5064
5113
  if (queryId === void 0) { queryId = this.generateQueryId(); }
5065
5114
  __DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
5066
- 'in the query option.') : tsInvariant.invariant(options.query, 16);
5067
- __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 17);
5068
- __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 18);
5069
- __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 19);
5115
+ 'in the query option.') : tsInvariant.invariant(options.query, 14);
5116
+ __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 15);
5117
+ __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 16);
5118
+ __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 17);
5070
5119
  return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
5071
5120
  };
5072
5121
  QueryManager.prototype.generateQueryId = function () {
@@ -5088,7 +5137,7 @@ var QueryManager = (function () {
5088
5137
  queryInfo.stop();
5089
5138
  };
5090
5139
  QueryManager.prototype.clearStore = function () {
5091
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(20));
5140
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(18));
5092
5141
  this.queries.forEach(function (queryInfo) {
5093
5142
  if (queryInfo.observableQuery) {
5094
5143
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -5135,7 +5184,8 @@ var QueryManager = (function () {
5135
5184
  return;
5136
5185
  }
5137
5186
  var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
5138
- if (fetchPolicy === "standby" || !oq.hasObservers()) {
5187
+ if (fetchPolicy === "standby" ||
5188
+ (include === "active" && !oq.hasObservers())) {
5139
5189
  return;
5140
5190
  }
5141
5191
  if (include === "active" ||
@@ -5581,7 +5631,7 @@ var ApolloClient = (function () {
5581
5631
  if (!cache) {
5582
5632
  throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
5583
5633
  "in the options object. \n" +
5584
- "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
5634
+ "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(7);
5585
5635
  }
5586
5636
  this.link = link;
5587
5637
  this.cache = cache;
@@ -5677,7 +5727,7 @@ var ApolloClient = (function () {
5677
5727
  __DEV__ ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
5678
5728
  'client.query can only return a single result. Please use client.watchQuery ' +
5679
5729
  'to receive multiple results from the cache and the network, or consider ' +
5680
- 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 10);
5730
+ 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 8);
5681
5731
  if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
5682
5732
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
5683
5733
  }
@@ -5788,13 +5838,19 @@ var ApolloClient = (function () {
5788
5838
  return ApolloClient;
5789
5839
  }());
5790
5840
 
5791
- var cache$1 = new (canUseWeakMap ? WeakMap : Map)();
5841
+ var contextKey = canUseSymbol
5842
+ ? Symbol.for('__APOLLO_CONTEXT__')
5843
+ : '__APOLLO_CONTEXT__';
5792
5844
  function getApolloContext() {
5793
- var context = cache$1.get(React__namespace.createContext);
5845
+ var context = React__namespace.createContext[contextKey];
5794
5846
  if (!context) {
5795
- context = React__namespace.createContext({});
5847
+ Object.defineProperty(React__namespace.createContext, contextKey, {
5848
+ value: context = React__namespace.createContext({}),
5849
+ enumerable: false,
5850
+ writable: false,
5851
+ configurable: true,
5852
+ });
5796
5853
  context.displayName = 'ApolloContext';
5797
- cache$1.set(React__namespace.createContext, context);
5798
5854
  }
5799
5855
  return context;
5800
5856
  }
@@ -5803,7 +5859,7 @@ var ApolloConsumer = function (props) {
5803
5859
  var ApolloContext = getApolloContext();
5804
5860
  return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5805
5861
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5806
- 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 27);
5862
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 25);
5807
5863
  return props.children(context.client);
5808
5864
  });
5809
5865
  };
@@ -5817,7 +5873,7 @@ var ApolloProvider = function (_a) {
5817
5873
  context = Object.assign({}, context, { client: client });
5818
5874
  }
5819
5875
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5820
- 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 28);
5876
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 26);
5821
5877
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5822
5878
  });
5823
5879
  };
@@ -5827,7 +5883,7 @@ function useApolloClient(override) {
5827
5883
  var client = override || context.client;
5828
5884
  __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5829
5885
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient' +
5830
- 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 31);
5886
+ 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 29);
5831
5887
  return client;
5832
5888
  }
5833
5889
 
@@ -5860,7 +5916,7 @@ function parser(document) {
5860
5916
  var variables, type, name;
5861
5917
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
5862
5918
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
5863
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 32);
5919
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
5864
5920
  var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
5865
5921
  var queries = document.definitions.filter(function (x) {
5866
5922
  return x.kind === 'OperationDefinition' && x.operation === 'query';
@@ -5874,11 +5930,11 @@ function parser(document) {
5874
5930
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
5875
5931
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
5876
5932
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
5877
- (queries.length || mutations.length || subscriptions.length), 33);
5933
+ (queries.length || mutations.length || subscriptions.length), 31);
5878
5934
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
5879
5935
  (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
5880
5936
  ("subscriptions and " + mutations.length + " mutations. ") +
5881
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 34);
5937
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
5882
5938
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
5883
5939
  if (!queries.length && !mutations.length)
5884
5940
  type = exports.DocumentType.Subscription;
@@ -5889,7 +5945,7 @@ function parser(document) {
5889
5945
  : subscriptions;
5890
5946
  __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
5891
5947
  (definitions.length + " definitions. ") +
5892
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 35);
5948
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 33);
5893
5949
  var definition = definitions[0];
5894
5950
  variables = definition.variableDefinitions || [];
5895
5951
  if (definition.name && definition.name.kind === 'Name') {
@@ -5907,7 +5963,7 @@ function verifyDocumentType(document, type) {
5907
5963
  var requiredOperationName = operationName(type);
5908
5964
  var usedOperationName = operationName(operation.type);
5909
5965
  __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
5910
- (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 36);
5966
+ (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
5911
5967
  }
5912
5968
 
5913
5969
  function useQuery(query, options) {