@apollo/client 3.4.5 → 3.4.9

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 (132) hide show
  1. package/apollo-client.cjs.js +1010 -114
  2. package/apollo-client.cjs.js.map +1 -1
  3. package/apollo-core.cjs.js +5772 -0
  4. package/apollo-core.cjs.js.map +1 -0
  5. package/apollo-core.cjs.min.js +1 -0
  6. package/cache/cache.cjs.js +22 -19
  7. package/cache/cache.cjs.js.map +1 -1
  8. package/cache/index.d.ts.map +1 -1
  9. package/cache/index.js +2 -3
  10. package/cache/index.js.map +1 -1
  11. package/cache/inmemory/entityStore.js +1 -1
  12. package/cache/inmemory/policies.js +12 -9
  13. package/cache/inmemory/policies.js.map +1 -1
  14. package/cache/inmemory/readFromStore.js +3 -3
  15. package/cache/inmemory/writeToStore.d.ts +1 -1
  16. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  17. package/cache/inmemory/writeToStore.js +4 -4
  18. package/cache/inmemory/writeToStore.js.map +1 -1
  19. package/core/ApolloClient.js +2 -2
  20. package/core/LocalState.js +1 -1
  21. package/core/ObservableQuery.d.ts +9 -6
  22. package/core/ObservableQuery.d.ts.map +1 -1
  23. package/core/ObservableQuery.js +70 -45
  24. package/core/ObservableQuery.js.map +1 -1
  25. package/core/QueryManager.d.ts +3 -3
  26. package/core/QueryManager.d.ts.map +1 -1
  27. package/core/QueryManager.js +20 -19
  28. package/core/QueryManager.js.map +1 -1
  29. package/core/core.cjs.js +94 -66
  30. package/core/core.cjs.js.map +1 -1
  31. package/core/index.d.ts.map +1 -1
  32. package/core/index.js +2 -1
  33. package/core/index.js.map +1 -1
  34. package/core/watchQueryOptions.d.ts +2 -1
  35. package/core/watchQueryOptions.d.ts.map +1 -1
  36. package/core/watchQueryOptions.js.map +1 -1
  37. package/errors/errors.cjs.js +1 -2
  38. package/errors/errors.cjs.js.map +1 -1
  39. package/errors/index.d.ts.map +1 -1
  40. package/errors/index.js +2 -3
  41. package/errors/index.js.map +1 -1
  42. package/invariantErrorCodes.js +59 -82
  43. package/link/core/ApolloLink.js +1 -1
  44. package/link/core/core.cjs.js +3 -3
  45. package/link/core/core.cjs.js.map +1 -1
  46. package/link/core/index.d.ts.map +1 -1
  47. package/link/core/index.js +2 -3
  48. package/link/core/index.js.map +1 -1
  49. package/link/http/checkFetcher.js +1 -1
  50. package/link/http/createHttpLink.d.ts.map +1 -1
  51. package/link/http/createHttpLink.js +7 -5
  52. package/link/http/createHttpLink.js.map +1 -1
  53. package/link/http/http.cjs.js +11 -8
  54. package/link/http/http.cjs.js.map +1 -1
  55. package/link/http/index.d.ts.map +1 -1
  56. package/link/http/index.js +2 -0
  57. package/link/http/index.js.map +1 -1
  58. package/link/http/serializeFetchParameter.js +1 -1
  59. package/link/persisted-queries/index.d.ts.map +1 -1
  60. package/link/persisted-queries/index.js +4 -2
  61. package/link/persisted-queries/index.js.map +1 -1
  62. package/link/persisted-queries/persisted-queries.cjs.js +4 -3
  63. package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
  64. package/link/utils/index.d.ts.map +1 -1
  65. package/link/utils/index.js +2 -0
  66. package/link/utils/index.js.map +1 -1
  67. package/link/utils/utils.cjs.js +3 -1
  68. package/link/utils/utils.cjs.js.map +1 -1
  69. package/link/utils/validateOperation.js +1 -1
  70. package/package.json +8 -8
  71. package/react/context/ApolloConsumer.js +1 -1
  72. package/react/context/ApolloProvider.js +1 -1
  73. package/react/context/context.cjs.js +5 -3
  74. package/react/context/context.cjs.js.map +1 -1
  75. package/react/context/index.d.ts.map +1 -1
  76. package/react/context/index.js +2 -0
  77. package/react/context/index.js.map +1 -1
  78. package/react/data/OperationData.js +2 -2
  79. package/react/data/QueryData.d.ts.map +1 -1
  80. package/react/data/QueryData.js +8 -8
  81. package/react/data/QueryData.js.map +1 -1
  82. package/react/data/data.cjs.js +13 -10
  83. package/react/data/data.cjs.js.map +1 -1
  84. package/react/data/index.d.ts.map +1 -1
  85. package/react/data/index.js +2 -0
  86. package/react/data/index.js.map +1 -1
  87. package/react/hoc/hoc-utils.js +1 -1
  88. package/react/hoc/hoc.cjs.js +5 -2
  89. package/react/hoc/hoc.cjs.js.map +1 -1
  90. package/react/hoc/index.d.ts.map +1 -1
  91. package/react/hoc/index.js +2 -0
  92. package/react/hoc/index.js.map +1 -1
  93. package/react/hoc/withApollo.js +1 -1
  94. package/react/hooks/hooks.cjs.js +4 -1
  95. package/react/hooks/hooks.cjs.js.map +1 -1
  96. package/react/hooks/index.d.ts.map +1 -1
  97. package/react/hooks/index.js +2 -0
  98. package/react/hooks/index.js.map +1 -1
  99. package/react/hooks/useApolloClient.js +1 -1
  100. package/react/index.d.ts.map +1 -1
  101. package/react/index.js +2 -3
  102. package/react/index.js.map +1 -1
  103. package/react/parser/index.d.ts.map +1 -1
  104. package/react/parser/index.js +6 -4
  105. package/react/parser/index.js.map +1 -1
  106. package/react/parser/parser.cjs.js +6 -4
  107. package/react/parser/parser.cjs.js.map +1 -1
  108. package/react/react.cjs.js +1 -2
  109. package/react/react.cjs.js.map +1 -1
  110. package/testing/index.js +2 -3
  111. package/testing/index.js.map +1 -1
  112. package/testing/testing.cjs.js +3 -3
  113. package/testing/testing.cjs.js.map +1 -1
  114. package/utilities/globals/index.d.ts +1 -0
  115. package/utilities/globals/index.d.ts.map +1 -1
  116. package/utilities/globals/index.js +4 -0
  117. package/utilities/globals/index.js.map +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/index.d.ts +3 -2
  123. package/utilities/index.d.ts.map +1 -1
  124. package/utilities/index.js +4 -4
  125. package/utilities/index.js.map +1 -1
  126. package/utilities/observables/Concast.js +1 -1
  127. package/utilities/observables/Concast.js.map +1 -1
  128. package/utilities/testing/mocking/mockLink.js +1 -1
  129. package/utilities/utilities.cjs.js +23 -18
  130. package/utilities/utilities.cjs.js.map +1 -1
  131. package/version.js +1 -1
  132. package/apollo-client.cjs.min.js +0 -1
@@ -2,17 +2,32 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var tslib = require('tslib');
5
6
  var tsInvariant = require('ts-invariant');
7
+ var equality = require('@wry/equality');
6
8
  var process$1 = require('ts-invariant/process');
7
9
  var graphql = require('graphql');
8
- var tslib = require('tslib');
9
- var equality = require('@wry/equality');
10
10
  var zenObservableTs = require('zen-observable-ts');
11
11
  require('symbol-observable');
12
12
  var optimism = require('optimism');
13
13
  var context = require('@wry/context');
14
14
  var trie = require('@wry/trie');
15
15
  var graphqlTag = require('graphql-tag');
16
+ var React = require('react');
17
+
18
+ function _interopNamespace(e) {
19
+ if (e && e.__esModule) return e;
20
+ var n = Object.create(null);
21
+ if (e) {
22
+ Object.keys(e).forEach(function (k) {
23
+ n[k] = e[k];
24
+ });
25
+ }
26
+ n['default'] = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
16
31
 
17
32
  function maybe(thunk) {
18
33
  try {
@@ -50,6 +65,9 @@ function removeTemporaryGlobals() {
50
65
  return process$1.remove();
51
66
  }
52
67
 
68
+ function checkDEV() {
69
+ __DEV__ ? tsInvariant.invariant("boolean" === typeof DEV, DEV) : tsInvariant.invariant("boolean" === typeof DEV, 38);
70
+ }
53
71
  removeTemporaryGlobals();
54
72
 
55
73
  function shouldInclude(_a, variables) {
@@ -62,7 +80,7 @@ function shouldInclude(_a, variables) {
62
80
  var evaledValue = false;
63
81
  if (ifArgument.value.kind === 'Variable') {
64
82
  evaledValue = variables && variables[ifArgument.value.name.value];
65
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 43);
83
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 39);
66
84
  }
67
85
  else {
68
86
  evaledValue = ifArgument.value.value;
@@ -99,13 +117,13 @@ function getInclusionDirectives(directives) {
99
117
  return;
100
118
  var directiveArguments = directive.arguments;
101
119
  var directiveName = directive.name.value;
102
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 44);
120
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 40);
103
121
  var ifArgument = directiveArguments[0];
104
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 45);
122
+ __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 41);
105
123
  var ifValue = ifArgument.value;
106
124
  __DEV__ ? tsInvariant.invariant(ifValue &&
107
125
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.") : tsInvariant.invariant(ifValue &&
108
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 46);
126
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 42);
109
127
  result.push({ directive: directive, ifArgument: ifArgument });
