@apollo/client 3.6.0-beta.1 → 3.6.0-beta.10

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 (170) hide show
  1. package/apollo-client.cjs +574 -421
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +36 -35
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/inmemory/helpers.d.ts +1 -0
  7. package/cache/inmemory/helpers.d.ts.map +1 -1
  8. package/cache/inmemory/helpers.js +4 -3
  9. package/cache/inmemory/helpers.js.map +1 -1
  10. package/cache/inmemory/key-extractor.js +7 -7
  11. package/cache/inmemory/key-extractor.js.map +1 -1
  12. package/cache/inmemory/object-canon.d.ts.map +1 -1
  13. package/cache/inmemory/object-canon.js +2 -1
  14. package/cache/inmemory/object-canon.js.map +1 -1
  15. package/cache/inmemory/policies.d.ts +1 -1
  16. package/cache/inmemory/policies.d.ts.map +1 -1
  17. package/cache/inmemory/policies.js +9 -9
  18. package/cache/inmemory/policies.js.map +1 -1
  19. package/cache/inmemory/readFromStore.js +6 -6
  20. package/cache/inmemory/readFromStore.js.map +1 -1
  21. package/cache/inmemory/writeToStore.js +13 -13
  22. package/cache/inmemory/writeToStore.js.map +1 -1
  23. package/core/ApolloClient.d.ts.map +1 -1
  24. package/core/ApolloClient.js +3 -3
  25. package/core/ApolloClient.js.map +1 -1
  26. package/core/LocalState.js +1 -1
  27. package/core/LocalState.js.map +1 -1
  28. package/core/ObservableQuery.d.ts +8 -2
  29. package/core/ObservableQuery.d.ts.map +1 -1
  30. package/core/ObservableQuery.js +83 -37
  31. package/core/ObservableQuery.js.map +1 -1
  32. package/core/QueryInfo.d.ts.map +1 -1
  33. package/core/QueryInfo.js +4 -2
  34. package/core/QueryInfo.js.map +1 -1
  35. package/core/QueryManager.d.ts +5 -2
  36. package/core/QueryManager.d.ts.map +1 -1
  37. package/core/QueryManager.js +19 -12
  38. package/core/QueryManager.js.map +1 -1
  39. package/core/core.cjs +113 -60
  40. package/core/core.cjs.map +1 -1
  41. package/core/index.d.ts +1 -1
  42. package/core/index.d.ts.map +1 -1
  43. package/core/index.js +1 -1
  44. package/core/index.js.map +1 -1
  45. package/core/watchQueryOptions.d.ts +8 -1
  46. package/core/watchQueryOptions.d.ts.map +1 -1
  47. package/core/watchQueryOptions.js.map +1 -1
  48. package/errors/errors.cjs +2 -2
  49. package/errors/errors.cjs.map +1 -1
  50. package/errors/index.js +2 -2
  51. package/errors/index.js.map +1 -1
  52. package/invariantErrorCodes.js +27 -27
  53. package/link/batch/batch.cjs +48 -38
  54. package/link/batch/batch.cjs.map +1 -1
  55. package/link/batch/batching.d.ts +2 -6
  56. package/link/batch/batching.d.ts.map +1 -1
  57. package/link/batch/batching.js +48 -38
  58. package/link/batch/batching.js.map +1 -1
  59. package/link/batch-http/batch-http.cjs +1 -1
  60. package/link/batch-http/batch-http.cjs.map +1 -1
  61. package/link/batch-http/batchHttpLink.js +2 -2
  62. package/link/batch-http/batchHttpLink.js.map +1 -1
  63. package/link/http/createHttpLink.js +2 -2
  64. package/link/http/createHttpLink.js.map +1 -1
  65. package/link/http/http.cjs +24 -13
  66. package/link/http/http.cjs.map +1 -1
  67. package/link/http/index.d.ts +1 -1
  68. package/link/http/index.d.ts.map +1 -1
  69. package/link/http/index.js +1 -1
  70. package/link/http/index.js.map +1 -1
  71. package/link/http/parseAndCheckHttpResponse.js +3 -3
  72. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  73. package/link/http/rewriteURIForGET.js +1 -1
  74. package/link/http/rewriteURIForGET.js.map +1 -1
  75. package/link/http/selectHttpOptionsAndBody.d.ts +5 -1
  76. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  77. package/link/http/selectHttpOptionsAndBody.js +19 -8
  78. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  79. package/link/http/serializeFetchParameter.js +1 -1
  80. package/link/http/serializeFetchParameter.js.map +1 -1
  81. package/link/subscriptions/index.d.ts +9 -0
  82. package/link/subscriptions/index.d.ts.map +1 -0
  83. package/link/subscriptions/index.js +39 -0
  84. package/link/subscriptions/index.js.map +1 -0
  85. package/link/subscriptions/package.json +8 -0
  86. package/link/subscriptions/subscriptions.cjs +45 -0
  87. package/link/subscriptions/subscriptions.cjs.map +1 -0
  88. package/link/utils/utils.cjs +1 -1
  89. package/link/utils/utils.cjs.map +1 -1
  90. package/link/utils/validateOperation.js +1 -1
  91. package/link/utils/validateOperation.js.map +1 -1
  92. package/main.cjs +4 -4
  93. package/package.json +27 -26
  94. package/react/components/components.cjs +3 -3
  95. package/react/context/context.cjs +3 -3
  96. package/react/hoc/hoc.cjs +9 -9
  97. package/react/hoc/hoc.cjs.map +1 -1
  98. package/react/hoc/mutation-hoc.js +2 -2
  99. package/react/hoc/mutation-hoc.js.map +1 -1
  100. package/react/hoc/query-hoc.js +1 -1
  101. package/react/hoc/query-hoc.js.map +1 -1
  102. package/react/hoc/subscription-hoc.js +1 -1
  103. package/react/hoc/subscription-hoc.js.map +1 -1
  104. package/react/hoc/withApollo.js +1 -1
  105. package/react/hoc/withApollo.js.map +1 -1
  106. package/react/hooks/hooks.cjs +345 -255
  107. package/react/hooks/hooks.cjs.map +1 -1
  108. package/react/hooks/options.d.ts +3 -0
  109. package/react/hooks/options.d.ts.map +1 -0
  110. package/react/hooks/options.js +20 -0
  111. package/react/hooks/options.js.map +1 -0
  112. package/react/hooks/useApolloClient.js +2 -2
  113. package/react/hooks/useApolloClient.js.map +1 -1
  114. package/react/hooks/useLazyQuery.d.ts +2 -2
  115. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  116. package/react/hooks/useLazyQuery.js +23 -28
  117. package/react/hooks/useLazyQuery.js.map +1 -1
  118. package/react/hooks/useMutation.d.ts.map +1 -1
  119. package/react/hooks/useMutation.js +59 -65
  120. package/react/hooks/useMutation.js.map +1 -1
  121. package/react/hooks/useQuery.d.ts +2 -2
  122. package/react/hooks/useQuery.d.ts.map +1 -1
  123. package/react/hooks/useQuery.js +235 -154
  124. package/react/hooks/useQuery.js.map +1 -1
  125. package/react/hooks/useSubscription.d.ts.map +1 -1
  126. package/react/hooks/useSubscription.js +10 -8
  127. package/react/hooks/useSubscription.js.map +1 -1
  128. package/react/parser/index.js +7 -7
  129. package/react/parser/index.js.map +1 -1
  130. package/react/parser/parser.cjs +7 -7
  131. package/react/parser/parser.cjs.map +1 -1
  132. package/react/react.cjs +2 -2
  133. package/react/ssr/RenderPromises.d.ts +2 -2
  134. package/react/ssr/RenderPromises.d.ts.map +1 -1
  135. package/react/ssr/RenderPromises.js +7 -5
  136. package/react/ssr/RenderPromises.js.map +1 -1
  137. package/react/ssr/ssr.cjs +10 -8
  138. package/react/ssr/ssr.cjs.map +1 -1
  139. package/react/types/types.d.ts +4 -1
  140. package/react/types/types.d.ts.map +1 -1
  141. package/react/types/types.js.map +1 -1
  142. package/testing/core/core.cjs +2 -2
  143. package/testing/core/core.cjs.map +1 -1
  144. package/testing/core/mocking/mockFetch.js +2 -2
  145. package/testing/core/mocking/mockFetch.js.map +1 -1
  146. package/testing/core/mocking/mockLink.js +2 -2
  147. package/testing/core/mocking/mockLink.js.map +1 -1
  148. package/testing/core/observableToPromise.js +1 -1
  149. package/testing/core/observableToPromise.js.map +1 -1
  150. package/testing/testing.cjs +5 -5
  151. package/utilities/common/makeUniqueId.js +1 -1
  152. package/utilities/common/makeUniqueId.js.map +1 -1
  153. package/utilities/globals/fix-graphql.js +1 -1
  154. package/utilities/globals/global.d.ts +2 -8
  155. package/utilities/globals/global.d.ts.map +1 -1
  156. package/utilities/globals/global.js +1 -1
  157. package/utilities/globals/global.js.map +1 -1
  158. package/utilities/globals/globals.cjs +1 -1
  159. package/utilities/globals/globals.cjs.map +1 -1
  160. package/utilities/graphql/directives.js +4 -4
  161. package/utilities/graphql/directives.js.map +1 -1
  162. package/utilities/graphql/fragments.js +3 -3
  163. package/utilities/graphql/fragments.js.map +1 -1
  164. package/utilities/graphql/getFromAST.js +2 -2
  165. package/utilities/graphql/getFromAST.js.map +1 -1
  166. package/utilities/graphql/storeUtils.js +5 -5
  167. package/utilities/graphql/storeUtils.js.map +1 -1
  168. package/utilities/utilities.cjs +15 -15
  169. package/utilities/utilities.cjs.map +1 -1
  170. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
6
  var tsInvariant = require('ts-invariant');
7
- var equality = require('@wry/equality');
7
+ var equal = require('@wry/equality');
8
8
  var zenObservableTs = require('zen-observable-ts');
9
9
  require('symbol-observable');
10
10
  var graphql = require('graphql');
@@ -13,20 +13,22 @@ var context = require('@wry/context');
13
13
  var trie = require('@wry/trie');
14
14
  var graphqlTag = require('graphql-tag');
15
15
  var React = require('react');
16
- var shim = require('use-sync-external-store/shim');
16
+
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
17
18
 
18
19
  function _interopNamespace(e) {
19
20
  if (e && e.__esModule) return e;
20
21
  var n = Object.create(null);
21
22
  if (e) {
22
- Object.keys(e).forEach(function (k) {
23
+ for (var k in e) {
23
24
  n[k] = e[k];
24
- });
25
+ }
25
26
  }
26
- n['default'] = e;
27
+ n["default"] = e;
27
28
  return Object.freeze(n);
28
29
  }
29
30
 
31
+ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
30
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
31
33
 