110
128
  });
111
129
  }
@@ -118,14 +136,14 @@ function getFragmentQueryDocument(document, fragmentName) {
118
136
  document.definitions.forEach(function (definition) {
119
137
  if (definition.kind === 'OperationDefinition') {
120
138
  throw __DEV__ ? new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
121
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(47);
139
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(43);
122
140
  }
123
141
  if (definition.kind === 'FragmentDefinition') {
124
142
  fragments.push(definition);
125
143
  }
126
144
  });
127
145
  if (typeof actualFragmentName === 'undefined') {
128
- __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, 48);
146
+ __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);
129
147
  actualFragmentName = fragments[0].name.value;
130
148
  }
131
149
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -162,7 +180,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
162
180
  return selection;
163
181
  case 'FragmentSpread': {
164
182
  var fragment = fragmentMap && fragmentMap[selection.name.value];
165
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 49);
183
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 45);
166
184
  return fragment;
167
185
  }
168
186
  default:
@@ -246,7 +264,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
246
264
  else {
247
265
  throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
248
266
  'is not supported. Use variables instead of inline arguments to ' +
249
- 'overcome this limitation.') : new tsInvariant.InvariantError(58);
267
+ 'overcome this limitation.') : new tsInvariant.InvariantError(54);
250
268
  }
251
269
  }
252
270
  function storeKeyNameFromField(field, variables) {
@@ -380,16 +398,16 @@ function isInlineFragment(selection) {
380
398
  }
381
399
 
382
400
  function checkDocument(doc) {
383
- __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', 50);
401
+ __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);
384
402
  var operations = doc.definitions
385
403
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
386
404
  .map(function (definition) {
387
405
  if (definition.kind !== 'OperationDefinition') {
388
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(51);
406
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(47);
389
407
  }
390
408
  return definition;
391
409
  });
392
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 52);
410
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 48);
393
411
  return doc;
394
412
  }
395
413
  function getOperationDefinition(doc) {
@@ -408,14 +426,14 @@ function getFragmentDefinitions(doc) {
408
426
  }
409
427
  function getQueryDefinition(doc) {
410
428
  var queryDef = getOperationDefinition(doc);
411
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 53);
429
+ __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 49);
412
430
  return queryDef;
413
431
  }
414
432
  function getFragmentDefinition(doc) {
415
- __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', 54);
416
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 55);
433
+ __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);
434
+ __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 51);
417
435
  var fragmentDef = doc.definitions[0];
418
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 56);
436
+ __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 52);
419
437
  return fragmentDef;
420
438
  }
421
439
  function getMainDefinition(queryDoc) {
@@ -438,7 +456,7 @@ function getMainDefinition(queryDoc) {
438
456
  if (fragmentDefinition) {
439
457
  return fragmentDefinition;
440
458
  }
441
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(57);
459
+ throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(53);
442
460
  }
443
461
  function getDefaultValues(definition) {
444
462
  var defaultValues = Object.create(null);
@@ -937,7 +955,7 @@ var Concast = (function (_super) {
937
955
  var sub = _this.sub;
938
956
  if (sub !== null) {
939
957
  if (sub)
940
- Promise.resolve().then(function () { return sub.unsubscribe(); });
958
+ setTimeout(function () { return sub.unsubscribe(); });
941
959
  _this.sub = null;
942
960
  _this.latest = ["error", error];
943
961
  _this.reject(error);
@@ -1086,7 +1104,7 @@ function stringifyForDisplay(value) {
1086
1104
  }).split(JSON.stringify(undefId)).join("<undefined>");
1087
1105
  }
1088
1106
 
1089
- __DEV__ ? tsInvariant.invariant("boolean" === typeof DEV, DEV) : tsInvariant.invariant("boolean" === typeof DEV, 59);
1107
+ checkDEV();
1090
1108
 
1091
1109
  function fromError(errorValue) {
1092
1110
  return new zenObservableTs.Observable(function (observer) {
@@ -1143,7 +1161,7 @@ function validateOperation(operation) {
1143
1161
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1144
1162
  var key = _a[_i];
1145
1163
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1146
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(29);
1164
+ throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(26);
1147
1165
  }
1148
1166
  }
1149
1167
  return operation;
@@ -1266,7 +1284,7 @@ var ApolloLink = (function () {
1266
1284
  return ApolloLink.concat(this, next);
1267
1285
  };
1268
1286
  ApolloLink.prototype.request = function (operation, forward) {
1269
- throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(23);
1287
+ throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(21);
1270
1288
  };
1271
1289
  ApolloLink.prototype.onError = function (error, observer) {
1272
1290
  if (observer && observer.error) {
@@ -1292,7 +1310,7 @@ var concat = ApolloLink.concat;
1292
1310
 
1293
1311
  var execute = ApolloLink.execute;
1294
1312
 
1295
- var version = '3.4.5';
1313
+ var version = '3.4.9';
1296
1314
 
1297
1315
  var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1298
1316
  function parseAndCheckHttpResponse(operations) {
@@ -1332,7 +1350,7 @@ var serializeFetchParameter = function (p, label) {
1332
1350
  serialized = JSON.stringify(p);
1333
1351
  }
1334
1352
  catch (e) {
1335
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(26);
1353
+ var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(23);
1336
1354
  parseError.parseError = e;
1337
1355
  throw parseError;
1338
1356
  }
@@ -1392,7 +1410,7 @@ function headersToLowerCase(headers) {
1392
1410
 
1393
1411
  var checkFetcher = function (fetcher) {
1394
1412
  if (!fetcher && typeof fetch === 'undefined') {
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(25);
1413
+ 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);
1396
1414
  }
1397
1415
  };
1398
1416
 
@@ -1460,12 +1478,12 @@ function rewriteURIForGET(chosenURI, body) {
1460
1478
  return { newURI: newURI };
1461
1479
  }
1462
1480
 
1481
+ var backupFetch = maybe(function () { return fetch; });
1463
1482
  var createHttpLink = function (linkOptions) {
1464
1483
  if (linkOptions === void 0) { linkOptions = {}; }
1465
- var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, fetcher = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, _b = linkOptions.includeUnusedVariables, includeUnusedVariables = _b === void 0 ? false : _b, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries", "includeUnusedVariables"]);
1466
- checkFetcher(fetcher);
1467
- if (!fetcher) {
1468
- fetcher = fetch;
1484
+ var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, preferredFetch = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, _b = linkOptions.includeUnusedVariables, includeUnusedVariables = _b === void 0 ? false : _b, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries", "includeUnusedVariables"]);
1485
+ if (__DEV__) {
1486
+ checkFetcher(preferredFetch || backupFetch);
1469
1487
  }
1470
1488
  var linkConfig = {
1471
1489
  http: { includeExtensions: includeExtensions },
@@ -1540,7 +1558,8 @@ var createHttpLink = function (linkOptions) {
1540
1558
  }
1541
1559
  }
1542
1560
  return new zenObservableTs.Observable(function (observer) {
1543
- fetcher(chosenURI, options)
1561
+ var currentFetch = preferredFetch || maybe(function () { return fetch; }) || backupFetch;
1562
+ currentFetch(chosenURI, options)
1544
1563
  .then(function (response) {
1545
1564
  operation.setContext({ response: response });
1546
1565
  return response;
@@ -1771,7 +1790,7 @@ var EntityStore = (function () {
1771
1790
  : newer;
1772
1791
  if (!incoming)
1773
1792
  return;
1774
- __DEV__ ? tsInvariant.invariant(typeof dataId === "string", "store.merge expects a string ID") : tsInvariant.invariant(typeof dataId === "string", 2);
1793
+ __DEV__ ? tsInvariant.invariant(typeof dataId === "string", "store.merge expects a string ID") : tsInvariant.invariant(typeof dataId === "string", 1);
1775
1794
  var merged = new DeepMerger(storeObjectReconciler).merge(existing, incoming);
1776
1795
  this.data[dataId] = merged;
1777
1796
  if (merged !== existing) {
@@ -2362,7 +2381,7 @@ var StoreReader = (function () {
2362
2381
  !context.store.has(objectOrReference.__ref)) {
2363
2382
  return {
2364
2383
  result: this.canon.empty,
2365
- missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(6), context)],
2384
+ missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(5), context)],
2366
2385
  };
2367
2386
  }
2368
2387
  var variables = context.variables, policies = context.policies, store = context.store;
@@ -2401,7 +2420,7 @@ var StoreReader = (function () {
2401
2420
  if (!addTypenameToDocument.added(selection)) {
2402
2421
  getMissing().push(missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
2403
2422
  ? objectOrReference.__ref + " object"
2404
- : "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(7), context));
2423
+ : "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(6), context));
2405
2424
  }
2406
2425
  }
2407
2426
  else if (Array.isArray(fieldValue)) {
@@ -2498,7 +2517,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
2498
2517
  var workSet_1 = new Set([fieldValue]);
2499
2518
  workSet_1.forEach(function (value) {
2500
2519
  if (isNonNullObject(value)) {
2501
- __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), 8);
2520
+ __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);
2502
2521
  Object.values(value).forEach(workSet_1.add, workSet_1);
2503
2522
  }
2504
2523
  });
@@ -2537,12 +2556,12 @@ var StoreWriter = (function () {
2537
2556
  context: context,
2538
2557
  });
2539
2558
  if (!isReference(ref)) {
2540
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(9);
2559
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(8);
2541
2560
  }
2542
2561
  context.incomingById.forEach(function (_a, dataId) {
2543
2562
  var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
2544
2563
  var entityRef = makeReference(dataId);
2545
- if (mergeTree.map.size) {
2564
+ if (mergeTree && mergeTree.map.size) {
2546
2565
  var applied = _this.applyMerges(mergeTree, entityRef, fields, context);
2547
2566
  if (isReference(applied)) {
2548
2567
  return;
@@ -2560,7 +2579,7 @@ var StoreWriter = (function () {
2560
2579
  }
2561
2580
  });
2562
2581
  var hasMergeFunction_1 = function (storeFieldName) {
2563
- var childTree = mergeTree.map.get(storeFieldName);
2582
+ var childTree = mergeTree && mergeTree.map.get(storeFieldName);
2564
2583
  return Boolean(childTree && childTree.info && childTree.info.merge);
2565
2584
  };
2566
2585
  Object.keys(fields).forEach(function (storeFieldName) {
@@ -2669,7 +2688,7 @@ var StoreWriter = (function () {
2669
2688
  else {
2670
2689
  context.incomingById.set(dataId, {
2671
2690
  fields: incomingFields,
2672
- mergeTree: mergeTree,
2691
+ mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
2673
2692
  selections: selections,
2674
2693
  });
2675
2694
  }
@@ -3034,7 +3053,7 @@ var Policies = (function () {
3034
3053
  var rootId = "ROOT_" + which.toUpperCase();
3035
3054
  var old = this.rootTypenamesById[rootId];
3036
3055
  if (typename !== old) {
3037
- __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 3);
3056
+ __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 2);
3038
3057
  if (old)
3039
3058
  delete this.rootIdsByTypename[old];
3040
3059
  this.rootIdsByTypename[typename] = rootId;
@@ -3278,7 +3297,7 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
3278
3297
  function makeMergeObjectsFunction(store) {
3279
3298
  return function mergeObjects(existing, incoming) {
3280
3299
  if (Array.isArray(existing) || Array.isArray(incoming)) {
3281
- throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
3300
+ throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(3);
3282
3301
  }
3283
3302
  if (isNonNullObject(existing) &&
3284
3303
  isNonNullObject(incoming)) {
@@ -3359,24 +3378,27 @@ function makeAliasMap(selectionSet, fragmentMap) {
3359
3378
  }
3360
3379
  function computeKeyObject(response, specifier, strict, aliasMap) {
3361
3380
  var keyObj = Object.create(null);
3362
- var prevKey;
3381
+ var lastResponseKey;
3382
+ var lastActualKey;
3363
3383
  specifier.forEach(function (s) {
3364
3384
  if (Array.isArray(s)) {
3365
- if (typeof prevKey === "string") {
3385
+ if (typeof lastActualKey === "string" &&
3386
+ typeof lastResponseKey === "string") {
3366
3387
  var subsets = aliasMap && aliasMap.subsets;
3367
- var subset = subsets && subsets[prevKey];
3368
- keyObj[prevKey] = computeKeyObject(response[prevKey], s, strict, subset);
3388
+ var subset = subsets && subsets[lastActualKey];
3389
+ keyObj[lastActualKey] =
3390
+ computeKeyObject(response[lastResponseKey], s, strict, subset);
3369
3391
  }
3370
3392
  }
3371
3393
  else {
3372
3394
  var aliases = aliasMap && aliasMap.aliases;
3373
3395
  var responseName = aliases && aliases[s] || s;
3374
3396
  if (hasOwn.call(response, responseName)) {
3375
- keyObj[prevKey = s] = response[responseName];
3397
+ keyObj[lastActualKey = s] = response[lastResponseKey = responseName];
3376
3398
  }
3377
3399
  else {
3378
- __DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 5);
3379
- prevKey = void 0;
3400
+ __DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 4);
3401
+ lastResponseKey = lastActualKey = void 0;
3380
3402
  }
3381
3403
  }
3382
3404
  });
@@ -3668,7 +3690,7 @@ var InMemoryCache = (function (_super) {
3668
3690
  return InMemoryCache;
3669
3691
  }(ApolloCache));
3670
3692
 
3671
- __DEV__ ? tsInvariant.invariant("boolean" === typeof DEV, DEV) : tsInvariant.invariant("boolean" === typeof DEV, 22);
3693
+ checkDEV();
3672
3694
  function isApolloError(err) {
3673
3695
  return err.hasOwnProperty('graphQLErrors');
3674
3696
  }
@@ -3735,11 +3757,12 @@ var ObservableQuery = (function (_super) {
3735
3757
  catch (_a) { }
3736
3758
  var first = !_this.observers.size;
3737
3759
  _this.observers.add(observer);
3738
- if (_this.lastError) {
3739
- observer.error && observer.error(_this.lastError);
3760
+ var last = _this.last;
3761
+ if (last && last.error) {
3762
+ observer.error && observer.error(last.error);
3740
3763
  }
3741
- else if (_this.lastResult) {
3742
- observer.next && observer.next(_this.lastResult);
3764
+ else if (last && last.result) {
3765
+ observer.next && observer.next(last.result);
3743
3766
  }
3744
3767
  if (first) {
3745
3768
  _this.reobserve().catch(function () { });
@@ -3752,18 +3775,6 @@ var ObservableQuery = (function (_super) {
3752
3775
  }) || this;
3753
3776
  _this.observers = new Set();
3754
3777
  _this.subscriptions = new Set();
3755
- _this.observer = {
3756
- next: function (result) {
3757
- if (_this.lastError || _this.isDifferentFromLastResult(result)) {
3758
- _this.updateLastResult(result);
3759
- iterateObserversSafely(_this.observers, 'next', result);
3760
- }
3761
- },
3762
- error: function (error) {
3763
- _this.updateLastResult(tslib.__assign(tslib.__assign({}, _this.lastResult), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false }));
3764
- iterateObserversSafely(_this.observers, 'error', _this.lastError = error);
3765
- },
3766
- };
3767
3778
  _this.isTornDown = false;
3768
3779
  _this.options = options;
3769
3780
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
@@ -3802,15 +3813,20 @@ var ObservableQuery = (function (_super) {
3802
3813
  };
3803
3814
  ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
3804
3815
  if (saveAsLastResult === void 0) { saveAsLastResult = true; }
3805
- var _a = this, lastResult = _a.lastResult, _b = _a.options.fetchPolicy, fetchPolicy = _b === void 0 ? "cache-first" : _b;
3816
+ var lastResult = this.getLastResult(true);
3806
3817
  var networkStatus = this.queryInfo.networkStatus ||
3807
3818
  (lastResult && lastResult.networkStatus) ||
3808
3819
  exports.NetworkStatus.ready;
3809
3820
  var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
3810
3821
  if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {
3811
3822
  var diff = this.queryInfo.getDiff();
3812
- result.data = (diff.complete ||
3813
- this.options.returnPartialData) ? diff.result : void 0;
3823
+ if (diff.complete || this.options.returnPartialData) {
3824
+ result.data = diff.result;
3825
+ }
3826
+ if (equality.equal(result.data, {})) {
3827
+ result.data = void 0;
3828
+ }
3829
+ var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
3814
3830
  if (diff.complete) {
3815
3831
  if (result.networkStatus === exports.NetworkStatus.loading &&
3816
3832
  (fetchPolicy === 'cache-first' ||
@@ -3823,12 +3839,13 @@ var ObservableQuery = (function (_super) {
3823
3839
  else if (fetchPolicy !== "no-cache") {
3824
3840
  result.partial = true;
3825
3841
  }
3826
- if (!diff.complete &&
3842
+ if (__DEV__ &&
3843
+ !diff.complete &&
3827
3844
  !this.options.partialRefetch &&
3828
3845
  !result.loading &&
3829
3846
  !result.data &&
3830
3847
  !result.error) {
3831
- result.error = new ApolloError({ clientErrors: diff.missing });
3848
+ logMissingFieldErrors(diff.missing);
3832
3849
  }
3833
3850
  }
3834
3851
  if (saveAsLastResult) {
@@ -3837,18 +3854,24 @@ var ObservableQuery = (function (_super) {
3837
3854
  return result;
3838
3855
  };
3839
3856
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
3840
- return !equality.equal(this.lastResultSnapshot, newResult);
3857
+ return !this.last || !equality.equal(this.last.result, newResult);
3841
3858
  };
3842
- ObservableQuery.prototype.getLastResult = function () {
3843
- return this.lastResult;
3859
+ ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
3860
+ var last = this.last;
3861
+ if (last &&
3862
+ last[key] &&
3863
+ (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
3864
+ return last[key];
3865
+ }
3866
+ };
3867
+ ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
3868
+ return this.getLast("result", variablesMustMatch);
3844
3869
  };
3845
- ObservableQuery.prototype.getLastError = function () {
3846
- return this.lastError;
3870
+ ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
3871
+ return this.getLast("error", variablesMustMatch);
3847
3872
  };
3848
3873
  ObservableQuery.prototype.resetLastResults = function () {
3849
- delete this.lastResult;
3850
- delete this.lastResultSnapshot;
3851
- delete this.lastError;
3874
+ delete this.last;
3852
3875
  this.isTornDown = false;
3853
3876
  };
3854
3877
  ObservableQuery.prototype.resetQueryStoreErrors = function () {
@@ -3961,12 +3984,10 @@ var ObservableQuery = (function (_super) {
3961
3984
  }, exports.NetworkStatus.setVariables);
3962
3985
  };
3963
3986
  ObservableQuery.prototype.updateQuery = function (mapFn) {
3964
- var _a;
3965
3987
  var queryManager = this.queryManager;
3966
3988
  var result = queryManager.cache.diff({
3967
3989
  query: this.options.query,
3968
3990
  variables: this.variables,
3969
- previousResult: (_a = this.lastResult) === null || _a === void 0 ? void 0 : _a.data,
3970
3991
  returnPartialData: true,
3971
3992
  optimistic: false,
3972
3993
  }).result;
@@ -4011,7 +4032,7 @@ var ObservableQuery = (function (_super) {
4011
4032
  pollingInfo.interval === pollInterval) {
4012
4033
  return;
4013
4034
  }
4014
- __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 13);
4035
+ __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 12);
4015
4036
  var info = pollingInfo || (this.pollingInfo = {});
4016
4037
  info.interval = pollInterval;
4017
4038
  var maybeFetch = function () {
@@ -4035,18 +4056,18 @@ var ObservableQuery = (function (_super) {
4035
4056
  };
4036
4057
  poll();
4037
4058
  };
4038
- ObservableQuery.prototype.updateLastResult = function (newResult) {
4039
- var previousResult = this.lastResult;
4040
- this.lastResult = newResult;
4041
- this.lastResultSnapshot = this.queryManager.assumeImmutableResults
4042
- ? newResult
4043
- : cloneDeep(newResult);
4059
+ ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
4060
+ if (variables === void 0) { variables = this.variables; }
4061
+ this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
4062
+ ? newResult
4063
+ : cloneDeep(newResult), variables: variables });
4044
4064
  if (!isNonEmptyArray(newResult.errors)) {
4045
- delete this.lastError;
4065
+ delete this.last.error;
4046
4066
  }
4047
- return previousResult;
4067
+ return this.last;
4048
4068
  };
4049
4069
  ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
4070
+ var _this = this;
4050
4071
  this.isTornDown = false;
4051
4072
  var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
4052
4073
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
@@ -4067,18 +4088,39 @@ var ObservableQuery = (function (_super) {
4067
4088
  }
4068
4089
  }
4069
4090
  }
4091
+ var variables = options.variables && tslib.__assign({}, options.variables);
4070
4092
  var concast = this.fetch(options, newNetworkStatus);
4093
+ var observer = {
4094
+ next: function (result) {
4095
+ _this.reportResult(result, variables);
4096
+ },
4097
+ error: function (error) {
4098
+ _this.reportError(error, variables);
4099
+ },
4100
+ };
4071
4101
  if (!useDisposableConcast) {
4072
- if (this.concast) {
4102
+ if (this.concast && this.observer) {
4073
4103
  this.concast.removeObserver(this.observer, true);
4074
4104
  }
4075
4105
  this.concast = concast;
4106
+ this.observer = observer;
4076
4107
  }
4077
- concast.addObserver(this.observer);
4108
+ concast.addObserver(observer);
4078
4109
  return concast.promise;
4079
4110
  };
4080
4111
  ObservableQuery.prototype.observe = function () {
4081
- this.observer.next(this.getCurrentResult(false));
4112
+ this.reportResult(this.getCurrentResult(false), this.variables);
4113
+ };
4114
+ ObservableQuery.prototype.reportResult = function (result, variables) {
4115
+ if (this.getLastError() || this.isDifferentFromLastResult(result)) {
4116
+ this.updateLastResult(result, variables);
4117
+ iterateObserversSafely(this.observers, 'next', result);
4118
+ }
4119
+ };
4120
+ ObservableQuery.prototype.reportError = function (error, variables) {
4121
+ var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
4122
+ this.updateLastResult(errorResult, variables);
4123
+ iterateObserversSafely(this.observers, 'error', this.last.error = error);
4082
4124
  };
4083
4125
  ObservableQuery.prototype.hasObservers = function () {
4084
4126
  return this.observers.size > 0;
@@ -4086,9 +4128,10 @@ var ObservableQuery = (function (_super) {
4086
4128
  ObservableQuery.prototype.tearDownQuery = function () {
4087
4129
  if (this.isTornDown)
4088
4130
  return;
4089
- if (this.concast) {
4131
+ if (this.concast && this.observer) {
4090
4132
  this.concast.removeObserver(this.observer);
4091
4133
  delete this.concast;
4134
+ delete this.observer;
4092
4135
  }
4093
4136
  this.stopPolling();
4094
4137
  this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
@@ -4103,6 +4146,11 @@ fixObservableSubclass(ObservableQuery);
4103
4146
  function defaultSubscriptionObserverErrorCallback(error) {
4104
4147
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4105
4148
  }
4149
+ function logMissingFieldErrors(missing) {
4150
+ if (__DEV__ && isNonEmptyArray(missing)) {
4151
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
4152
+ }
4153
+ }
4106
4154
  function applyNextFetchPolicy(options) {
4107
4155
  var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
4108
4156
  if (nextFetchPolicy) {
@@ -4281,7 +4329,7 @@ var LocalState = (function () {
4281
4329
  }
4282
4330
  else {
4283
4331
  fragment = fragmentMap[selection.name.value];
4284
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 12);
4332
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 11);
4285
4333
  }
4286
4334
  if (fragment && fragment.typeCondition) {
4287
4335
  typeCondition = fragment.typeCondition.name.value;
@@ -4667,29 +4715,31 @@ var QueryManager = (function () {
4667
4715
  this.queries.forEach(function (_info, queryId) {
4668
4716
  _this.stopQueryNoBroadcast(queryId);
4669
4717
  });
4670
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(14));
4718
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(13));
4671
4719
  };
4672
4720
  QueryManager.prototype.cancelPendingFetches = function (error) {
4673
4721
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
4674
4722
  this.fetchCancelFns.clear();
4675
4723
  };
4676
4724
  QueryManager.prototype.mutate = function (_a) {
4677
- var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _b = _a.refetchQueries, refetchQueries = _b === void 0 ? [] : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _d = _a.errorPolicy, errorPolicy = _d === void 0 ? 'none' : _d, fetchPolicy = _a.fetchPolicy, keepRootFields = _a.keepRootFields, context = _a.context;
4725
+ var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _b = _a.refetchQueries, refetchQueries = _b === void 0 ? [] : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _d = _a.errorPolicy, errorPolicy = _d === void 0 ? 'none' : _d, _e = _a.fetchPolicy, fetchPolicy = _e === void 0 ? 'network-only' : _e, keepRootFields = _a.keepRootFields, context = _a.context;
4678
4726
  return tslib.__awaiter(this, void 0, void 0, function () {
4679
4727
  var mutationId, mutationStoreValue, self;
4680
- return tslib.__generator(this, function (_e) {
4681
- switch (_e.label) {
4728
+ return tslib.__generator(this, function (_f) {
4729
+ switch (_f.label) {
4682
4730
  case 0:
4683
- __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 15);
4684
- __DEV__ ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.") : tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', 16);
4731
+ __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 14);
4732
+ __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
4733
+ 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' ||
4734
+ fetchPolicy === 'no-cache', 15);
4685
4735
  mutationId = this.generateMutationId();
4686
4736
  mutation = this.transform(mutation).document;
4687
4737
  variables = this.getVariables(mutation, variables);
4688
4738
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4689
4739
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4690
4740
  case 1:
4691
- variables = (_e.sent());
4692
- _e.label = 2;
4741
+ variables = (_f.sent());
4742
+ _f.label = 2;
4693
4743
  case 2:
4694
4744
  mutationStoreValue = this.mutationStore &&
4695
4745
  (this.mutationStore[mutationId] = {
@@ -4966,10 +5016,10 @@ var QueryManager = (function () {
4966
5016
  var _this = this;
4967
5017
  if (queryId === void 0) { queryId = this.generateQueryId(); }
4968
5018
  __DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
4969
- 'in the query option.') : tsInvariant.invariant(options.query, 17);
4970
- __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 18);
4971
- __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 19);
4972
- __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 20);
5019
+ 'in the query option.') : tsInvariant.invariant(options.query, 16);
5020
+ __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 17);
5021
+ __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 18);
5022
+ __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 19);
4973
5023
  return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
4974
5024
  };
4975
5025
  QueryManager.prototype.generateQueryId = function () {
@@ -4991,7 +5041,7 @@ var QueryManager = (function () {
4991
5041
  queryInfo.stop();
4992
5042
  };
4993
5043
  QueryManager.prototype.clearStore = function () {
4994
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(21));
5044
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(20));
4995
5045
  this.queries.forEach(function (queryInfo) {
4996
5046
  if (queryInfo.observableQuery) {
4997
5047
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -5266,7 +5316,7 @@ var QueryManager = (function () {
5266
5316
  return _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
5267
5317
  };
5268
5318
  this.fetchCancelFns.set(queryId, function (reason) {
5269
- Promise.resolve().then(function () { return concast.cancel(reason); });
5319
+ setTimeout(function () { return concast.cancel(reason); });
5270
5320
  });
5271
5321
  var concast = new Concast(this.transform(normalized.query).hasClientExports
5272
5322
  ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
@@ -5359,10 +5409,9 @@ var QueryManager = (function () {
5359
5409
  if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
5360
5410
  var data = diff.result;
5361
5411
  if (__DEV__ &&
5362
- isNonEmptyArray(diff.missing) &&
5363
- !equality.equal(data, {}) &&
5364
- !returnPartialData) {
5365
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + diff.missing.map(function (m) { return m.path.join('.'); }).join(', '), diff.missing);
5412
+ !returnPartialData &&
5413
+ !equality.equal(data, {})) {
5414
+ logMissingFieldErrors(diff.missing);
5366
5415
  }
5367
5416
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
5368
5417
  if (data && _this.transform(query).hasForcedResolvers) {
@@ -5485,7 +5534,7 @@ var ApolloClient = (function () {
5485
5534
  if (!cache) {
5486
5535
  throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
5487
5536
  "in the options object. \n" +
5488
- "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(10);
5537
+ "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
5489
5538
  }
5490
5539
  this.link = link;
5491
5540
  this.cache = cache;
@@ -5581,7 +5630,7 @@ var ApolloClient = (function () {
5581
5630
  __DEV__ ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
5582
5631
  'client.query can only return a single result. Please use client.watchQuery ' +
5583
5632
  'to receive multiple results from the cache and the network, or consider ' +
5584
- 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 11);
5633
+ 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 10);
5585
5634
  if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
5586
5635
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
5587
5636
  }
@@ -5692,7 +5741,842 @@ var ApolloClient = (function () {
5692
5741
  return ApolloClient;
5693
5742
  }());
5694
5743
 
5695
- tsInvariant.setVerbosity(DEV ? "log" : "silent");
5744
+ var cache$1 = new (canUseWeakMap ? WeakMap : Map)();
5745
+ function getApolloContext() {
5746
+ var context = cache$1.get(React__namespace.createContext);
5747
+ if (!context) {
5748
+ context = React__namespace.createContext({});
5749
+ context.displayName = 'ApolloContext';
5750
+ cache$1.set(React__namespace.createContext, context);
5751
+ }
5752
+ return context;
5753
+ }
5754
+
5755
+ var ApolloConsumer = function (props) {
5756
+ var ApolloContext = getApolloContext();
5757
+ return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5758
+ __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5759
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 27);
5760
+ return props.children(context.client);
5761
+ });
5762
+ };
5763
+
5764
+ var ApolloProvider = function (_a) {
5765
+ var client = _a.client, children = _a.children;
5766
+ var ApolloContext = getApolloContext();
5767
+ return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5768
+ if (context === void 0) { context = {}; }
5769
+ if (client && context.client !== client) {
5770
+ context = Object.assign({}, context, { client: client });
5771
+ }
5772
+ __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5773
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 28);
5774
+ return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5775
+ });
5776
+ };
5777
+
5778
+ function useApolloClient() {
5779
+ var client = React__namespace.useContext(getApolloContext()).client;
5780
+ __DEV__ ? tsInvariant.invariant(client, 'No Apollo Client instance can be found. Please ensure that you ' +
5781
+ 'have called `ApolloProvider` higher up in your tree.') : tsInvariant.invariant(client, 33);
5782
+ return client;
5783
+ }
5784
+
5785
+ checkDEV();
5786
+ exports.DocumentType = void 0;
5787
+ (function (DocumentType) {
5788
+ DocumentType[DocumentType["Query"] = 0] = "Query";
5789
+ DocumentType[DocumentType["Mutation"] = 1] = "Mutation";
5790
+ DocumentType[DocumentType["Subscription"] = 2] = "Subscription";
5791
+ })(exports.DocumentType || (exports.DocumentType = {}));
5792
+ var cache = new Map();
5793
+ function operationName(type) {
5794
+ var name;
5795
+ switch (type) {
5796
+ case exports.DocumentType.Query:
5797
+ name = 'Query';
5798
+ break;
5799
+ case exports.DocumentType.Mutation:
5800
+ name = 'Mutation';
5801
+ break;
5802
+ case exports.DocumentType.Subscription:
5803
+ name = 'Subscription';
5804
+ break;
5805
+ }
5806
+ return name;
5807
+ }
5808
+ function parser(document) {
5809
+ var cached = cache.get(document);
5810
+ if (cached)
5811
+ return cached;
5812
+ var variables, type, name;
5813
+ __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
5814
+ "DocumentNode. You may need to use 'graphql-tag' or another method " +
5815
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 34);
5816
+ var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
5817
+ var queries = document.definitions.filter(function (x) {
5818
+ return x.kind === 'OperationDefinition' && x.operation === 'query';
5819
+ });
5820
+ var mutations = document.definitions.filter(function (x) {
5821
+ return x.kind === 'OperationDefinition' && x.operation === 'mutation';
5822
+ });
5823
+ var subscriptions = document.definitions.filter(function (x) {
5824
+ return x.kind === 'OperationDefinition' && x.operation === 'subscription';
5825
+ });
5826
+ __DEV__ ? tsInvariant.invariant(!fragments.length ||
5827
+ (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
5828
+ "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
5829
+ (queries.length || mutations.length || subscriptions.length), 35);
5830
+ __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
5831
+ (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
5832
+ ("subscriptions and " + mutations.length + " mutations. ") +
5833
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 36);
5834
+ type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
5835
+ if (!queries.length && !mutations.length)
5836
+ type = exports.DocumentType.Subscription;
5837
+ var definitions = queries.length
5838
+ ? queries
5839
+ : mutations.length
5840
+ ? mutations
5841
+ : subscriptions;
5842
+ __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
5843
+ (definitions.length + " definitions. ") +
5844
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 37);
5845
+ var definition = definitions[0];
5846
+ variables = definition.variableDefinitions || [];
5847
+ if (definition.name && definition.name.kind === 'Name') {
5848
+ name = definition.name.value;
5849
+ }
5850
+ else {
5851
+ name = 'data';
5852
+ }
5853
+ var payload = { name: name, type: type, variables: variables };
5854
+ cache.set(document, payload);
5855
+ return payload;
5856
+ }
5857
+
5858
+ var OperationData = (function () {
5859
+ function OperationData(options, context) {
5860
+ this.isMounted = false;
5861
+ this.previousOptions = {};
5862
+ this.context = {};
5863
+ this.options = {};
5864
+ this.options = options || {};
5865
+ this.context = context || {};
5866
+ }
5867
+ OperationData.prototype.getOptions = function () {
5868
+ return this.options;
5869
+ };
5870
+ OperationData.prototype.setOptions = function (newOptions, storePrevious) {
5871
+ if (storePrevious === void 0) { storePrevious = false; }
5872
+ if (storePrevious && !equality.equal(this.options, newOptions)) {
5873
+ this.previousOptions = this.options;
5874
+ }
5875
+ this.options = newOptions;
5876
+ };
5877
+ OperationData.prototype.unmount = function () {
5878
+ this.isMounted = false;
5879
+ };
5880
+ OperationData.prototype.refreshClient = function () {
5881
+ var client = (this.options && this.options.client) ||
5882
+ (this.context && this.context.client);
5883
+ __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5884
+ 'Wrap the root component in an <ApolloProvider>, or pass an ' +
5885
+ 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 29);
5886
+ var isNew = false;
5887
+ if (client !== this.client) {
5888
+ isNew = true;
5889
+ this.client = client;
5890
+ this.cleanup();
5891
+ }
5892
+ return {
5893
+ client: this.client,
5894
+ isNew: isNew
5895
+ };
5896
+ };
5897
+ OperationData.prototype.verifyDocumentType = function (document, type) {
5898
+ var operation = parser(document);
5899
+ var requiredOperationName = operationName(type);
5900
+ var usedOperationName = operationName(operation.type);
5901
+ __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
5902
+ (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 30);
5903
+ };
5904
+ return OperationData;
5905
+ }());
5906
+
5907
+ var SubscriptionData = (function (_super) {
5908
+ tslib.__extends(SubscriptionData, _super);
5909
+ function SubscriptionData(_a) {
5910
+ var options = _a.options, context = _a.context, setResult = _a.setResult;
5911
+ var _this = _super.call(this, options, context) || this;
5912
+ _this.currentObservable = {};
5913
+ _this.setResult = setResult;
5914
+ _this.initialize(options);
5915
+ return _this;
5916
+ }
5917
+ SubscriptionData.prototype.execute = function (result) {
5918
+ if (this.getOptions().skip === true) {
5919
+ this.cleanup();
5920
+ return {
5921
+ loading: false,
5922
+ error: undefined,
5923
+ data: undefined,
5924
+ variables: this.getOptions().variables
5925
+ };
5926
+ }
5927
+ var currentResult = result;
5928
+ if (this.refreshClient().isNew) {
5929
+ currentResult = this.getLoadingResult();
5930
+ }
5931
+ var shouldResubscribe = this.getOptions().shouldResubscribe;
5932
+ if (typeof shouldResubscribe === 'function') {
5933
+ shouldResubscribe = !!shouldResubscribe(this.getOptions());
5934
+ }
5935
+ if (shouldResubscribe !== false &&
5936
+ this.previousOptions &&
5937
+ Object.keys(this.previousOptions).length > 0 &&
5938
+ (this.previousOptions.subscription !== this.getOptions().subscription ||
5939
+ !equality.equal(this.previousOptions.variables, this.getOptions().variables) ||
5940
+ this.previousOptions.skip !== this.getOptions().skip)) {
5941
+ this.cleanup();
5942
+ currentResult = this.getLoadingResult();
5943
+ }
5944
+ this.initialize(this.getOptions());
5945
+ this.startSubscription();
5946
+ this.previousOptions = this.getOptions();
5947
+ return tslib.__assign(tslib.__assign({}, currentResult), { variables: this.getOptions().variables });
5948
+ };
5949
+ SubscriptionData.prototype.afterExecute = function () {
5950
+ this.isMounted = true;
5951
+ };
5952
+ SubscriptionData.prototype.cleanup = function () {
5953
+ this.endSubscription();
5954
+ delete this.currentObservable.query;
5955
+ };
5956
+ SubscriptionData.prototype.initialize = function (options) {
5957
+ if (this.currentObservable.query || this.getOptions().skip === true)
5958
+ return;
5959
+ this.currentObservable.query = this.refreshClient().client.subscribe({
5960
+ query: options.subscription,
5961
+ variables: options.variables,
5962
+ fetchPolicy: options.fetchPolicy,
5963
+ context: options.context,
5964
+ });
5965
+ };
5966
+ SubscriptionData.prototype.startSubscription = function () {
5967
+ if (this.currentObservable.subscription)
5968
+ return;
5969
+ this.currentObservable.subscription = this.currentObservable.query.subscribe({
5970
+ next: this.updateCurrentData.bind(this),
5971
+ error: this.updateError.bind(this),
5972
+ complete: this.completeSubscription.bind(this)
5973
+ });
5974
+ };
5975
+ SubscriptionData.prototype.getLoadingResult = function () {
5976
+ return {
5977
+ loading: true,
5978
+ error: undefined,
5979
+ data: undefined
5980
+ };
5981
+ };
5982
+ SubscriptionData.prototype.updateResult = function (result) {
5983
+ if (this.isMounted) {
5984
+ this.setResult(result);
5985
+ }
5986
+ };
5987
+ SubscriptionData.prototype.updateCurrentData = function (result) {
5988
+ var onSubscriptionData = this.getOptions().onSubscriptionData;
5989
+ this.updateResult({
5990
+ data: result.data,
5991
+ loading: false,
5992
+ error: undefined
5993
+ });
5994
+ if (onSubscriptionData) {
5995
+ onSubscriptionData({
5996
+ client: this.refreshClient().client,
5997
+ subscriptionData: result
5998
+ });
5999
+ }
6000
+ };
6001
+ SubscriptionData.prototype.updateError = function (error) {
6002
+ this.updateResult({
6003
+ error: error,
6004
+ loading: false
6005
+ });
6006
+ };
6007
+ SubscriptionData.prototype.completeSubscription = function () {
6008
+ var _this = this;
6009
+ Promise.resolve().then(function () {
6010
+ var onSubscriptionComplete = _this.getOptions().onSubscriptionComplete;
6011
+ if (onSubscriptionComplete)
6012
+ onSubscriptionComplete();
6013
+ _this.endSubscription();
6014
+ });
6015
+ };
6016
+ SubscriptionData.prototype.endSubscription = function () {
6017
+ if (this.currentObservable.subscription) {
6018
+ this.currentObservable.subscription.unsubscribe();
6019
+ delete this.currentObservable.subscription;
6020
+ }
6021
+ };
6022
+ return SubscriptionData;
6023
+ }(OperationData));
6024
+
6025
+ var MutationData = (function (_super) {
6026
+ tslib.__extends(MutationData, _super);
6027
+ function MutationData(_a) {
6028
+ var options = _a.options, context = _a.context, result = _a.result, setResult = _a.setResult;
6029
+ var _this = _super.call(this, options, context) || this;
6030
+ _this.runMutation = function (mutationFunctionOptions) {
6031
+ if (mutationFunctionOptions === void 0) { mutationFunctionOptions = {}; }
6032
+ _this.onMutationStart();
6033
+ var mutationId = _this.generateNewMutationId();
6034
+ return _this.mutate(mutationFunctionOptions)
6035
+ .then(function (response) {
6036
+ _this.onMutationCompleted(response, mutationId);
6037
+ return response;
6038
+ })
6039
+ .catch(function (error) {
6040
+ var onError = _this.getOptions().onError;
6041
+ _this.onMutationError(error, mutationId);
6042
+ if (onError) {
6043
+ onError(error);
6044
+ return {
6045
+ data: undefined,
6046
+ errors: error,
6047
+ };
6048
+ }
6049
+ else {
6050
+ throw error;
6051
+ }
6052
+ });
6053
+ };
6054
+ _this.verifyDocumentType(options.mutation, exports.DocumentType.Mutation);
6055
+ _this.result = result;
6056
+ _this.setResult = setResult;
6057
+ _this.mostRecentMutationId = 0;
6058
+ return _this;
6059
+ }
6060
+ MutationData.prototype.execute = function (result) {
6061
+ this.isMounted = true;
6062
+ this.verifyDocumentType(this.getOptions().mutation, exports.DocumentType.Mutation);
6063
+ return [
6064
+ this.runMutation,
6065
+ tslib.__assign(tslib.__assign({}, result), { client: this.refreshClient().client })
6066
+ ];
6067
+ };
6068
+ MutationData.prototype.afterExecute = function () {
6069
+ this.isMounted = true;
6070
+ return this.unmount.bind(this);
6071
+ };
6072
+ MutationData.prototype.cleanup = function () {
6073
+ };
6074
+ MutationData.prototype.mutate = function (options) {
6075
+ return this.refreshClient().client.mutate(mergeOptions(this.getOptions(), options));
6076
+ };
6077
+ MutationData.prototype.onMutationStart = function () {
6078
+ if (!this.result.loading && !this.getOptions().ignoreResults) {
6079
+ this.updateResult({
6080
+ loading: true,
6081
+ error: undefined,
6082
+ data: undefined,
6083
+ called: true
6084
+ });
6085
+ }
6086
+ };
6087
+ MutationData.prototype.onMutationCompleted = function (response, mutationId) {
6088
+ var _a = this.getOptions(), onCompleted = _a.onCompleted, ignoreResults = _a.ignoreResults;
6089
+ var data = response.data, errors = response.errors;
6090
+ var error = errors && errors.length > 0
6091
+ ? new ApolloError({ graphQLErrors: errors })
6092
+ : undefined;
6093
+ var callOncomplete = function () {
6094
+ return onCompleted ? onCompleted(data) : null;
6095
+ };
6096
+ if (this.isMostRecentMutation(mutationId) && !ignoreResults) {
6097
+ this.updateResult({
6098
+ called: true,
6099
+ loading: false,
6100
+ data: data,
6101
+ error: error
6102
+ });
6103
+ }
6104
+ callOncomplete();
6105
+ };
6106
+ MutationData.prototype.onMutationError = function (error, mutationId) {
6107
+ if (this.isMostRecentMutation(mutationId)) {
6108
+ this.updateResult({
6109
+ loading: false,
6110
+ error: error,
6111
+ data: undefined,
6112
+ called: true
6113
+ });
6114
+ }
6115
+ };
6116
+ MutationData.prototype.generateNewMutationId = function () {
6117
+ return ++this.mostRecentMutationId;
6118
+ };
6119
+ MutationData.prototype.isMostRecentMutation = function (mutationId) {
6120
+ return this.mostRecentMutationId === mutationId;
6121
+ };
6122
+ MutationData.prototype.updateResult = function (result) {
6123
+ if (this.isMounted &&
6124
+ (!this.previousResult || !equality.equal(this.previousResult, result))) {
6125
+ this.setResult(result);
6126
+ this.previousResult = result;
6127
+ return result;
6128
+ }
6129
+ };
6130
+ return MutationData;
6131
+ }(OperationData));
6132
+
6133
+ var QueryData = (function (_super) {
6134
+ tslib.__extends(QueryData, _super);
6135
+ function QueryData(_a) {
6136
+ var options = _a.options, context = _a.context, onNewData = _a.onNewData;
6137
+ var _this = _super.call(this, options, context) || this;
6138
+ _this.runLazy = false;
6139
+ _this.previous = Object.create(null);
6140
+ _this.runLazyQuery = function (options) {
6141
+ _this.cleanup();
6142
+ _this.runLazy = true;
6143
+ _this.lazyOptions = options;
6144
+ _this.onNewData();
6145
+ };
6146
+ _this.obsRefetch = function (variables) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.refetch(variables); };
6147
+ _this.obsFetchMore = function (fetchMoreOptions) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.fetchMore(fetchMoreOptions); };
6148
+ _this.obsUpdateQuery = function (mapFn) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.updateQuery(mapFn); };
6149
+ _this.obsStartPolling = function (pollInterval) {
6150
+ var _a;
6151
+ (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.startPolling(pollInterval);
6152
+ };
6153
+ _this.obsStopPolling = function () {
6154
+ var _a;
6155
+ (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.stopPolling();
6156
+ };
6157
+ _this.obsSubscribeToMore = function (options) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.subscribeToMore(options); };
6158
+ _this.onNewData = onNewData;
6159
+ return _this;
6160
+ }
6161
+ QueryData.prototype.execute = function () {
6162
+ this.refreshClient();
6163
+ var _a = this.getOptions(), skip = _a.skip, query = _a.query;
6164
+ if (skip || query !== this.previous.query) {
6165
+ this.removeQuerySubscription();
6166
+ this.removeObservable(!skip);
6167
+ this.previous.query = query;
6168
+ }
6169
+ this.updateObservableQuery();
6170
+ return this.getExecuteSsrResult() || this.getExecuteResult();
6171
+ };
6172
+ QueryData.prototype.executeLazy = function () {
6173
+ return !this.runLazy
6174
+ ? [
6175
+ this.runLazyQuery,
6176
+ {
6177
+ loading: false,
6178
+ networkStatus: exports.NetworkStatus.ready,
6179
+ called: false,
6180
+ data: undefined
6181
+ }
6182
+ ]
6183
+ : [this.runLazyQuery, this.execute()];
6184
+ };
6185
+ QueryData.prototype.fetchData = function () {
6186
+ var _this = this;
6187
+ var options = this.getOptions();
6188
+ if (options.skip || options.ssr === false)
6189
+ return false;
6190
+ return new Promise(function (resolve) { return _this.startQuerySubscription(resolve); });
6191
+ };
6192
+ QueryData.prototype.afterExecute = function (_a) {
6193
+ var _b = _a === void 0 ? {} : _a, _c = _b.lazy, lazy = _c === void 0 ? false : _c;
6194
+ this.isMounted = true;
6195
+ var options = this.getOptions();
6196
+ if (this.currentObservable &&
6197
+ !this.ssrInitiated() &&
6198
+ !this.client.disableNetworkFetches) {
6199
+ this.startQuerySubscription();
6200
+ }
6201
+ if (!lazy || this.runLazy) {
6202
+ this.handleErrorOrCompleted();
6203
+ }
6204
+ this.previousOptions = options;
6205
+ return this.unmount.bind(this);
6206
+ };
6207
+ QueryData.prototype.cleanup = function () {
6208
+ this.removeQuerySubscription();
6209
+ this.removeObservable(true);
6210
+ delete this.previous.result;
6211
+ };
6212
+ QueryData.prototype.getOptions = function () {
6213
+ var options = _super.prototype.getOptions.call(this);
6214
+ if (this.lazyOptions) {
6215
+ options.variables = tslib.__assign(tslib.__assign({}, options.variables), this.lazyOptions.variables);
6216
+ options.context = tslib.__assign(tslib.__assign({}, options.context), this.lazyOptions.context);
6217
+ }
6218
+ if (this.runLazy) {
6219
+ delete options.skip;
6220
+ }
6221
+ return options;
6222
+ };
6223
+ QueryData.prototype.ssrInitiated = function () {
6224
+ return this.context && this.context.renderPromises;
6225
+ };
6226
+ QueryData.prototype.getExecuteSsrResult = function () {
6227
+ var _a = this.getOptions(), ssr = _a.ssr, skip = _a.skip;
6228
+ var ssrDisabled = ssr === false;
6229
+ var fetchDisabled = this.refreshClient().client.disableNetworkFetches;
6230
+ var ssrLoading = tslib.__assign({ loading: true, networkStatus: exports.NetworkStatus.loading, called: true, data: undefined, stale: false, client: this.client }, this.observableQueryFields());
6231
+ if (ssrDisabled && (this.ssrInitiated() || fetchDisabled)) {
6232
+ this.previous.result = ssrLoading;
6233
+ return ssrLoading;
6234
+ }
6235
+ if (this.ssrInitiated()) {
6236
+ var result = this.getExecuteResult() || ssrLoading;
6237
+ if (result.loading && !skip) {
6238
+ this.context.renderPromises.addQueryPromise(this, function () { return null; });
6239
+ }
6240
+ return result;
6241
+ }
6242
+ };
6243
+ QueryData.prototype.prepareObservableQueryOptions = function () {
6244
+ var options = this.getOptions();
6245
+ this.verifyDocumentType(options.query, exports.DocumentType.Query);
6246
+ var displayName = options.displayName || 'Query';
6247
+ if (this.ssrInitiated() &&
6248
+ (options.fetchPolicy === 'network-only' ||
6249
+ options.fetchPolicy === 'cache-and-network')) {
6250
+ options.fetchPolicy = 'cache-first';
6251
+ }
6252
+ return tslib.__assign(tslib.__assign({}, options), { displayName: displayName, context: options.context });
6253
+ };
6254
+ QueryData.prototype.initializeObservableQuery = function () {
6255
+ if (this.ssrInitiated()) {
6256
+ this.currentObservable = this.context.renderPromises.getSSRObservable(this.getOptions());
6257
+ }
6258
+ if (!this.currentObservable) {
6259
+ var observableQueryOptions = this.prepareObservableQueryOptions();
6260
+ this.previous.observableQueryOptions = tslib.__assign(tslib.__assign({}, observableQueryOptions), { children: void 0 });
6261
+ this.currentObservable = this.refreshClient().client.watchQuery(tslib.__assign({}, observableQueryOptions));
6262
+ if (this.ssrInitiated()) {
6263
+ this.context.renderPromises.registerSSRObservable(this.currentObservable, observableQueryOptions);
6264
+ }
6265
+ }
6266
+ };
6267
+ QueryData.prototype.updateObservableQuery = function () {
6268
+ if (!this.currentObservable) {
6269
+ this.initializeObservableQuery();
6270
+ return;
6271
+ }
6272
+ var newObservableQueryOptions = tslib.__assign(tslib.__assign({}, this.prepareObservableQueryOptions()), { children: void 0 });
6273
+ if (this.getOptions().skip) {
6274
+ this.previous.observableQueryOptions = newObservableQueryOptions;
6275
+ return;
6276
+ }
6277
+ if (!equality.equal(newObservableQueryOptions, this.previous.observableQueryOptions)) {
6278
+ this.previous.observableQueryOptions = newObservableQueryOptions;
6279
+ this.currentObservable
6280
+ .setOptions(newObservableQueryOptions)
6281
+ .catch(function () { });
6282
+ }
6283
+ };
6284
+ QueryData.prototype.startQuerySubscription = function (onNewData) {
6285
+ var _this = this;
6286
+ if (onNewData === void 0) { onNewData = this.onNewData; }
6287
+ if (this.currentSubscription || this.getOptions().skip)
6288
+ return;
6289
+ this.currentSubscription = this.currentObservable.subscribe({
6290
+ next: function (_a) {
6291
+ var loading = _a.loading, networkStatus = _a.networkStatus, data = _a.data;
6292
+ var previousResult = _this.previous.result;
6293
+ if (previousResult &&
6294
+ previousResult.loading === loading &&
6295
+ previousResult.networkStatus === networkStatus &&
6296
+ equality.equal(previousResult.data, data)) {
6297
+ return;
6298
+ }
6299
+ onNewData();
6300
+ },
6301
+ error: function (error) {
6302
+ _this.resubscribeToQuery();
6303
+ if (!error.hasOwnProperty('graphQLErrors'))
6304
+ throw error;
6305
+ var previousResult = _this.previous.result;
6306
+ if ((previousResult && previousResult.loading) ||
6307
+ !equality.equal(error, _this.previous.error)) {
6308
+ _this.previous.error = error;
6309
+ onNewData();
6310
+ }
6311
+ }
6312
+ });
6313
+ };
6314
+ QueryData.prototype.resubscribeToQuery = function () {
6315
+ this.removeQuerySubscription();
6316
+ var currentObservable = this.currentObservable;
6317
+ if (currentObservable) {
6318
+ var last = currentObservable["last"];
6319
+ try {
6320
+ currentObservable.resetLastResults();
6321
+ this.startQuerySubscription();
6322
+ }
6323
+ finally {
6324
+ currentObservable["last"] = last;
6325
+ }
6326
+ }
6327
+ };
6328
+ QueryData.prototype.getExecuteResult = function () {
6329
+ var result = this.observableQueryFields();
6330
+ var options = this.getOptions();
6331
+ if (options.skip) {
6332
+ result = tslib.__assign(tslib.__assign({}, result), { data: undefined, error: undefined, loading: false, networkStatus: exports.NetworkStatus.ready, called: true });
6333
+ }
6334
+ else if (this.currentObservable) {
6335
+ var currentResult = this.currentObservable.getCurrentResult();
6336
+ var data = currentResult.data, loading = currentResult.loading, partial = currentResult.partial, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
6337
+ var error = currentResult.error;
6338
+ if (errors && errors.length > 0) {
6339
+ error = new ApolloError({ graphQLErrors: errors });
6340
+ }
6341
+ result = tslib.__assign(tslib.__assign({}, result), { data: data, loading: loading, networkStatus: networkStatus, error: error, called: true });
6342
+ if (loading) ;
6343
+ else if (error) {
6344
+ Object.assign(result, {
6345
+ data: (this.currentObservable.getLastResult() || {})
6346
+ .data
6347
+ });
6348
+ }
6349
+ else {
6350
+ var fetchPolicy = this.currentObservable.options.fetchPolicy;
6351
+ var partialRefetch = options.partialRefetch;
6352
+ if (partialRefetch &&
6353
+ partial &&
6354
+ (!data || Object.keys(data).length === 0) &&
6355
+ fetchPolicy !== 'cache-only') {
6356
+ Object.assign(result, {
6357
+ loading: true,
6358
+ networkStatus: exports.NetworkStatus.loading
6359
+ });
6360
+ result.refetch();
6361
+ return result;
6362
+ }
6363
+ }
6364
+ }
6365
+ result.client = this.client;
6366
+ this.setOptions(options, true);
6367
+ var previousResult = this.previous.result;
6368
+ this.previous.loading =
6369
+ previousResult && previousResult.loading || false;
6370
+ result.previousData = previousResult &&
6371
+ (previousResult.data || previousResult.previousData);
6372
+ this.previous.result = result;
6373
+ this.currentObservable && this.currentObservable.resetQueryStoreErrors();
6374
+ return result;
6375
+ };
6376
+ QueryData.prototype.handleErrorOrCompleted = function () {
6377
+ if (!this.currentObservable || !this.previous.result)
6378
+ return;
6379
+ var _a = this.previous.result, data = _a.data, loading = _a.loading, error = _a.error;
6380
+ if (!loading) {
6381
+ var _b = this.getOptions(), query = _b.query, variables = _b.variables, onCompleted = _b.onCompleted, onError = _b.onError, skip = _b.skip;
6382
+ if (this.previousOptions &&
6383
+ !this.previous.loading &&
6384
+ equality.equal(this.previousOptions.query, query) &&
6385
+ equality.equal(this.previousOptions.variables, variables)) {
6386
+ return;
6387
+ }
6388
+ if (onCompleted && !error && !skip) {
6389
+ onCompleted(data);
6390
+ }
6391
+ else if (onError && error) {
6392
+ onError(error);
6393
+ }
6394
+ }
6395
+ };
6396
+ QueryData.prototype.removeQuerySubscription = function () {
6397
+ if (this.currentSubscription) {
6398
+ this.currentSubscription.unsubscribe();
6399
+ delete this.currentSubscription;
6400
+ }
6401
+ };
6402
+ QueryData.prototype.removeObservable = function (andDelete) {
6403
+ if (this.currentObservable) {
6404
+ this.currentObservable["tearDownQuery"]();
6405
+ if (andDelete) {
6406
+ delete this.currentObservable;
6407
+ }
6408
+ }
6409
+ };
6410
+ QueryData.prototype.observableQueryFields = function () {
6411
+ var _a;
6412
+ return {
6413
+ variables: (_a = this.currentObservable) === null || _a === void 0 ? void 0 : _a.variables,
6414
+ refetch: this.obsRefetch,
6415
+ fetchMore: this.obsFetchMore,
6416
+ updateQuery: this.obsUpdateQuery,
6417
+ startPolling: this.obsStartPolling,
6418
+ stopPolling: this.obsStopPolling,
6419
+ subscribeToMore: this.obsSubscribeToMore
6420
+ };
6421
+ };
6422
+ return QueryData;
6423
+ }(OperationData));
6424
+
6425
+ function useDeepMemo(memoFn, key) {
6426
+ var ref = React.useRef();
6427
+ if (!ref.current || !equality.equal(key, ref.current.key)) {
6428
+ ref.current = { key: key, value: memoFn() };
6429
+ }
6430
+ return ref.current.value;
6431
+ }
6432
+
6433
+ function useAfterFastRefresh(effectFn) {
6434
+ if (__DEV__) {
6435
+ var didRefresh_1 = React.useRef(false);
6436
+ React.useEffect(function () {
6437
+ return function () {
6438
+ didRefresh_1.current = true;
6439
+ };
6440
+ }, []);
6441
+ React.useEffect(function () {
6442
+ if (didRefresh_1.current === true) {
6443
+ didRefresh_1.current = false;
6444
+ effectFn();
6445
+ }
6446
+ }, []);
6447
+ }
6448
+ }
6449
+
6450
+ function useBaseQuery(query, options, lazy) {
6451
+ if (lazy === void 0) { lazy = false; }
6452
+ var context = React.useContext(getApolloContext());
6453
+ var _a = React.useReducer(function (x) { return x + 1; }, 0), tick = _a[0], forceUpdate = _a[1];
6454
+ var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { query: query }) : { query: query };
6455
+ var queryDataRef = React.useRef();
6456
+ var queryData = queryDataRef.current || (queryDataRef.current = new QueryData({
6457
+ options: updatedOptions,
6458
+ context: context,
6459
+ onNewData: function () {
6460
+ if (!queryData.ssrInitiated()) {
6461
+ Promise.resolve().then(function () { return queryDataRef.current && queryDataRef.current.isMounted && forceUpdate(); });
6462
+ }
6463
+ else {
6464
+ forceUpdate();
6465
+ }
6466
+ }
6467
+ }));
6468
+ queryData.setOptions(updatedOptions);
6469
+ queryData.context = context;
6470
+ var memo = {
6471
+ options: tslib.__assign(tslib.__assign({}, updatedOptions), { onError: void 0, onCompleted: void 0 }),
6472
+ context: context,
6473
+ tick: tick
6474
+ };
6475
+ var result = useDeepMemo(function () { return (lazy ? queryData.executeLazy() : queryData.execute()); }, memo);
6476
+ var queryResult = lazy
6477
+ ? result[1]
6478
+ : result;
6479
+ if (__DEV__) {
6480
+ useAfterFastRefresh(forceUpdate);
6481
+ }
6482
+ React.useEffect(function () {
6483
+ return function () {
6484
+ queryData.cleanup();
6485
+ queryDataRef.current = void 0;
6486
+ };
6487
+ }, []);
6488
+ React.useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
6489
+ queryResult.loading,
6490
+ queryResult.networkStatus,
6491
+ queryResult.error,
6492
+ queryResult.data,
6493
+ queryData.currentObservable,
6494
+ ]);
6495
+ return result;
6496
+ }
6497
+
6498
+ function useLazyQuery(query, options) {
6499
+ return useBaseQuery(query, options, true);
6500
+ }
6501
+
6502
+ function useMutation(mutation, options) {
6503
+ var context = React.useContext(getApolloContext());
6504
+ var _a = React.useState({ called: false, loading: false }), result = _a[0], setResult = _a[1];
6505
+ var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { mutation: mutation }) : { mutation: mutation };
6506
+ var mutationDataRef = React.useRef();
6507
+ function getMutationDataRef() {
6508
+ if (!mutationDataRef.current) {
6509
+ mutationDataRef.current = new MutationData({
6510
+ options: updatedOptions,
6511
+ context: context,
6512
+ result: result,
6513
+ setResult: setResult
6514
+ });
6515
+ }
6516
+ return mutationDataRef.current;
6517
+ }
6518
+ var mutationData = getMutationDataRef();
6519
+ mutationData.setOptions(updatedOptions);
6520
+ mutationData.context = context;
6521
+ React.useEffect(function () { return mutationData.afterExecute(); });
6522
+ return mutationData.execute(result);
6523
+ }
6524
+
6525
+ function useQuery(query, options) {
6526
+ return useBaseQuery(query, options, false);
6527
+ }
6528
+
6529
+ function useSubscription(subscription, options) {
6530
+ var _a = React.useReducer(function (x) { return x + 1; }, 0), forceUpdate = _a[1];
6531
+ var context = React.useContext(getApolloContext());
6532
+ var updatedOptions = options
6533
+ ? tslib.__assign(tslib.__assign({}, options), { subscription: subscription }) : { subscription: subscription };
6534
+ var _b = React.useState({
6535
+ loading: !updatedOptions.skip,
6536
+ error: void 0,
6537
+ data: void 0,
6538
+ }), result = _b[0], setResult = _b[1];
6539
+ var subscriptionDataRef = React.useRef();
6540
+ function getSubscriptionDataRef() {
6541
+ if (!subscriptionDataRef.current) {
6542
+ subscriptionDataRef.current = new SubscriptionData({
6543
+ options: updatedOptions,
6544
+ context: context,
6545
+ setResult: setResult
6546
+ });
6547
+ }
6548
+ return subscriptionDataRef.current;
6549
+ }
6550
+ var subscriptionData = getSubscriptionDataRef();
6551
+ subscriptionData.setOptions(updatedOptions, true);
6552
+ subscriptionData.context = context;
6553
+ if (__DEV__) {
6554
+ useAfterFastRefresh(forceUpdate);
6555
+ }
6556
+ React.useEffect(function () { return subscriptionData.afterExecute(); });
6557
+ React.useEffect(function () {
6558
+ return function () {
6559
+ subscriptionData.cleanup();
6560
+ subscriptionDataRef.current = void 0;
6561
+ };
6562
+ }, []);
6563
+ return subscriptionData.execute(result);
6564
+ }
6565
+
6566
+ function useReactiveVar(rv) {
6567
+ var value = rv();
6568
+ var setValue = React.useState(value)[1];
6569
+ React.useEffect(function () {
6570
+ var probablySameValue = rv();
6571
+ if (value !== probablySameValue) {
6572
+ setValue(probablySameValue);
6573
+ }
6574
+ else {
6575
+ return rv.onNextChange(setValue);
6576
+ }
6577
+ }, [value]);
6578
+ return value;
6579
+ }
5696
6580
 
5697
6581
  exports.setLogVerbosity = tsInvariant.setVerbosity;
5698
6582
  exports.Observable = zenObservableTs.Observable;
@@ -5703,8 +6587,10 @@ exports.gql = graphqlTag.gql;
5703
6587
  exports.resetCaches = graphqlTag.resetCaches;
5704
6588
  exports.ApolloCache = ApolloCache;
5705
6589
  exports.ApolloClient = ApolloClient;
6590
+ exports.ApolloConsumer = ApolloConsumer;
5706
6591
  exports.ApolloError = ApolloError;
5707
6592
  exports.ApolloLink = ApolloLink;
6593
+ exports.ApolloProvider = ApolloProvider;
5708
6594
  exports.HttpLink = HttpLink;
5709
6595
  exports.InMemoryCache = InMemoryCache;
5710
6596
  exports.MissingFieldError = MissingFieldError;
@@ -5721,12 +6607,16 @@ exports.fallbackHttpConfig = fallbackHttpConfig;
5721
6607
  exports.from = from;
5722
6608
  exports.fromError = fromError;
5723
6609
  exports.fromPromise = fromPromise;
6610
+ exports.getApolloContext = getApolloContext;
5724
6611
  exports.isApolloError = isApolloError;
5725
6612
  exports.isReference = isReference;
5726
6613
  exports.makeReference = makeReference;
5727
6614
  exports.makeVar = makeVar;
5728
6615
  exports.mergeOptions = mergeOptions;
6616
+ exports.operationName = operationName;
5729
6617
  exports.parseAndCheckHttpResponse = parseAndCheckHttpResponse;
6618
+ exports.parser = parser;
6619
+ exports.resetApolloContext = getApolloContext;
5730
6620
  exports.rewriteURIForGET = rewriteURIForGET;
5731
6621
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
5732
6622
  exports.selectURI = selectURI;
@@ -5734,4 +6624,10 @@ exports.serializeFetchParameter = serializeFetchParameter;
5734
6624
  exports.split = split;
5735
6625
  exports.throwServerError = throwServerError;
5736
6626
  exports.toPromise = toPromise;
6627
+ exports.useApolloClient = useApolloClient;
6628
+ exports.useLazyQuery = useLazyQuery;
6629
+ exports.useMutation = useMutation;
6630
+ exports.useQuery = useQuery;
6631
+ exports.useReactiveVar = useReactiveVar;
6632
+ exports.useSubscription = useSubscription;
5737
6633
  //# sourceMappingURL=apollo-client.cjs.js.map