32
34
  function maybe(thunk) {
@@ -46,7 +48,7 @@ function shouldInclude(_a, variables) {
46
48
  var evaledValue = false;
47
49
  if (ifArgument.value.kind === 'Variable') {
48
50
  evaledValue = variables && variables[ifArgument.value.name.value];
49
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 37);
51
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 37);
50
52
  }
51
53
  else {
52
54
  evaledValue = ifArgument.value.value;
@@ -83,12 +85,12 @@ function getInclusionDirectives(directives) {
83
85
  return;
84
86
  var directiveArguments = directive.arguments;
85
87
  var directiveName = directive.name.value;
86
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
88
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
87
89
  var ifArgument = directiveArguments[0];
88
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
90
+ __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
89
91
  var ifValue = ifArgument.value;
90
92
  __DEV__ ? tsInvariant.invariant(ifValue &&
91
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.") : tsInvariant.invariant(ifValue &&
93
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
92
94
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
93
95
  result.push({ directive: directive, ifArgument: ifArgument });
94
96
  });
@@ -101,7 +103,7 @@ function getFragmentQueryDocument(document, fragmentName) {
101
103
  var fragments = [];
102
104
  document.definitions.forEach(function (definition) {
103
105
  if (definition.kind === 'OperationDefinition') {
104
- throw __DEV__ ? new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
106
+ throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
105
107
  'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(41);
106
108
  }
107
109
  if (definition.kind === 'FragmentDefinition') {
@@ -109,7 +111,7 @@ function getFragmentQueryDocument(document, fragmentName) {
109
111
  }
110
112
  });
111
113
  if (typeof actualFragmentName === 'undefined') {
112
- __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);
114
+ __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : tsInvariant.invariant(fragments.length === 1, 42);
113
115
  actualFragmentName = fragments[0].name.value;
114
116
  }
115
117
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -146,7 +148,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
146
148
  return selection;
147
149
  case 'FragmentSpread': {
148
150
  var fragment = fragmentMap && fragmentMap[selection.name.value];
149
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 43);
151
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value, ".")) : tsInvariant.invariant(fragment, 43);
150
152
  return fragment;
151
153
  }
152
154
  default:
@@ -228,7 +230,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
228
230
  argObj[name.value] = null;
229
231
  }
230
232
  else {
231
- throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
233
+ throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
232
234
  'is not supported. Use variables instead of inline arguments to ' +
233
235
  'overcome this limitation.') : new tsInvariant.InvariantError(52);
234
236
  }
@@ -280,7 +282,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
280
282
  filterKeys.forEach(function (key) {
281
283
  filteredArgs_1[key] = args[key];
282
284
  });
283
- return directives['connection']['key'] + "(" + stringify(filteredArgs_1) + ")";
285
+ return "".concat(directives['connection']['key'], "(").concat(stringify(filteredArgs_1), ")");
284
286
  }
285
287
  else {
286
288
  return directives['connection']['key'];
@@ -289,17 +291,17 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
289
291
  var completeFieldName = fieldName;
290
292
  if (args) {
291
293
  var stringifiedArgs = stringify(args);
292
- completeFieldName += "(" + stringifiedArgs + ")";
294
+ completeFieldName += "(".concat(stringifiedArgs, ")");
293
295
  }
294
296
  if (directives) {
295
297
  Object.keys(directives).forEach(function (key) {
296
298
  if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
297
299
  return;
298
300
  if (directives[key] && Object.keys(directives[key]).length) {
299
- completeFieldName += "@" + key + "(" + stringify(directives[key]) + ")";
301
+ completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
300
302
  }
301
303
  else {
302
- completeFieldName += "@" + key;
304
+ completeFieldName += "@".concat(key);
303
305
  }
304
306
  });
305
307
  }
@@ -369,11 +371,11 @@ function checkDocument(doc) {
369
371
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
370
372
  .map(function (definition) {
371
373
  if (definition.kind !== 'OperationDefinition') {
372
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(45);
374
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(45);
373
375
  }
374
376
  return definition;
375
377
  });
376
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 46);
378
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 46);
377
379
  return doc;
378
380
  }
379
381
  function getOperationDefinition(doc) {
@@ -704,7 +706,7 @@ function removeClientSetsFromDocument(document) {
704
706
  return modifiedDoc;
705
707
  }
706
708
 
707
- var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
709
+ var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
708
710
  function mergeDeep() {
709
711
  var sources = [];
710
712
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -741,7 +743,7 @@ var DeepMerger = (function () {
741
743
  }
742
744
  if (isNonNullObject(source) && isNonNullObject(target)) {
743
745
  Object.keys(source).forEach(function (sourceKey) {
744
- if (hasOwnProperty$3.call(target, sourceKey)) {
746
+ if (hasOwnProperty$4.call(target, sourceKey)) {
745
747
  var targetValue = target[sourceKey];
746
748
  if (source[sourceKey] !== targetValue) {
747
749
  var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
@@ -1078,7 +1080,7 @@ var prefixCounts = new Map();
1078
1080
  function makeUniqueId(prefix) {
1079
1081
  var count = prefixCounts.get(prefix) || 1;
1080
1082
  prefixCounts.set(prefix, count + 1);
1081
- return prefix + ":" + count + ":" + Math.random().toString(36).slice(2);
1083
+ return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
1082
1084
  }
1083
1085
 
1084
1086
  function stringifyForDisplay(value) {
@@ -1143,7 +1145,7 @@ function validateOperation(operation) {
1143
1145
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1144
1146
  var key = _a[_i];
1145
1147
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1146
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(24);
1148
+ throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: ".concat(key)) : new tsInvariant.InvariantError(24);
1147
1149
  }
1148
1150
  }
1149
1151
  return operation;
@@ -1292,9 +1294,9 @@ var concat = ApolloLink.concat;
1292
1294
 
1293
1295
  var execute = ApolloLink.execute;
1294
1296
 
1295
- var version = '3.6.0-beta.1';
1297
+ var version = '3.6.0-beta.10';
1296
1298
 
1297
- var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1299
+ var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1298
1300
  function parseAndCheckHttpResponse(operations) {
1299
1301
  return function (response) { return response
1300
1302
  .text()
@@ -1313,14 +1315,14 @@ function parseAndCheckHttpResponse(operations) {
1313
1315
  })
1314
1316
  .then(function (result) {
1315
1317
  if (response.status >= 300) {
1316
- throwServerError(response, result, "Response not successful: Received status code " + response.status);
1318
+ throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1317
1319
  }
1318
1320
  if (!Array.isArray(result) &&
1319
- !hasOwnProperty$2.call(result, 'data') &&
1320
- !hasOwnProperty$2.call(result, 'errors')) {
1321
- throwServerError(response, result, "Server response was missing for query '" + (Array.isArray(operations)
1321
+ !hasOwnProperty$3.call(result, 'data') &&
1322
+ !hasOwnProperty$3.call(result, 'errors')) {
1323
+ throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1322
1324
  ? operations.map(function (op) { return op.operationName; })
1323
- : operations.operationName) + "'.");
1325
+ : operations.operationName, "'."));
1324
1326
  }
1325
1327
  return result;
1326
1328
  }); };
@@ -1332,7 +1334,7 @@ var serializeFetchParameter = function (p, label) {
1332
1334
  serialized = JSON.stringify(p);
1333
1335
  }
1334
1336
  catch (e) {
1335
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(21);
1337
+ var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new tsInvariant.InvariantError(21);
1336
1338
  parseError.parseError = e;
1337
1339
  throw parseError;
1338
1340
  }
@@ -1356,17 +1358,27 @@ var fallbackHttpConfig = {
1356
1358
  options: defaultOptions,
1357
1359
  };
1358
1360
  var defaultPrinter = function (ast, printer) { return printer(ast); };
1359
- var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1361
+ function selectHttpOptionsAndBody(operation, fallbackConfig) {
1362
+ var configs = [];
1363
+ for (var _i = 2; _i < arguments.length; _i++) {
1364
+ configs[_i - 2] = arguments[_i];
1365
+ }
1366
+ configs.unshift(fallbackConfig);
1367
+ return selectHttpOptionsAndBodyInternal.apply(void 0, tslib.__spreadArray([operation,
1368
+ defaultPrinter], configs, false));
1369
+ }
1370
+ function selectHttpOptionsAndBodyInternal(operation, printer) {
1360
1371
  var configs = [];
1361
- for (var _i = 3; _i < arguments.length; _i++) {
1362
- configs[_i - 3] = arguments[_i];
1372
+ for (var _i = 2; _i < arguments.length; _i++) {
1373
+ configs[_i - 2] = arguments[_i];
1363
1374
  }
1364
- var options = tslib.__assign(tslib.__assign({}, fallbackConfig.options), { headers: fallbackConfig.headers, credentials: fallbackConfig.credentials });
1365
- var http = fallbackConfig.http || {};
1375
+ var options = {};
1376
+ var http = {};
1366
1377
  configs.forEach(function (config) {
1367
1378
  options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), headersToLowerCase(config.headers)) });
1368
- if (config.credentials)
1379
+ if (config.credentials) {
1369
1380
  options.credentials = config.credentials;
1381
+ }
1370
1382
  http = tslib.__assign(tslib.__assign({}, http), config.http);
1371
1383
  });
1372
1384
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
@@ -1379,7 +1391,7 @@ var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1379
1391
  options: options,
1380
1392
  body: body,
1381
1393
  };
1382
- };
1394
+ }
1383
1395
  function headersToLowerCase(headers) {
1384
1396
  if (headers) {
1385
1397
  var normalized_1 = Object.create(null);
@@ -1422,7 +1434,7 @@ var selectURI = function (operation, fallbackURI) {
1422
1434
  function rewriteURIForGET(chosenURI, body) {
1423
1435
  var queryParams = [];
1424
1436
  var addQueryParam = function (key, value) {
1425
- queryParams.push(key + "=" + encodeURIComponent(value));
1437
+ queryParams.push("".concat(key, "=").concat(encodeURIComponent(value)));
1426
1438
  };
1427
1439
  if ('query' in body) {
1428
1440
  addQueryParam('query', body.query);
@@ -1494,7 +1506,7 @@ var createHttpLink = function (linkOptions) {
1494
1506
  credentials: context.credentials,
1495
1507
  headers: contextHeaders,
1496
1508
  };
1497
- var _b = selectHttpOptionsAndBody(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1509
+ var _b = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1498
1510
  if (body.variables && !includeUnusedVariables) {
1499
1511
  var unusedNames_1 = new Set(Object.keys(body.variables));
1500
1512
  graphql.visit(operation.query, {
@@ -1687,7 +1699,7 @@ function defaultDataIdFromObject(_a, context) {
1687
1699
  if (id === void 0)
1688
1700
  id = _id;
1689
1701
  if (id !== void 0) {
1690
- return __typename + ":" + ((typeof id === "number" ||
1702
+ return "".concat(__typename, ":").concat((typeof id === "number" ||
1691
1703
  typeof id === "string") ? id : JSON.stringify(id));
1692
1704
  }
1693
1705
  }
@@ -1717,7 +1729,7 @@ function fieldNameFromStoreName(storeFieldName) {
1717
1729
  }
1718
1730
  function selectionSetMatchesResult(selectionSet, result, variables) {
1719
1731
  if (isNonNullObject(result)) {
1720
- return Array.isArray(result)
1732
+ return isArray(result)
1721
1733
  ? result.every(function (item) { return selectionSetMatchesResult(selectionSet, item, variables); })
1722
1734
  : selectionSet.selections.every(function (field) {
1723
1735
  if (isField(field) && shouldInclude(field, variables)) {
@@ -1734,11 +1746,12 @@ function selectionSetMatchesResult(selectionSet, result, variables) {
1734
1746
  function storeValueIsStoreObject(value) {
1735
1747
  return isNonNullObject(value) &&
1736
1748
  !isReference(value) &&
1737
- !Array.isArray(value);
1749
+ !isArray(value);
1738
1750
  }
1739
1751
  function makeProcessedFieldsMerger() {
1740
1752
  return new DeepMerger;
1741
1753
  }
1754
+ var isArray = function (a) { return Array.isArray(a); };
1742
1755
 
1743
1756
  var DELETE = Object.create(null);
1744
1757
  var delModifier = function () { return DELETE; };
@@ -2149,7 +2162,7 @@ var Layer = (function (_super) {
2149
2162
  }
2150
2163
  else if (ownStoreObject !== parentStoreObject) {
2151
2164
  Object.keys(ownStoreObject).forEach(function (storeFieldName) {
2152
- if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2165
+ if (!equal.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2153
2166
  _this.group.dirty(dataId, storeFieldName);
2154
2167
  }
2155
2168
  });
@@ -2193,7 +2206,7 @@ var Stump = (function (_super) {
2193
2206
  function storeObjectReconciler(existingObject, incomingObject, property) {
2194
2207
  var existingValue = existingObject[property];
2195
2208
  var incomingValue = incomingObject[property];
2196
- return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2209
+ return equal.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2197
2210
  }
2198
2211
  function supportsResultCaching(store) {
2199
2212
  return !!(store instanceof EntityStore && store.group.caching);
@@ -2201,7 +2214,7 @@ function supportsResultCaching(store) {
2201
2214
 
2202
2215
  function shallowCopy(value) {
2203
2216
  if (isNonNullObject(value)) {
2204
- return Array.isArray(value)
2217
+ return isArray(value)
2205
2218
  ? value.slice(0)
2206
2219
  : tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
2207
2220
  }
@@ -2423,7 +2436,7 @@ var StoreReader = (function () {
2423
2436
  !context.store.has(objectOrReference.__ref)) {
2424
2437
  return {
2425
2438
  result: this.canon.empty,
2426
- missing: "Dangling reference to missing " + objectOrReference.__ref + " object",
2439
+ missing: "Dangling reference to missing ".concat(objectOrReference.__ref, " object"),
2427
2440
  };
2428
2441
  }
2429
2442
  var variables = context.variables, policies = context.policies, store = context.store;
@@ -2458,13 +2471,13 @@ var StoreReader = (function () {
2458
2471
  if (fieldValue === void 0) {
2459
2472
  if (!addTypenameToDocument.added(selection)) {
2460
2473
  missing = context.merge(missing, (_a = {},
2461
- _a[resultName] = "Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
2474
+ _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(isReference(objectOrReference)
2462
2475
  ? objectOrReference.__ref + " object"
2463
2476
  : "object " + JSON.stringify(objectOrReference, null, 2)),
2464
2477
  _a));
2465
2478
  }
2466
2479
  }
2467
- else if (Array.isArray(fieldValue)) {
2480
+ else if (isArray(fieldValue)) {
2468
2481
  fieldValue = handleMissing(_this.executeSubSelectedArray({
2469
2482
  field: selection,
2470
2483
  array: fieldValue,
@@ -2523,7 +2536,7 @@ var StoreReader = (function () {
2523
2536
  if (item === null) {
2524
2537
  return null;
2525
2538
  }
2526
- if (Array.isArray(item)) {
2539
+ if (isArray(item)) {
2527
2540
  return handleMissing(_this.executeSubSelectedArray({
2528
2541
  field: field,
2529
2542
  array: item,
@@ -2568,7 +2581,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
2568
2581
  var workSet_1 = new Set([fieldValue]);
2569
2582
  workSet_1.forEach(function (value) {
2570
2583
  if (isNonNullObject(value)) {
2571
- __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);
2584
+ __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : tsInvariant.invariant(!isReference(value), 5);
2572
2585
  Object.values(value).forEach(workSet_1.add, workSet_1);
2573
2586
  }
2574
2587
  });
@@ -2655,10 +2668,10 @@ function keyFieldsFnFromSpecifier(specifier) {
2655
2668
  hasOwn.call(object, schemaKeyPath[0])) {
2656
2669
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
2657
2670
  }
2658
- __DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '" + schemaKeyPath.join('.') + "' while extracting keyFields from " + JSON.stringify(object)) : tsInvariant.invariant(extracted !== void 0, 2);
2671
+ __DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '".concat(schemaKeyPath.join('.'), "' while extracting keyFields from ").concat(JSON.stringify(object))) : tsInvariant.invariant(extracted !== void 0, 2);
2659
2672
  return extracted;
2660
2673
  });
2661
- return context.typename + ":" + JSON.stringify(keyObject);
2674
+ return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
2662
2675
  });
2663
2676
  }
2664
2677
  function keyArgsFnFromSpecifier(specifier) {
@@ -2717,13 +2730,13 @@ function getSpecifierPaths(spec) {
2717
2730
  var paths_1 = info.paths = [];
2718
2731
  var currentPath_1 = [];
2719
2732
  spec.forEach(function (s, i) {
2720
- if (Array.isArray(s)) {
2733
+ if (isArray(s)) {
2721
2734
  getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
2722
2735
  currentPath_1.length = 0;
2723
2736
  }
2724
2737
  else {
2725
2738
  currentPath_1.push(s);
2726
- if (!Array.isArray(spec[i + 1])) {
2739
+ if (!isArray(spec[i + 1])) {
2727
2740
  paths_1.push(currentPath_1.slice(0));
2728
2741
  currentPath_1.length = 0;
2729
2742
  }
@@ -2738,14 +2751,14 @@ function extractKey(object, key) {
2738
2751
  function extractKeyPath(object, path, extract) {
2739
2752
  extract = extract || extractKey;
2740
2753
  return normalize(path.reduce(function reducer(obj, key) {
2741
- return Array.isArray(obj)
2754
+ return isArray(obj)
2742
2755
  ? obj.map(function (child) { return reducer(child, key); })
2743
2756
  : obj && extract(obj, key);
2744
2757
  }, object));
2745
2758
  }
2746
2759
  function normalize(value) {
2747
2760
  if (isNonNullObject(value)) {
2748
- if (Array.isArray(value)) {
2761
+ if (isArray(value)) {
2749
2762
  return value.map(normalize);
2750
2763
  }
2751
2764
  return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
@@ -2808,7 +2821,7 @@ var Policies = (function () {
2808
2821
  var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
2809
2822
  while (keyFn) {
2810
2823
  var specifierOrId = keyFn(object, context);
2811
- if (Array.isArray(specifierOrId)) {
2824
+ if (isArray(specifierOrId)) {
2812
2825
  keyFn = keyFieldsFnFromSpecifier(specifierOrId);
2813
2826
  }
2814
2827
  else {
@@ -2851,7 +2864,7 @@ var Policies = (function () {
2851
2864
  setMerge(existing, incoming.merge);
2852
2865
  existing.keyFn =
2853
2866
  keyFields === false ? nullKeyFieldsFn :
2854
- Array.isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2867
+ isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2855
2868
  typeof keyFields === "function" ? keyFields :
2856
2869
  existing.keyFn;
2857
2870
  if (fields) {
@@ -2865,7 +2878,7 @@ var Policies = (function () {
2865
2878
  var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
2866
2879
  existing.keyFn =
2867
2880
  keyArgs === false ? simpleKeyArgsFn :
2868
- Array.isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2881
+ isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2869
2882
  typeof keyArgs === "function" ? keyArgs :
2870
2883
  existing.keyFn;
2871
2884
  if (typeof read === "function") {
@@ -2884,7 +2897,7 @@ var Policies = (function () {
2884
2897
  var rootId = "ROOT_" + which.toUpperCase();
2885
2898
  var old = this.rootTypenamesById[rootId];
2886
2899
  if (typename !== old) {
2887
- __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 3);
2900
+ __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root ".concat(which, " __typename more than once")) : tsInvariant.invariant(!old || old === which, 3);
2888
2901
  if (old)
2889
2902
  delete this.rootIdsByTypename[old];
2890
2903
  this.rootIdsByTypename[typename] = rootId;
@@ -2968,7 +2981,7 @@ var Policies = (function () {
2968
2981
  if (supertypeSet.has(supertype)) {
2969
2982
  if (!typenameSupertypeSet.has(supertype)) {
2970
2983
  if (checkingFuzzySubtypes) {
2971
- __DEV__ && tsInvariant.invariant.warn("Inferring subtype " + typename + " of supertype " + supertype);
2984
+ __DEV__ && tsInvariant.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
2972
2985
  }
2973
2986
  typenameSupertypeSet.add(supertype);
2974
2987
  }
@@ -3010,7 +3023,7 @@ var Policies = (function () {
3010
3023
  var args = argsFromFieldSpecifier(fieldSpec);
3011
3024
  while (keyFn) {
3012
3025
  var specifierOrString = keyFn(args, context);
3013
- if (Array.isArray(specifierOrString)) {
3026
+ if (isArray(specifierOrString)) {
3014
3027
  keyFn = keyArgsFnFromSpecifier(specifierOrString);
3015
3028
  }
3016
3029
  else {
@@ -3122,7 +3135,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3122
3135
  }
3123
3136
  }
3124
3137
  if (__DEV__ && options.from === void 0) {
3125
- __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + stringifyForDisplay(Array.from(readFieldArgs)));
3138
+ __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments ".concat(stringifyForDisplay(Array.from(readFieldArgs))));
3126
3139
  }
3127
3140
  if (void 0 === options.variables) {
3128
3141
  options.variables = variables;
@@ -3131,7 +3144,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3131
3144
  }
3132
3145
  function makeMergeObjectsFunction(store) {
3133
3146
  return function mergeObjects(existing, incoming) {
3134
- if (Array.isArray(existing) || Array.isArray(incoming)) {
3147
+ if (isArray(existing) || isArray(incoming)) {
3135
3148
  throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
3136
3149
  }
3137
3150
  if (isNonNullObject(existing) &&
@@ -3162,7 +3175,7 @@ function makeMergeObjectsFunction(store) {
3162
3175
  }
3163
3176
 
3164
3177
  function getContextFlavor(context, clientOnly, deferred) {
3165
- var key = "" + clientOnly + deferred;
3178
+ var key = "".concat(clientOnly).concat(deferred);
3166
3179
  var flavored = context.flavors.get(key);
3167
3180
  if (!flavored) {
3168
3181
  context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
@@ -3204,7 +3217,7 @@ var StoreWriter = (function () {
3204
3217
  context: context,
3205
3218
  });
3206
3219
  if (!isReference(ref)) {
3207
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(6);
3220
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new tsInvariant.InvariantError(6);
3208
3221
  }
3209
3222
  context.incomingById.forEach(function (_a, dataId) {
3210
3223
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -3309,7 +3322,7 @@ var StoreWriter = (function () {
3309
3322
  !context.deferred &&
3310
3323
  !addTypenameToDocument.added(field) &&
3311
3324
  !policies.getReadFunction(typename, field.name.value)) {
3312
- __DEV__ && tsInvariant.invariant.error(("Missing field '" + resultKeyNameFromField(field) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
3325
+ __DEV__ && tsInvariant.invariant.error("Missing field '".concat(resultKeyNameFromField(field), "' while writing result ").concat(JSON.stringify(result, null, 2)).substring(0, 1000));
3313
3326
  }
3314
3327
  });
3315
3328
  try {
@@ -3360,7 +3373,7 @@ var StoreWriter = (function () {
3360
3373
  if (!field.selectionSet || value === null) {
3361
3374
  return __DEV__ ? cloneDeep(value) : value;
3362
3375
  }
3363
- if (Array.isArray(value)) {
3376
+ if (isArray(value)) {
3364
3377
  return value.map(function (item, i) {
3365
3378
  var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
3366
3379
  maybeRecycleChildMergeTree(mergeTree, i);
@@ -3425,7 +3438,7 @@ var StoreWriter = (function () {
3425
3438
  var _a;
3426
3439
  var _this = this;
3427
3440
  if (mergeTree.map.size && !isReference(incoming)) {
3428
- var e_1 = (!Array.isArray(incoming) &&
3441
+ var e_1 = (!isArray(incoming) &&
3429
3442
  (isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
3430
3443
  var i_1 = incoming;
3431
3444
  if (e_1 && !getStorageArgs) {
@@ -3433,7 +3446,7 @@ var StoreWriter = (function () {
3433
3446
  }
3434
3447
  var changedFields_1;
3435
3448
  var getValue_1 = function (from, name) {
3436
- return Array.isArray(from)
3449
+ return isArray(from)
3437
3450
  ? (typeof name === "number" ? from[name] : void 0)
3438
3451
  : context.store.getFieldValue(from, String(name));
3439
3452
  };
@@ -3455,7 +3468,7 @@ var StoreWriter = (function () {
3455
3468
  }
3456
3469
  });
3457
3470
  if (changedFields_1) {
3458
- incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
3471
+ incoming = (isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
3459
3472
  changedFields_1.forEach(function (value, name) {
3460
3473
  incoming[name] = value;
3461
3474
  });
@@ -3523,7 +3536,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3523
3536
  return;
3524
3537
  if (isReference(existing))
3525
3538
  return;
3526
- if (equality.equal(existing, incoming))
3539
+ if (equal.equal(existing, incoming))
3527
3540
  return;
3528
3541
  if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
3529
3542
  return;
@@ -3531,13 +3544,13 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3531
3544
  var parentType = store.getFieldValue(existingRef, "__typename") ||
3532
3545
  store.getFieldValue(incomingObj, "__typename");
3533
3546
  var fieldName = fieldNameFromStoreName(storeFieldName);
3534
- var typeDotName = parentType + "." + fieldName;
3547
+ var typeDotName = "".concat(parentType, ".").concat(fieldName);
3535
3548
  if (warnings.has(typeDotName))
3536
3549
  return;
3537
3550
  warnings.add(typeDotName);
3538
3551
  var childTypenames = [];
3539
- if (!Array.isArray(existing) &&
3540
- !Array.isArray(incoming)) {
3552
+ if (!isArray(existing) &&
3553
+ !isArray(incoming)) {
3541
3554
  [existing, incoming].forEach(function (child) {
3542
3555
  var typename = store.getFieldValue(child, "__typename");
3543
3556
  if (typeof typename === "string" &&
@@ -3546,10 +3559,10 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3546
3559
  }
3547
3560
  });
3548
3561
  }
3549
- __DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the " + fieldName + " field of a " + parentType + " object.\n\nTo address this problem (which is not a bug in Apollo Client), " + (childTypenames.length
3562
+ __DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the ".concat(fieldName, " field of a ").concat(parentType, " object.\n\nTo address this problem (which is not a bug in Apollo Client), ").concat(childTypenames.length
3550
3563
  ? "either ensure all objects of type " +
3551
3564
  childTypenames.join(" and ") + " have an ID or a custom merge function, or "
3552
- : "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
3565
+ : "", "define a custom merge function for the ").concat(typeDotName, " field, so InMemoryCache can safely merge these objects:\n\n existing: ").concat(JSON.stringify(existing).slice(0, 1000), "\n incoming: ").concat(JSON.stringify(incoming).slice(0, 1000), "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n"));
3553
3566
  }
3554
3567
 
3555
3568
  var InMemoryCache = (function (_super) {
@@ -3837,7 +3850,7 @@ var InMemoryCache = (function (_super) {
3837
3850
  return;
3838
3851
  }
3839
3852
  }
3840
- if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
3853
+ if (!lastDiff || !equal.equal(lastDiff.result, diff.result)) {
3841
3854
  c.callback(c.lastDiff = diff, lastDiff);
3842
3855
  }
3843
3856
  };
@@ -3856,11 +3869,11 @@ var generateErrorMessage = function (err) {
3856
3869
  var errorMessage = error
3857
3870
  ? error.message
3858
3871
  : 'Error message not found.';
3859
- message += errorMessage + "\n";
3872
+ message += "".concat(errorMessage, "\n");
3860
3873
  });
3861
3874
  }
3862
3875
  if (err.networkError) {
3863
- message += err.networkError.message + "\n";
3876
+ message += "".concat(err.networkError.message, "\n");
3864
3877
  }
3865
3878
  message = message.replace(/\n$/, '');
3866
3879
  return message;
@@ -3895,8 +3908,7 @@ function isNetworkRequestInFlight(networkStatus) {
3895
3908
  return networkStatus ? networkStatus < 7 : false;
3896
3909
  }
3897
3910
 
3898
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3899
- var warnedAboutUpdateQuery = false;
3911
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3900
3912
  var ObservableQuery = (function (_super) {
3901
3913
  tslib.__extends(ObservableQuery, _super);
3902
3914
  function ObservableQuery(_a) {
@@ -3982,7 +3994,7 @@ var ObservableQuery = (function (_super) {
3982
3994
  if (diff.complete || this.options.returnPartialData) {
3983
3995
  result.data = diff.result;
3984
3996
  }
3985
- if (equality.equal(result.data, {})) {
3997
+ if (equal.equal(result.data, {})) {
3986
3998
  result.data = void 0;
3987
3999
  }
3988
4000
  if (diff.complete) {
@@ -4013,13 +4025,13 @@ var ObservableQuery = (function (_super) {
4013
4025
  return result;
4014
4026
  };
4015
4027
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
4016
- return !this.last || !equality.equal(this.last.result, newResult);
4028
+ return !this.last || !equal.equal(this.last.result, newResult);
4017
4029
  };
4018
4030
  ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
4019
4031
  var last = this.last;
4020
4032
  if (last &&
4021
4033
  last[key] &&
4022
- (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
4034
+ (!variablesMustMatch || equal.equal(last.variables, this.variables))) {
4023
4035
  return last[key];
4024
4036
  }
4025
4037
  };
@@ -4042,7 +4054,7 @@ var ObservableQuery = (function (_super) {
4042
4054
  pollInterval: 0,
4043
4055
  };
4044
4056
  var fetchPolicy = this.options.fetchPolicy;
4045
- if (fetchPolicy === 'standby' || fetchPolicy === 'cache-and-network') {
4057
+ if (fetchPolicy === 'cache-and-network') {
4046
4058
  reobserveOptions.fetchPolicy = fetchPolicy;
4047
4059
  }
4048
4060
  else if (fetchPolicy === 'no-cache') {
@@ -4051,14 +4063,14 @@ var ObservableQuery = (function (_super) {
4051
4063
  else {
4052
4064
  reobserveOptions.fetchPolicy = 'network-only';
4053
4065
  }
4054
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4066
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4055
4067
  var queryDef = getQueryDefinition(this.options.query);
4056
4068
  var vars = queryDef.variableDefinitions;
4057
4069
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4058
- __DEV__ && tsInvariant.invariant.warn("Called refetch(" + JSON.stringify(variables) + ") for query " + (((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef)) + ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?");
4070
+ __DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
4059
4071
  }
4060
4072
  }
4061
- if (variables && !equality.equal(this.options.variables, variables)) {
4073
+ if (variables && !equal.equal(this.options.variables, variables)) {
4062
4074
  reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
4063
4075
  }
4064
4076
  this.queryInfo.resetLastWrite();
@@ -4068,35 +4080,49 @@ var ObservableQuery = (function (_super) {
4068
4080
  var _this = this;
4069
4081
  var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
4070
4082
  var qid = this.queryManager.generateQueryId();
4083
+ var queryInfo = this.queryInfo;
4084
+ var originalNetworkStatus = queryInfo.networkStatus;
4085
+ queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4071
4086
  if (combinedOptions.notifyOnNetworkStatusChange) {
4072
- this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4073
4087
  this.observe();
4074
4088
  }
4089
+ var updatedQuerySet = new Set();
4075
4090
  return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
4076
- var data = fetchMoreResult.data;
4077
- var updateQuery = fetchMoreOptions.updateQuery;
4078
- if (updateQuery) {
4079
- if (__DEV__ &&
4080
- !warnedAboutUpdateQuery) {
4081
- __DEV__ && tsInvariant.invariant.warn("The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.");
4082
- warnedAboutUpdateQuery = true;
4083
- }
4084
- _this.updateQuery(function (previous) { return updateQuery(previous, {
4085
- fetchMoreResult: data,
4086
- variables: combinedOptions.variables,
4087
- }); });
4088
- }
4089
- else {
4090
- _this.queryManager.cache.writeQuery({
4091
- query: combinedOptions.query,
4092
- variables: combinedOptions.variables,
4093
- data: data,
4094
- });
4095
- }
4091
+ _this.queryManager.removeQuery(qid);
4092
+ if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
4093
+ queryInfo.networkStatus = originalNetworkStatus;
4094
+ }
4095
+ _this.queryManager.cache.batch({
4096
+ update: function (cache) {
4097
+ var updateQuery = fetchMoreOptions.updateQuery;
4098
+ if (updateQuery) {
4099
+ cache.updateQuery({
4100
+ query: _this.options.query,
4101
+ variables: _this.variables,
4102
+ returnPartialData: true,
4103
+ optimistic: false,
4104
+ }, function (previous) { return updateQuery(previous, {
4105
+ fetchMoreResult: fetchMoreResult.data,
4106
+ variables: combinedOptions.variables,
4107
+ }); });
4108
+ }
4109
+ else {
4110
+ cache.writeQuery({
4111
+ query: combinedOptions.query,
4112
+ variables: combinedOptions.variables,
4113
+ data: fetchMoreResult.data,
4114
+ });
4115
+ }
4116
+ },
4117
+ onWatchUpdated: function (watch) {
4118
+ updatedQuerySet.add(watch.query);
4119
+ },
4120
+ });
4096
4121
  return fetchMoreResult;
4097
4122
  }).finally(function () {
4098
- _this.queryManager.stopQuery(qid);
4099
- _this.reobserve();
4123
+ if (!updatedQuerySet.has(_this.options.query)) {
4124
+ reobserveCacheFirst(_this);
4125
+ }
4100
4126
  });
4101
4127
  };
4102
4128
  ObservableQuery.prototype.subscribeToMore = function (options) {
@@ -4139,7 +4165,7 @@ var ObservableQuery = (function (_super) {
4139
4165
  return this.reobserve(newOptions);
4140
4166
  };
4141
4167
  ObservableQuery.prototype.setVariables = function (variables) {
4142
- if (equality.equal(this.variables, variables)) {
4168
+ if (equal.equal(this.variables, variables)) {
4143
4169
  return this.observers.size
4144
4170
  ? this.result()
4145
4171
  : Promise.resolve();
@@ -4181,6 +4207,27 @@ var ObservableQuery = (function (_super) {
4181
4207
  this.options.pollInterval = 0;
4182
4208
  this.updatePolling();
4183
4209
  };
4210
+ ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
4211
+ if (options === void 0) { options = this.options; }
4212
+ if (options.nextFetchPolicy) {
4213
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
4214
+ if (typeof options.nextFetchPolicy === "function") {
4215
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
4216
+ reason: reason,
4217
+ options: options,
4218
+ observable: this,
4219
+ initialPolicy: this.initialFetchPolicy,
4220
+ });
4221
+ }
4222
+ else if (reason === "variables-changed") {
4223
+ options.fetchPolicy = this.initialFetchPolicy;
4224
+ }
4225
+ else {
4226
+ options.fetchPolicy = options.nextFetchPolicy;
4227
+ }
4228
+ }
4229
+ return options.fetchPolicy;
4230
+ };
4184
4231
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4185
4232
  this.queryManager.setObservableQuery(this);
4186
4233
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -4251,8 +4298,8 @@ var ObservableQuery = (function (_super) {
4251
4298
  if (newOptions &&
4252
4299
  newOptions.variables &&
4253
4300
  !newOptions.fetchPolicy &&
4254
- !equality.equal(newOptions.variables, oldVariables)) {
4255
- options.fetchPolicy = this.initialFetchPolicy;
4301
+ !equal.equal(newOptions.variables, oldVariables)) {
4302
+ this.applyNextFetchPolicy("variables-changed");
4256
4303
  if (newNetworkStatus === void 0) {
4257
4304
  newNetworkStatus = exports.NetworkStatus.setVariables;
4258
4305
  }
@@ -4282,8 +4329,11 @@ var ObservableQuery = (function (_super) {
4282
4329
  this.reportResult(this.getCurrentResult(false), this.variables);
4283
4330
  };
4284
4331
  ObservableQuery.prototype.reportResult = function (result, variables) {
4285
- if (this.getLastError() || this.isDifferentFromLastResult(result)) {
4286
- this.updateLastResult(result, variables);
4332
+ var lastError = this.getLastError();
4333
+ if (lastError || this.isDifferentFromLastResult(result)) {
4334
+ if (lastError || !result.partial || this.options.returnPartialData) {
4335
+ this.updateLastResult(result, variables);
4336
+ }
4287
4337
  iterateObserversSafely(this.observers, 'next', result);
4288
4338
  }
4289
4339
  };
@@ -4313,20 +4363,29 @@ var ObservableQuery = (function (_super) {
4313
4363
  return ObservableQuery;
4314
4364
  }(zenObservableTs.Observable));
4315
4365
  fixObservableSubclass(ObservableQuery);
4366
+ function reobserveCacheFirst(obsQuery) {
4367
+ var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
4368
+ if (fetchPolicy === "cache-and-network" ||
4369
+ fetchPolicy === "network-only") {
4370
+ return obsQuery.reobserve({
4371
+ fetchPolicy: "cache-first",
4372
+ nextFetchPolicy: function () {
4373
+ this.nextFetchPolicy = nextFetchPolicy;
4374
+ if (typeof nextFetchPolicy === "function") {
4375
+ return nextFetchPolicy.apply(this, arguments);
4376
+ }
4377
+ return fetchPolicy;
4378
+ },
4379
+ });
4380
+ }
4381
+ return obsQuery.reobserve();
4382
+ }
4316
4383
  function defaultSubscriptionObserverErrorCallback(error) {
4317
4384
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4318
4385
  }
4319
4386
  function logMissingFieldErrors(missing) {
4320
4387
  if (__DEV__ && missing) {
4321
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + JSON.stringify(missing), missing);
4322
- }
4323
- }
4324
- function applyNextFetchPolicy(options) {
4325
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
4326
- if (nextFetchPolicy) {
4327
- options.fetchPolicy = typeof nextFetchPolicy === "function"
4328
- ? nextFetchPolicy.call(options, fetchPolicy)
4329
- : nextFetchPolicy;
4388
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4330
4389
  }
4331
4390
  }
4332
4391
 
@@ -4499,7 +4558,7 @@ var LocalState = (function () {
4499
4558
  }
4500
4559
  else {
4501
4560
  fragment = fragmentMap[selection.name.value];
4502
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 9);
4561
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value)) : tsInvariant.invariant(fragment, 9);
4503
4562
  }
4504
4563
  if (fragment && fragment.typeCondition) {
4505
4564
  typeCondition = fragment.typeCondition.name.value;
@@ -4630,10 +4689,10 @@ var QueryInfo = (function () {
4630
4689
  var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
4631
4690
  if (this.variables &&
4632
4691
  this.networkStatus !== exports.NetworkStatus.loading &&
4633
- !equality.equal(this.variables, query.variables)) {
4692
+ !equal.equal(this.variables, query.variables)) {
4634
4693
  networkStatus = exports.NetworkStatus.setVariables;
4635
4694
  }
4636
- if (!equality.equal(query.variables, this.variables)) {
4695
+ if (!equal.equal(query.variables, this.variables)) {
4637
4696
  this.lastDiff = void 0;
4638
4697
  }
4639
4698
  Object.assign(this, {
@@ -4659,7 +4718,7 @@ var QueryInfo = (function () {
4659
4718
  QueryInfo.prototype.getDiff = function (variables) {
4660
4719
  if (variables === void 0) { variables = this.variables; }
4661
4720
  var options = this.getDiffOptions(variables);
4662
- if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
4721
+ if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
4663
4722
  return this.lastDiff.diff;
4664
4723
  }
4665
4724
  this.updateWatch(this.variables = variables);
@@ -4693,7 +4752,7 @@ var QueryInfo = (function () {
4693
4752
  var oldDiff = this.lastDiff && this.lastDiff.diff;
4694
4753
  this.updateLastDiff(diff);
4695
4754
  if (!this.dirty &&
4696
- !equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4755
+ !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
4697
4756
  this.dirty = true;
4698
4757
  if (!this.notifyTimeout) {
4699
4758
  this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
@@ -4711,11 +4770,12 @@ var QueryInfo = (function () {
4711
4770
  if (oq) {
4712
4771
  oq["queryInfo"] = this;
4713
4772
  this.listeners.add(this.oqListener = function () {
4714
- if (_this.getDiff().fromOptimisticTransaction) {
4773
+ var diff = _this.getDiff();
4774
+ if (diff.fromOptimisticTransaction) {
4715
4775
  oq["observe"]();
4716
4776
  }
4717
4777
  else {
4718
- oq.reobserve();
4778
+ reobserveCacheFirst(oq);
4719
4779
  }
4720
4780
  });
4721
4781
  }
@@ -4767,7 +4827,7 @@ var QueryInfo = (function () {
4767
4827
  }
4768
4828
  var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
4769
4829
  if (!this.lastWatch ||
4770
- !equality.equal(watchOptions, this.lastWatch)) {
4830
+ !equal.equal(watchOptions, this.lastWatch)) {
4771
4831
  this.cancel();
4772
4832
  this.cancel = this.cache.watch(this.lastWatch = watchOptions);
4773
4833
  }
@@ -4779,8 +4839,8 @@ var QueryInfo = (function () {
4779
4839
  var lastWrite = this.lastWrite;
4780
4840
  return !(lastWrite &&
4781
4841
  lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
4782
- equality.equal(variables, lastWrite.variables) &&
4783
- equality.equal(result.data, lastWrite.result.data));
4842
+ equal.equal(variables, lastWrite.variables) &&
4843
+ equal.equal(result.data, lastWrite.result.data));
4784
4844
  };
4785
4845
  QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
4786
4846
  var _this = this;
@@ -4857,10 +4917,10 @@ function shouldWriteResult(result, errorPolicy) {
4857
4917
  return writeWithErrors;
4858
4918
  }
4859
4919
 
4860
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4920
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4861
4921
  var QueryManager = (function () {
4862
4922
  function QueryManager(_a) {
4863
- var cache = _a.cache, link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
4923
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
4864
4924
  this.clientAwareness = {};
4865
4925
  this.queries = new Map();
4866
4926
  this.fetchCancelFns = new Map();
@@ -4871,6 +4931,7 @@ var QueryManager = (function () {
4871
4931
  this.inFlightLinkObservables = new Map();
4872
4932
  this.cache = cache;
4873
4933
  this.link = link;
4934
+ this.defaultOptions = defaultOptions || Object.create(null);
4874
4935
  this.queryDeduplication = queryDeduplication;
4875
4936
  this.clientAwareness = clientAwareness;
4876
4937
  this.localState = localState || new LocalState({ cache: cache });
@@ -4892,11 +4953,12 @@ var QueryManager = (function () {
4892
4953
  this.fetchCancelFns.clear();
4893
4954
  };
4894
4955
  QueryManager.prototype.mutate = function (_a) {
4895
- 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;
4956
+ var _b, _c;
4957
+ var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
4896
4958
  return tslib.__awaiter(this, void 0, void 0, function () {
4897
4959
  var mutationId, mutationStoreValue, self;
4898
- return tslib.__generator(this, function (_f) {
4899
- switch (_f.label) {
4960
+ return tslib.__generator(this, function (_h) {
4961
+ switch (_h.label) {
4900
4962
  case 0:
4901
4963
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4902
4964
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4908,8 +4970,8 @@ var QueryManager = (function () {
4908
4970
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4909
4971
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4910
4972
  case 1:
4911
- variables = (_f.sent());
4912
- _f.label = 2;
4973
+ variables = (_h.sent());
4974
+ _h.label = 2;
4913
4975
  case 2:
4914
4976
  mutationStoreValue = this.mutationStore &&
4915
4977
  (this.mutationStore[mutationId] = {
@@ -5010,7 +5072,7 @@ var QueryManager = (function () {
5010
5072
  this.queries.forEach(function (_a, queryId) {
5011
5073
  var observableQuery = _a.observableQuery;
5012
5074
  var queryName = observableQuery && observableQuery.queryName;
5013
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5075
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5014
5076
  return;
5015
5077
  }
5016
5078
  var updater = updateQueries_1[queryName];
@@ -5290,7 +5352,7 @@ var QueryManager = (function () {
5290
5352
  if (__DEV__ && queryNamesAndDocs.size) {
5291
5353
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
5292
5354
  if (!included) {
5293
- __DEV__ && tsInvariant.invariant.warn("Unknown query " + (typeof nameOrDoc === "string" ? "named " : "") + JSON.stringify(nameOrDoc, null, 2) + " requested in refetchQueries options.include array");
5355
+ __DEV__ && tsInvariant.invariant.warn("Unknown query ".concat(typeof nameOrDoc === "string" ? "named " : "").concat(JSON.stringify(nameOrDoc, null, 2), " requested in refetchQueries options.include array"));
5294
5356
  }
5295
5357
  });
5296
5358
  }
@@ -5362,8 +5424,10 @@ var QueryManager = (function () {
5362
5424
  };
5363
5425
  QueryManager.prototype.removeQuery = function (queryId) {
5364
5426
  this.fetchCancelFns.delete(queryId);
5365
- this.getQuery(queryId).stop();
5366
- this.queries.delete(queryId);
5427
+ if (this.queries.has(queryId)) {
5428
+ this.getQuery(queryId).stop();
5429
+ this.queries.delete(queryId);
5430
+ }
5367
5431
  };
5368
5432
  QueryManager.prototype.broadcastQueries = function () {
5369
5433
  if (this.onBroadcast)
@@ -5469,7 +5533,8 @@ var QueryManager = (function () {
5469
5533
  var query = this.transform(options.query).document;
5470
5534
  var variables = this.getVariables(query, options.variables);
5471
5535
  var queryInfo = this.getQuery(queryId);
5472
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
5536
+ var defaults = this.defaultOptions.watchQuery;
5537
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? defaults && defaults.fetchPolicy || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? defaults && defaults.errorPolicy || "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
5473
5538
  var normalized = Object.assign({}, options, {
5474
5539
  query: query,
5475
5540
  variables: variables,
@@ -5491,7 +5556,9 @@ var QueryManager = (function () {
5491
5556
  : fromVariables(normalized.variables));
5492
5557
  concast.cleanup(function () {
5493
5558
  _this.fetchCancelFns.delete(queryId);
5494
- applyNextFetchPolicy(options);
5559
+ if (queryInfo.observableQuery) {
5560
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
5561
+ }
5495
5562
  });
5496
5563
  return concast;
5497
5564
  };
@@ -5578,7 +5645,7 @@ var QueryManager = (function () {
5578
5645
  var data = diff.result;
5579
5646
  if (__DEV__ &&
5580
5647
  !returnPartialData &&
5581
- !equality.equal(data, {})) {
5648
+ !equal.equal(data, {})) {
5582
5649
  logMissingFieldErrors(diff.missing);
5583
5650
  }
5584
5651
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
@@ -5687,7 +5754,6 @@ function mergeOptions(defaults, options) {
5687
5754
  var ApolloClient = (function () {
5688
5755
  function ApolloClient(options) {
5689
5756
  var _this = this;
5690
- this.defaultOptions = {};
5691
5757
  this.resetStoreCallbacks = [];
5692
5758
  this.clearStoreCallbacks = [];
5693
5759
  var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
@@ -5708,7 +5774,7 @@ var ApolloClient = (function () {
5708
5774
  this.cache = cache;
5709
5775
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5710
5776
  this.queryDeduplication = queryDeduplication;
5711
- this.defaultOptions = defaultOptions || {};
5777
+ this.defaultOptions = defaultOptions || Object.create(null);
5712
5778
  this.typeDefs = typeDefs;
5713
5779
  if (ssrForceFetchDelay) {
5714
5780
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5755,6 +5821,7 @@ var ApolloClient = (function () {
5755
5821
  this.queryManager = new QueryManager({
5756
5822
  cache: this.cache,
5757
5823
  link: this.link,
5824
+ defaultOptions: this.defaultOptions,
5758
5825
  queryDeduplication: queryDeduplication,
5759
5826
  ssrMode: ssrMode,
5760
5827
  clientAwareness: {
@@ -5881,7 +5948,7 @@ var ApolloClient = (function () {
5881
5948
  result.queries = queries;
5882
5949
  result.results = results;
5883
5950
  result.catch(function (error) {
5884
- __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
5951
+ __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error ".concat(error));
5885
5952
  });
5886
5953
  return result;
5887
5954
  };
@@ -5957,8 +6024,8 @@ function useApolloClient(override) {
5957
6024
  var context = React.useContext(getApolloContext());
5958
6025
  var client = override || context.client;
5959
6026
  __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5960
- 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient' +
5961
- 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 29);
6027
+ 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
6028
+ 'instance in via options.') : tsInvariant.invariant(!!client, 29);
5962
6029
  return client;
5963
6030
  }
5964
6031
 
@@ -5989,7 +6056,7 @@ function parser(document) {
5989
6056
  if (cached)
5990
6057
  return cached;
5991
6058
  var variables, type, name;
5992
- __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
6059
+ __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
5993
6060
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
5994
6061
  "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
5995
6062
  var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
@@ -6007,8 +6074,8 @@ function parser(document) {
6007
6074
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6008
6075
  (queries.length || mutations.length || subscriptions.length), 31);
6009
6076
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6010
- (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
6011
- ("subscriptions and " + mutations.length + " mutations. ") +
6077
+ "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6078
+ "subscriptions and ".concat(mutations.length, " mutations. ") +
6012
6079
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
6013
6080
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6014
6081
  if (!queries.length && !mutations.length)
@@ -6018,8 +6085,8 @@ function parser(document) {
6018
6085
  : mutations.length
6019
6086
  ? mutations
6020
6087
  : subscriptions;
6021
- __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
6022
- (definitions.length + " definitions. ") +
6088
+ __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6089
+ "".concat(definitions.length, " definitions. ") +
6023
6090
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 33);
6024
6091
  var definition = definitions[0];
6025
6092
  variables = definition.variableDefinitions || [];
@@ -6037,182 +6104,278 @@ function verifyDocumentType(document, type) {
6037
6104
  var operation = parser(document);
6038
6105
  var requiredOperationName = operationName(type);
6039
6106
  var usedOperationName = operationName(operation.type);
6040
- __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
6041
- (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6107
+ __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6108
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6042
6109
  }
6043
6110
 
6044
- function useQuery(query, options) {
6045
- var _a;
6046
- var context = React.useContext(getApolloContext());
6047
- var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6048
- verifyDocumentType(query, exports.DocumentType.Query);
6049
- var ref = React.useRef({
6050
- client: client,
6051
- query: query,
6052
- options: options,
6053
- watchQueryOptions: createWatchQueryOptions(query, options),
6054
- });
6055
- var _b = React.useState(function () {
6056
- var watchQueryOptions = createWatchQueryOptions(query, options);
6057
- var obsQuery = null;
6058
- if (context.renderPromises) {
6059
- obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
6060
- }
6061
- if (!obsQuery) {
6062
- obsQuery = client.watchQuery(watchQueryOptions);
6063
- if (context.renderPromises) {
6064
- context.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
6065
- }
6066
- }
6067
- if (context.renderPromises &&
6068
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6069
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6070
- obsQuery.getCurrentResult().loading) {
6071
- context.renderPromises.addQueryPromise({
6072
- getOptions: function () { return createWatchQueryOptions(query, options); },
6073
- fetchData: function () { return new Promise(function (resolve) {
6074
- var sub = obsQuery.subscribe({
6075
- next: function (result) {
6076
- if (!result.loading) {
6111
+ function useNormalizedOptions(optionsOrFunction) {
6112
+ var optionsRef = React.useRef();
6113
+ var options = optionsRef.current || Object.create(null);
6114
+ if (typeof optionsOrFunction === "function") {
6115
+ var newOptions = optionsOrFunction(options);
6116
+ if (newOptions !== options) {
6117
+ Object.assign(options, newOptions, newOptions.variables && {
6118
+ variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
6119
+ });
6120
+ }
6121
+ }
6122
+ else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
6123
+ options = optionsOrFunction;
6124
+ }
6125
+ return optionsRef.current = options;
6126
+ }
6127
+
6128
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6129
+ function useQuery(query, optionsOrFunction) {
6130
+ var options = useNormalizedOptions(optionsOrFunction);
6131
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6132
+ }
6133
+ function useInternalState(client, query) {
6134
+ var stateRef = React.useRef();
6135
+ if (!stateRef.current ||
6136
+ client !== stateRef.current.client ||
6137
+ query !== stateRef.current.query) {
6138
+ stateRef.current = new InternalState(client, query);
6139
+ }
6140
+ var state = stateRef.current;
6141
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6142
+ state.forceUpdate = function () {
6143
+ setTick(function (tick) { return tick + 1; });
6144
+ };
6145
+ return state;
6146
+ }
6147
+ var InternalState = (function () {
6148
+ function InternalState(client, query) {
6149
+ this.client = client;
6150
+ this.query = query;
6151
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6152
+ verifyDocumentType(query, exports.DocumentType.Query);
6153
+ }
6154
+ InternalState.prototype.forceUpdate = function () {
6155
+ };
6156
+ InternalState.prototype.useQuery = function (options) {
6157
+ this.useOptions(options);
6158
+ var obsQuery = this.useObservableQuery();
6159
+ this.useSubscriptionEffect(obsQuery);
6160
+ var result = this.getCurrentResult();
6161
+ this.unsafeHandlePartialRefetch(result);
6162
+ return this.toQueryResult(result);
6163
+ };
6164
+ InternalState.prototype.useOptions = function (options) {
6165
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6166
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6167
+ if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
6168
+ this.watchQueryOptions = watchQueryOptions;
6169
+ }
6170
+ this.ssrDisabled = !!(options && (options.ssr === false ||
6171
+ options.skip));
6172
+ this.onCompleted = options
6173
+ && options.onCompleted
6174
+ || InternalState.prototype.onCompleted;
6175
+ this.onError = options
6176
+ && options.onError
6177
+ || InternalState.prototype.onError;
6178
+ };
6179
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6180
+ var _b;
6181
+ if (_a === void 0) { _a = {}; }
6182
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6183
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6184
+ if (skip) {
6185
+ watchQueryOptions.fetchPolicy = 'standby';
6186
+ }
6187
+ else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
6188
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6189
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6190
+ watchQueryOptions.fetchPolicy = 'cache-first';
6191
+ }
6192
+ else if (!watchQueryOptions.fetchPolicy) {
6193
+ var defaultOptions = this.client.defaultOptions.watchQuery;
6194
+ watchQueryOptions.fetchPolicy =
6195
+ defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
6196
+ }
6197
+ if (!watchQueryOptions.variables) {
6198
+ watchQueryOptions.variables = {};
6199
+ }
6200
+ return watchQueryOptions;
6201
+ };
6202
+ InternalState.prototype.onCompleted = function (data) { };
6203
+ InternalState.prototype.onError = function (error) { };
6204
+ InternalState.prototype.useObservableQuery = function () {
6205
+ var _this = this;
6206
+ var obsQuery = this.observable =
6207
+ this.renderPromises
6208
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6209
+ || this.observable
6210
+ || this.client.watchQuery(this.watchQueryOptions);
6211
+ this.obsQueryFields = React.useMemo(function () { return ({
6212
+ refetch: obsQuery.refetch.bind(obsQuery),
6213
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6214
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6215
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6216
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6217
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6218
+ }); }, [obsQuery]);
6219
+ if (this.renderPromises) {
6220
+ this.renderPromises.registerSSRObservable(obsQuery);
6221
+ if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
6222
+ this.renderPromises.addQueryPromise({
6223
+ getOptions: function () { return obsQuery.options; },
6224
+ fetchData: function () { return new Promise(function (resolve) {
6225
+ var sub = obsQuery.subscribe({
6226
+ next: function (result) {
6227
+ if (!result.loading) {
6228
+ resolve();
6229
+ sub.unsubscribe();
6230
+ }
6231
+ },
6232
+ error: function () {
6077
6233
  resolve();
6078
6234
  sub.unsubscribe();
6079
- }
6080
- },
6081
- error: function () {
6082
- resolve();
6083
- sub.unsubscribe();
6084
- },
6085
- complete: function () {
6086
- resolve();
6087
- },
6088
- });
6089
- }); },
6090
- }, function () { return null; });
6091
- }
6092
- return obsQuery;
6093
- }), obsQuery = _b[0], setObsQuery = _b[1];
6094
- React.useEffect(function () {
6095
- var watchQueryOptions = createWatchQueryOptions(query, options);
6096
- if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
6097
- var obsQuery_1 = client.watchQuery(watchQueryOptions);
6098
- setObsQuery(obsQuery_1);
6099
- }
6100
- else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6101
- obsQuery.setOptions(watchQueryOptions);
6102
- setObsQuery(obsQuery);
6235
+ },
6236
+ complete: function () {
6237
+ resolve();
6238
+ },
6239
+ });
6240
+ }); },
6241
+ }, function () { return null; });
6242
+ obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
6243
+ }
6103
6244
  }
6104
- Object.assign(ref.current, {
6105
- client: client,
6106
- query: query,
6107
- options: options,
6108
- watchQueryOptions: watchQueryOptions,
6245
+ var prevOptionsRef = React.useRef({
6246
+ watchQueryOptions: this.watchQueryOptions,
6109
6247
  });
6110
- }, [obsQuery, client, query, options]);
6111
- var _c = React.useMemo(function () {
6112
- var previousResult;
6113
- var subscribe = function (forceUpdate) {
6114
- var subscription = obsQuery.subscribe(forceUpdate, onError);
6115
- function onError(error) {
6116
- forceUpdate();
6117
- subscription.unsubscribe();
6248
+ React.useEffect(function () {
6249
+ if (_this.renderPromises) ;
6250
+ else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
6251
+ obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
6252
+ prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
6253
+ _this.setResult(obsQuery.getCurrentResult());
6254
+ }
6255
+ }, [obsQuery, this.watchQueryOptions]);
6256
+ return obsQuery;
6257
+ };
6258
+ InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
6259
+ var _this = this;
6260
+ React.useEffect(function () {
6261
+ if (_this.renderPromises) {
6262
+ return;
6263
+ }
6264
+ var onNext = function () {
6265
+ var previousResult = _this.result;
6266
+ var result = obsQuery.getCurrentResult();
6267
+ if (previousResult &&
6268
+ previousResult.loading === result.loading &&
6269
+ previousResult.networkStatus === result.networkStatus &&
6270
+ equal.equal(previousResult.data, result.data)) {
6271
+ return;
6272
+ }
6273
+ _this.setResult(result);
6274
+ };
6275
+ var onError = function (error) {
6118
6276
  var last = obsQuery["last"];
6119
- obsQuery.resetLastResults();
6120
- obsQuery.subscribe(forceUpdate, onError);
6121
- obsQuery["last"] = last;
6122
- if (!error.hasOwnProperty('graphQLErrors')) {
6277
+ subscription.unsubscribe();
6278
+ try {
6279
+ obsQuery.resetLastResults();
6280
+ subscription = obsQuery.subscribe(onNext, onError);
6281
+ }
6282
+ finally {
6283
+ obsQuery["last"] = last;
6284
+ }
6285
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6123
6286
  throw error;
6124
6287
  }
6125
- }
6126
- return function () {
6127
- subscription.unsubscribe();
6128
- };
6129
- };
6130
- var getSnapshot = function () {
6131
- var result = obsQuery.getCurrentResult();
6132
- if (result.errors && result.errors.length) {
6133
- result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6134
- }
6135
- if (!previousResult ||
6136
- previousResult.loading !== result.loading ||
6137
- previousResult.networkStatus !== result.networkStatus ||
6138
- !equality.equal(previousResult.data, result.data) ||
6139
- !equality.equal(previousResult.error, result.error)) {
6140
- if (previousResult) {
6141
- result = tslib.__assign(tslib.__assign({}, result), { previousData: previousResult.data || previousResult.previousData });
6288
+ var previousResult = _this.result;
6289
+ if (!previousResult ||
6290
+ (previousResult && previousResult.loading) ||
6291
+ !equal.equal(error, previousResult.error)) {
6292
+ _this.setResult({
6293
+ data: (previousResult && previousResult.data),
6294
+ error: error,
6295
+ loading: false,
6296
+ networkStatus: exports.NetworkStatus.error,
6297
+ });
6142
6298
  }
6143
- previousResult = result;
6144
- }
6145
- return previousResult;
6146
- };
6147
- return [subscribe, getSnapshot];
6148
- }, [obsQuery]), subscribe = _c[0], getSnapshot = _c[1];
6149
- var obsQueryMethods = React.useMemo(function () { return ({
6150
- refetch: obsQuery.refetch.bind(obsQuery),
6151
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
6152
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
6153
- startPolling: obsQuery.startPolling.bind(obsQuery),
6154
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
6155
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6156
- }); }, [obsQuery]);
6157
- var result = shim.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
6158
- React.useEffect(function () {
6159
- var _a, _b, _c, _d, _e, _f;
6160
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) ||
6161
- ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) === 'standby') {
6162
- return;
6163
- }
6299
+ };
6300
+ var subscription = obsQuery.subscribe(onNext, onError);
6301
+ return function () { return subscription.unsubscribe(); };
6302
+ }, [
6303
+ obsQuery,
6304
+ this.renderPromises,
6305
+ this.client.disableNetworkFetches,
6306
+ ]);
6307
+ };
6308
+ InternalState.prototype.setResult = function (nextResult) {
6309
+ var previousResult = this.result;
6310
+ if (previousResult && previousResult.data) {
6311
+ this.previousData = previousResult.data;
6312
+ }
6313
+ this.result = nextResult;
6314
+ this.forceUpdate();
6315
+ this.handleErrorOrCompleted(nextResult);
6316
+ };
6317
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6164
6318
  if (!result.loading) {
6165
6319
  if (result.error) {
6166
- (_d = (_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.onError) === null || _d === void 0 ? void 0 : _d.call(_c, result.error);
6320
+ this.onError(result.error);
6167
6321
  }
6168
6322
  else if (result.data) {
6169
- (_f = (_e = ref.current.options) === null || _e === void 0 ? void 0 : _e.onCompleted) === null || _f === void 0 ? void 0 : _f.call(_e, result.data);
6170
- }
6171
- }
6172
- }, [result]);
6173
- var partial;
6174
- (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
6175
- if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6176
- result = {
6177
- loading: false,
6178
- data: void 0,
6179
- error: void 0,
6180
- networkStatus: exports.NetworkStatus.ready,
6181
- };
6182
- }
6183
- else {
6184
- if (partial &&
6185
- (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
6323
+ this.onCompleted(result.data);
6324
+ }
6325
+ }
6326
+ };
6327
+ InternalState.prototype.getCurrentResult = function () {
6328
+ var result = this.result;
6329
+ if (!result) {
6330
+ result = this.result = this.observable.getCurrentResult();
6331
+ this.handleErrorOrCompleted(result);
6332
+ }
6333
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6334
+ this.queryHookOptions.ssr === false) {
6335
+ result = {
6336
+ loading: true,
6337
+ data: void 0,
6338
+ error: void 0,
6339
+ networkStatus: exports.NetworkStatus.loading,
6340
+ };
6341
+ }
6342
+ else if (this.queryHookOptions.skip ||
6343
+ this.queryHookOptions.fetchPolicy === 'standby') {
6344
+ result = {
6345
+ loading: false,
6346
+ data: void 0,
6347
+ error: void 0,
6348
+ networkStatus: exports.NetworkStatus.ready,
6349
+ };
6350
+ }
6351
+ return result;
6352
+ };
6353
+ InternalState.prototype.toQueryResult = function (result) {
6354
+ var queryResult = this.toQueryResultCache.get(result);
6355
+ if (queryResult)
6356
+ return queryResult;
6357
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6358
+ this.toQueryResultCache.set(result, queryResult = tslib.__assign(tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: true, previousData: this.previousData }));
6359
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6360
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6361
+ }
6362
+ return queryResult;
6363
+ };
6364
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6365
+ if (result.partial &&
6366
+ this.queryHookOptions.partialRefetch &&
6186
6367
  !result.loading &&
6187
6368
  (!result.data || Object.keys(result.data).length === 0) &&
6188
- obsQuery.options.fetchPolicy !== 'cache-only') {
6189
- result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
6190
- obsQuery.refetch();
6191
- }
6192
- if (context.renderPromises && (options === null || options === void 0 ? void 0 : options.ssr) !== false && result.loading) {
6193
- obsQuery.setOptions(createWatchQueryOptions(query, options))
6194
- .catch(function () { });
6369
+ this.observable.options.fetchPolicy !== 'cache-only') {
6370
+ Object.assign(result, {
6371
+ loading: true,
6372
+ networkStatus: exports.NetworkStatus.refetch,
6373
+ });
6374
+ this.observable.refetch();
6195
6375
  }
6196
- }
6197
- return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryMethods), { variables: obsQuery.variables, client: client, called: true }), result);
6198
- }
6199
- function createWatchQueryOptions(query, options) {
6200
- var _a;
6201
- if (options === void 0) { options = {}; }
6202
- var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var watchQueryOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6203
- if (skip) {
6204
- watchQueryOptions.fetchPolicy = 'standby';
6205
- }
6206
- else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
6207
- (watchQueryOptions.fetchPolicy === 'network-only' ||
6208
- watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6209
- watchQueryOptions.fetchPolicy = 'cache-first';
6210
- }
6211
- else if (!watchQueryOptions.fetchPolicy) {
6212
- watchQueryOptions.fetchPolicy = 'cache-first';
6213
- }
6214
- return tslib.__assign({ query: query }, watchQueryOptions);
6215
- }
6376
+ };
6377
+ return InternalState;
6378
+ }());
6216
6379
 
6217
6380
  var EAGER_METHODS = [
6218
6381
  'refetch',
@@ -6221,39 +6384,20 @@ var EAGER_METHODS = [
6221
6384
  'startPolling',
6222
6385
  'subscribeToMore',
6223
6386
  ];
6224
- function useLazyQuery(query, options) {
6387
+ function useLazyQuery(query, optionsOrFunction) {
6388
+ var options = useNormalizedOptions(optionsOrFunction);
6225
6389
  var _a = React.useState({
6226
6390
  called: false,
6227
- resolves: [],
6228
6391
  }), execution = _a[0], setExecution = _a[1];
6229
- var execute = React.useCallback(function (executeOptions) {
6230
- var resolve;
6231
- var promise = new Promise(function (resolve1) { return (resolve = resolve1); });
6232
- setExecution(function (execution) {
6233
- if (execution.called) {
6234
- result && result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables);
6235
- }
6236
- return {
6237
- called: true,
6238
- resolves: tslib.__spreadArray(tslib.__spreadArray([], execution.resolves, true), [resolve], false),
6239
- options: executeOptions,
6240
- };
6241
- });
6242
- return promise;
6243
- }, []);
6244
6392
  var result = useQuery(query, tslib.__assign(tslib.__assign(tslib.__assign({}, options), execution.options), { fetchPolicy: execution.called ? options === null || options === void 0 ? void 0 : options.fetchPolicy : 'standby', skip: undefined }));
6245
- React.useEffect(function () {
6246
- var resolves = execution.resolves;
6247
- if (!result.loading && resolves.length) {
6248
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { resolves: [] })); });
6249
- resolves.forEach(function (resolve) { return resolve(result); });
6250
- }
6251
- }, [result, execution]);
6252
6393
  if (!execution.called) {
6253
6394
  result = tslib.__assign(tslib.__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
6395
+ }
6396
+ var eagerMethods = React.useMemo(function () {
6397
+ var eagerMethods = {};
6254
6398
  var _loop_1 = function (key) {
6255
6399
  var method = result[key];
6256
- result[key] = function () {
6400
+ eagerMethods[key] = function () {
6257
6401
  var args = [];
6258
6402
  for (var _i = 0; _i < arguments.length; _i++) {
6259
6403
  args[_i] = arguments[_i];
@@ -6266,7 +6410,20 @@ function useLazyQuery(query, options) {
6266
6410
  var key = EAGER_METHODS_1[_i];
6267
6411
  _loop_1(key);
6268
6412
  }
6269
- }
6413
+ return eagerMethods;
6414
+ }, []);
6415
+ result.error = result.error || void 0;
6416
+ Object.assign(result, eagerMethods);
6417
+ var execute = React.useCallback(function (executeOptions) {
6418
+ setExecution({ called: true, options: executeOptions });
6419
+ var promise = result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables).then(function (result1) {
6420
+ var result2 = tslib.__assign(tslib.__assign({}, result), { data: result1.data, error: result1.error, called: true, loading: false });
6421
+ Object.assign(result2, eagerMethods);
6422
+ return result2;
6423
+ });
6424
+ promise.catch(function () { });
6425
+ return promise;
6426
+ }, []);
6270
6427
  return [execute, result];
6271
6428
  }
6272
6429
 
@@ -6282,79 +6439,73 @@ function useMutation(mutation, options) {
6282
6439
  result: result,
6283
6440
  mutationId: 0,
6284
6441
  isMounted: true,
6285
- execute: null,
6286
6442
  client: client,
6287
6443
  mutation: mutation,
6288
6444
  options: options,
6289
6445
  });
6290
- var execute = React.useMemo(function () {
6291
- if (ref.current.execute != null &&
6292
- ref.current.client === client &&
6293
- equality.equal(options, ref.current.options) &&
6294
- equality.equal(mutation, ref.current.mutation)) {
6295
- return ref.current.execute;
6296
- }
6297
- ref.current.client = client;
6298
- ref.current.options = options;
6299
- ref.current.mutation = mutation;
6300
- ref.current.execute = function (executeOptions) {
6301
- if (executeOptions === void 0) { executeOptions = {}; }
6302
- var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6303
- if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6304
- setResult(ref.current.result = {
6305
- loading: true,
6306
- error: void 0,
6307
- data: void 0,
6446
+ {
6447
+ Object.assign(ref.current, { client: client, options: options, mutation: mutation });
6448
+ }
6449
+ var execute = React.useCallback(function (executeOptions) {
6450
+ if (executeOptions === void 0) { executeOptions = {}; }
6451
+ var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
6452
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6453
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6454
+ setResult(ref.current.result = {
6455
+ loading: true,
6456
+ error: void 0,
6457
+ data: void 0,
6458
+ called: true,
6459
+ client: client,
6460
+ });
6461
+ }
6462
+ var mutationId = ++ref.current.mutationId;
6463
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
6464
+ return client.mutate(clientOptions).then(function (response) {
6465
+ var _a, _b;
6466
+ var data = response.data, errors = response.errors;
6467
+ var error = errors && errors.length > 0
6468
+ ? new ApolloError({ graphQLErrors: errors })
6469
+ : void 0;
6470
+ if (mutationId === ref.current.mutationId &&
6471
+ !clientOptions.ignoreResults) {
6472
+ var result_1 = {
6308
6473
  called: true,
6474
+ loading: false,
6475
+ data: data,
6476
+ error: error,
6309
6477
  client: client,
6310
- });
6311
- }
6312
- var mutationId = ++ref.current.mutationId;
6313
- var clientOptions = mergeOptions(baseOptions, executeOptions);
6314
- return client.mutate(clientOptions).then(function (response) {
6315
- var _a;
6316
- var data = response.data, errors = response.errors;
6317
- var error = errors && errors.length > 0
6318
- ? new ApolloError({ graphQLErrors: errors })
6319
- : void 0;
6320
- if (mutationId === ref.current.mutationId &&
6321
- !baseOptions.ignoreResults) {
6322
- var result_1 = {
6323
- called: true,
6324
- loading: false,
6325
- data: data,
6326
- error: error,
6327
- client: client,
6328
- };
6329
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6330
- setResult(ref.current.result = result_1);
6331
- }
6332
- }
6333
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6334
- return response;
6335
- }).catch(function (error) {
6336
- if (mutationId === ref.current.mutationId &&
6337
- ref.current.isMounted) {
6338
- var result_2 = {
6339
- loading: false,
6340
- error: error,
6341
- data: void 0,
6342
- called: true,
6343
- client: client,
6344
- };
6345
- if (!equality.equal(ref.current.result, result_2)) {
6346
- setResult(ref.current.result = result_2);
6347
- }
6478
+ };
6479
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
6480
+ setResult(ref.current.result = result_1);
6348
6481
  }
6349
- if (baseOptions.onError) {
6350
- baseOptions.onError(error);
6351
- return { data: void 0, errors: error };
6482
+ }
6483
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6484
+ (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
6485
+ return response;
6486
+ }).catch(function (error) {
6487
+ var _a, _b;
6488
+ if (mutationId === ref.current.mutationId &&
6489
+ ref.current.isMounted) {
6490
+ var result_2 = {
6491
+ loading: false,
6492
+ error: error,
6493
+ data: void 0,
6494
+ called: true,
6495
+ client: client,
6496
+ };
6497
+ if (!equal.equal(ref.current.result, result_2)) {
6498
+ setResult(ref.current.result = result_2);
6352
6499
  }
6353
- throw error;
6354
- });
6355
- };
6356
- return ref.current.execute;
6357
- }, [client, mutation, options]);
6500
+ }
6501
+ if (baseOptions.onError || clientOptions.onError) {
6502
+ (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
6503
+ (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
6504
+ return { data: void 0, errors: error };
6505
+ }
6506
+ throw error;
6507
+ });
6508
+ }, []);
6358
6509
  var reset = React.useCallback(function () {
6359
6510
  setResult({ called: false, loading: false, client: client });
6360
6511
  }, []);
@@ -6391,20 +6542,22 @@ function useSubscription(subscription, options) {
6391
6542
  if (typeof shouldResubscribe === 'function') {
6392
6543
  shouldResubscribe = !!shouldResubscribe(options);
6393
6544
  }
6394
- if ((options === null || options === void 0 ? void 0 : options.skip) && !(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6395
- setResult({
6396
- loading: false,
6397
- data: void 0,
6398
- error: void 0,
6399
- variables: options === null || options === void 0 ? void 0 : options.variables,
6400
- });
6401
- setObservable(null);
6545
+ if (options === null || options === void 0 ? void 0 : options.skip) {
6546
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6547
+ setResult({
6548
+ loading: false,
6549
+ data: void 0,
6550
+ error: void 0,
6551
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6552
+ });
6553
+ setObservable(null);
6554
+ }
6402
6555
  }
6403
6556
  else if (shouldResubscribe !== false && (client !== ref.current.client ||
6404
6557
  subscription !== ref.current.subscription ||
6405
6558
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6406
6559
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6407
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6560
+ !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6408
6561
  setResult({
6409
6562
  loading: true,
6410
6563
  data: void 0,
@@ -6491,7 +6644,6 @@ exports.HttpLink = HttpLink;
6491
6644
  exports.InMemoryCache = InMemoryCache;
6492
6645
  exports.MissingFieldError = MissingFieldError;
6493
6646
  exports.ObservableQuery = ObservableQuery;
6494
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
6495
6647
  exports.checkFetcher = checkFetcher;
6496
6648
  exports.concat = concat;
6497
6649
  exports.createHttpLink = createHttpLink;
@@ -6516,6 +6668,7 @@ exports.parser = parser;
6516
6668
  exports.resetApolloContext = getApolloContext;
6517
6669
  exports.rewriteURIForGET = rewriteURIForGET;
6518
6670
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
6671
+ exports.selectHttpOptionsAndBodyInternal = selectHttpOptionsAndBodyInternal;
6519
6672
  exports.selectURI = selectURI;
6520
6673
  exports.serializeFetchParameter = serializeFetchParameter;
6521
6674
  exports.split = split;