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

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 (175) hide show
  1. package/apollo-client.cjs +585 -419
  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 +1 -1
  24. package/core/ApolloClient.d.ts.map +1 -1
  25. package/core/ApolloClient.js +3 -3
  26. package/core/ApolloClient.js.map +1 -1
  27. package/core/LocalState.js +1 -1
  28. package/core/LocalState.js.map +1 -1
  29. package/core/ObservableQuery.d.ts +8 -3
  30. package/core/ObservableQuery.d.ts.map +1 -1
  31. package/core/ObservableQuery.js +92 -45
  32. package/core/ObservableQuery.js.map +1 -1
  33. package/core/QueryInfo.d.ts.map +1 -1
  34. package/core/QueryInfo.js +4 -2
  35. package/core/QueryInfo.js.map +1 -1
  36. package/core/QueryManager.d.ts +5 -2
  37. package/core/QueryManager.d.ts.map +1 -1
  38. package/core/QueryManager.js +21 -13
  39. package/core/QueryManager.js.map +1 -1
  40. package/core/core.cjs +122 -68
  41. package/core/core.cjs.map +1 -1
  42. package/core/index.d.ts +1 -1
  43. package/core/index.d.ts.map +1 -1
  44. package/core/index.js +1 -1
  45. package/core/index.js.map +1 -1
  46. package/core/watchQueryOptions.d.ts +9 -1
  47. package/core/watchQueryOptions.d.ts.map +1 -1
  48. package/core/watchQueryOptions.js.map +1 -1
  49. package/errors/errors.cjs +2 -2
  50. package/errors/errors.cjs.map +1 -1
  51. package/errors/index.js +2 -2
  52. package/errors/index.js.map +1 -1
  53. package/invariantErrorCodes.js +27 -27
  54. package/link/batch/batch.cjs +48 -38
  55. package/link/batch/batch.cjs.map +1 -1
  56. package/link/batch/batching.d.ts +2 -6
  57. package/link/batch/batching.d.ts.map +1 -1
  58. package/link/batch/batching.js +48 -38
  59. package/link/batch/batching.js.map +1 -1
  60. package/link/batch-http/batch-http.cjs +1 -1
  61. package/link/batch-http/batch-http.cjs.map +1 -1
  62. package/link/batch-http/batchHttpLink.js +2 -2
  63. package/link/batch-http/batchHttpLink.js.map +1 -1
  64. package/link/http/createHttpLink.js +2 -2
  65. package/link/http/createHttpLink.js.map +1 -1
  66. package/link/http/http.cjs +24 -13
  67. package/link/http/http.cjs.map +1 -1
  68. package/link/http/index.d.ts +1 -1
  69. package/link/http/index.d.ts.map +1 -1
  70. package/link/http/index.js +1 -1
  71. package/link/http/index.js.map +1 -1
  72. package/link/http/parseAndCheckHttpResponse.js +3 -3
  73. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  74. package/link/http/rewriteURIForGET.js +1 -1
  75. package/link/http/rewriteURIForGET.js.map +1 -1
  76. package/link/http/selectHttpOptionsAndBody.d.ts +5 -1
  77. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  78. package/link/http/selectHttpOptionsAndBody.js +19 -8
  79. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  80. package/link/http/serializeFetchParameter.js +1 -1
  81. package/link/http/serializeFetchParameter.js.map +1 -1
  82. package/link/subscriptions/index.d.ts +9 -0
  83. package/link/subscriptions/index.d.ts.map +1 -0
  84. package/link/subscriptions/index.js +39 -0
  85. package/link/subscriptions/index.js.map +1 -0
  86. package/link/subscriptions/package.json +8 -0
  87. package/link/subscriptions/subscriptions.cjs +45 -0
  88. package/link/subscriptions/subscriptions.cjs.map +1 -0
  89. package/link/utils/utils.cjs +1 -1
  90. package/link/utils/utils.cjs.map +1 -1
  91. package/link/utils/validateOperation.js +1 -1
  92. package/link/utils/validateOperation.js.map +1 -1
  93. package/main.cjs +4 -4
  94. package/package.json +27 -26
  95. package/react/components/components.cjs +3 -3
  96. package/react/context/context.cjs +3 -3
  97. package/react/hoc/hoc.cjs +9 -9
  98. package/react/hoc/hoc.cjs.map +1 -1
  99. package/react/hoc/mutation-hoc.js +2 -2
  100. package/react/hoc/mutation-hoc.js.map +1 -1
  101. package/react/hoc/query-hoc.js +1 -1
  102. package/react/hoc/query-hoc.js.map +1 -1
  103. package/react/hoc/subscription-hoc.js +1 -1
  104. package/react/hoc/subscription-hoc.js.map +1 -1
  105. package/react/hoc/withApollo.js +1 -1
  106. package/react/hoc/withApollo.js.map +1 -1
  107. package/react/hooks/hooks.cjs +364 -263
  108. package/react/hooks/hooks.cjs.map +1 -1
  109. package/react/hooks/index.d.ts +1 -1
  110. package/react/hooks/index.d.ts.map +1 -1
  111. package/react/hooks/index.js +1 -1
  112. package/react/hooks/index.js.map +1 -1
  113. package/react/hooks/useApolloClient.js +2 -2
  114. package/react/hooks/useApolloClient.js.map +1 -1
  115. package/react/hooks/useLazyQuery.d.ts +2 -2
  116. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  117. package/react/hooks/useLazyQuery.js +48 -39
  118. package/react/hooks/useLazyQuery.js.map +1 -1
  119. package/react/hooks/useMutation.d.ts.map +1 -1
  120. package/react/hooks/useMutation.js +59 -65
  121. package/react/hooks/useMutation.js.map +1 -1
  122. package/react/hooks/useQuery.d.ts +31 -1
  123. package/react/hooks/useQuery.d.ts.map +1 -1
  124. package/react/hooks/useQuery.js +254 -153
  125. package/react/hooks/useQuery.js.map +1 -1
  126. package/react/hooks/useSubscription.d.ts.map +1 -1
  127. package/react/hooks/useSubscription.js +10 -8
  128. package/react/hooks/useSubscription.js.map +1 -1
  129. package/react/parser/index.js +7 -7
  130. package/react/parser/index.js.map +1 -1
  131. package/react/parser/parser.cjs +7 -7
  132. package/react/parser/parser.cjs.map +1 -1
  133. package/react/react.cjs +2 -2
  134. package/react/ssr/RenderPromises.d.ts +2 -2
  135. package/react/ssr/RenderPromises.d.ts.map +1 -1
  136. package/react/ssr/RenderPromises.js +7 -5
  137. package/react/ssr/RenderPromises.js.map +1 -1
  138. package/react/ssr/ssr.cjs +10 -8
  139. package/react/ssr/ssr.cjs.map +1 -1
  140. package/react/types/types.d.ts +11 -12
  141. package/react/types/types.d.ts.map +1 -1
  142. package/react/types/types.js.map +1 -1
  143. package/testing/core/core.cjs +2 -2
  144. package/testing/core/core.cjs.map +1 -1
  145. package/testing/core/mocking/mockFetch.js +2 -2
  146. package/testing/core/mocking/mockFetch.js.map +1 -1
  147. package/testing/core/mocking/mockLink.js +2 -2
  148. package/testing/core/mocking/mockLink.js.map +1 -1
  149. package/testing/core/observableToPromise.js +1 -1
  150. package/testing/core/observableToPromise.js.map +1 -1
  151. package/testing/testing.cjs +5 -5
  152. package/utilities/common/makeUniqueId.js +1 -1
  153. package/utilities/common/makeUniqueId.js.map +1 -1
  154. package/utilities/globals/fix-graphql.js +1 -1
  155. package/utilities/globals/global.d.ts +2 -8
  156. package/utilities/globals/global.d.ts.map +1 -1
  157. package/utilities/globals/global.js +1 -1
  158. package/utilities/globals/global.js.map +1 -1
  159. package/utilities/globals/globals.cjs +1 -1
  160. package/utilities/globals/globals.cjs.map +1 -1
  161. package/utilities/graphql/directives.js +4 -4
  162. package/utilities/graphql/directives.js.map +1 -1
  163. package/utilities/graphql/fragments.js +3 -3
  164. package/utilities/graphql/fragments.js.map +1 -1
  165. package/utilities/graphql/getFromAST.js +2 -2
  166. package/utilities/graphql/getFromAST.js.map +1 -1
  167. package/utilities/graphql/storeUtils.js +5 -5
  168. package/utilities/graphql/storeUtils.js.map +1 -1
  169. package/utilities/graphql/transform.d.ts +2 -2
  170. package/utilities/graphql/transform.d.ts.map +1 -1
  171. package/utilities/graphql/transform.js +1 -1
  172. package/utilities/graphql/transform.js.map +1 -1
  173. package/utilities/utilities.cjs +16 -16
  174. package/utilities/utilities.cjs.map +1 -1
  175. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -13,17 +13,16 @@ 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');
17
16
 
18
17
  function _interopNamespace(e) {
19
18
  if (e && e.__esModule) return e;
20
19
  var n = Object.create(null);
21
20
  if (e) {
22
- Object.keys(e).forEach(function (k) {
21
+ for (var k in e) {
23
22
  n[k] = e[k];
24
- });
23
+ }
25
24
  }
26
- n['default'] = e;
25
+ n["default"] = e;
27
26
  return Object.freeze(n);
28
27
  }
29
28
 
@@ -46,7 +45,7 @@ function shouldInclude(_a, variables) {
46
45
  var evaledValue = false;
47
46
  if (ifArgument.value.kind === 'Variable') {
48
47
  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);
48
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 37);
50
49
  }
51
50
  else {
52
51
  evaledValue = ifArgument.value.value;
@@ -83,12 +82,12 @@ function getInclusionDirectives(directives) {
83
82
  return;
84
83
  var directiveArguments = directive.arguments;
85
84
  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);
85
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
87
86
  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);
87
+ __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
88
  var ifValue = ifArgument.value;
90
89
  __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 &&
90
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
92
91
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
93
92
  result.push({ directive: directive, ifArgument: ifArgument });
94
93
  });
@@ -101,7 +100,7 @@ function getFragmentQueryDocument(document, fragmentName) {
101
100
  var fragments = [];
102
101
  document.definitions.forEach(function (definition) {
103
102
  if (definition.kind === 'OperationDefinition') {
104
- throw __DEV__ ? new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
103
+ throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
105
104
  'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(41);
106
105
  }
107
106
  if (definition.kind === 'FragmentDefinition') {
@@ -109,7 +108,7 @@ function getFragmentQueryDocument(document, fragmentName) {
109
108
  }
110
109
  });
111
110
  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);
111
+ __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
112
  actualFragmentName = fragments[0].name.value;
114
113
  }
115
114
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -146,7 +145,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
146
145
  return selection;
147
146
  case 'FragmentSpread': {
148
147
  var fragment = fragmentMap && fragmentMap[selection.name.value];
149
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 43);
148
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value, ".")) : tsInvariant.invariant(fragment, 43);
150
149
  return fragment;
151
150
  }
152
151
  default:
@@ -228,7 +227,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
228
227
  argObj[name.value] = null;
229
228
  }
230
229
  else {
231
- throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
230
+ throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
232
231
  'is not supported. Use variables instead of inline arguments to ' +
233
232
  'overcome this limitation.') : new tsInvariant.InvariantError(52);
234
233
  }
@@ -280,7 +279,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
280
279
  filterKeys.forEach(function (key) {
281
280
  filteredArgs_1[key] = args[key];
282
281
  });
283
- return directives['connection']['key'] + "(" + stringify(filteredArgs_1) + ")";
282
+ return "".concat(directives['connection']['key'], "(").concat(stringify(filteredArgs_1), ")");
284
283
  }
285
284
  else {
286
285
  return directives['connection']['key'];
@@ -289,17 +288,17 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
289
288
  var completeFieldName = fieldName;
290
289
  if (args) {
291
290
  var stringifiedArgs = stringify(args);
292
- completeFieldName += "(" + stringifiedArgs + ")";
291
+ completeFieldName += "(".concat(stringifiedArgs, ")");
293
292
  }
294
293
  if (directives) {
295
294
  Object.keys(directives).forEach(function (key) {
296
295
  if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
297
296
  return;
298
297
  if (directives[key] && Object.keys(directives[key]).length) {
299
- completeFieldName += "@" + key + "(" + stringify(directives[key]) + ")";
298
+ completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
300
299
  }
301
300
  else {
302
- completeFieldName += "@" + key;
301
+ completeFieldName += "@".concat(key);
303
302
  }
304
303
  });
305
304
  }
@@ -369,11 +368,11 @@ function checkDocument(doc) {
369
368
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
370
369
  .map(function (definition) {
371
370
  if (definition.kind !== 'OperationDefinition') {
372
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(45);
371
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(45);
373
372
  }
374
373
  return definition;
375
374
  });
376
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 46);
375
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 46);
377
376
  return doc;
378
377
  }
379
378
  function getOperationDefinition(doc) {
@@ -540,7 +539,7 @@ function removeDirectivesFromDocument(directives, doc) {
540
539
  return modifiedDoc;
541
540
  }
542
541
  var addTypenameToDocument = Object.assign(function (doc) {
543
- return graphql.visit(checkDocument(doc), {
542
+ return graphql.visit(doc, {
544
543
  SelectionSet: {
545
544
  enter: function (node, _key, parent) {
546
545
  if (parent &&
@@ -704,7 +703,7 @@ function removeClientSetsFromDocument(document) {
704
703
  return modifiedDoc;
705
704
  }
706
705
 
707
- var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
706
+ var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
708
707
  function mergeDeep() {
709
708
  var sources = [];
710
709
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -741,7 +740,7 @@ var DeepMerger = (function () {
741
740
  }
742
741
  if (isNonNullObject(source) && isNonNullObject(target)) {
743
742
  Object.keys(source).forEach(function (sourceKey) {
744
- if (hasOwnProperty$3.call(target, sourceKey)) {
743
+ if (hasOwnProperty$4.call(target, sourceKey)) {
745
744
  var targetValue = target[sourceKey];
746
745
  if (source[sourceKey] !== targetValue) {
747
746
  var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
@@ -1078,7 +1077,7 @@ var prefixCounts = new Map();
1078
1077
  function makeUniqueId(prefix) {
1079
1078
  var count = prefixCounts.get(prefix) || 1;
1080
1079
  prefixCounts.set(prefix, count + 1);
1081
- return prefix + ":" + count + ":" + Math.random().toString(36).slice(2);
1080
+ return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
1082
1081
  }
1083
1082
 
1084
1083
  function stringifyForDisplay(value) {
@@ -1143,7 +1142,7 @@ function validateOperation(operation) {
1143
1142
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1144
1143
  var key = _a[_i];
1145
1144
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1146
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(24);
1145
+ throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: ".concat(key)) : new tsInvariant.InvariantError(24);
1147
1146
  }
1148
1147
  }
1149
1148
  return operation;
@@ -1292,9 +1291,9 @@ var concat = ApolloLink.concat;
1292
1291
 
1293
1292
  var execute = ApolloLink.execute;
1294
1293
 
1295
- var version = '3.6.0-beta.1';
1294
+ var version = '3.6.0-beta.12';
1296
1295
 
1297
- var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1296
+ var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1298
1297
  function parseAndCheckHttpResponse(operations) {
1299
1298
  return function (response) { return response
1300
1299
  .text()
@@ -1313,14 +1312,14 @@ function parseAndCheckHttpResponse(operations) {
1313
1312
  })
1314
1313
  .then(function (result) {
1315
1314
  if (response.status >= 300) {
1316
- throwServerError(response, result, "Response not successful: Received status code " + response.status);
1315
+ throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1317
1316
  }
1318
1317
  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)
1318
+ !hasOwnProperty$3.call(result, 'data') &&
1319
+ !hasOwnProperty$3.call(result, 'errors')) {
1320
+ throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1322
1321
  ? operations.map(function (op) { return op.operationName; })
1323
- : operations.operationName) + "'.");
1322
+ : operations.operationName, "'."));
1324
1323
  }
1325
1324
  return result;
1326
1325
  }); };
@@ -1332,7 +1331,7 @@ var serializeFetchParameter = function (p, label) {
1332
1331
  serialized = JSON.stringify(p);
1333
1332
  }
1334
1333
  catch (e) {
1335
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(21);
1334
+ var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new tsInvariant.InvariantError(21);
1336
1335
  parseError.parseError = e;
1337
1336
  throw parseError;
1338
1337
  }
@@ -1356,17 +1355,27 @@ var fallbackHttpConfig = {
1356
1355
  options: defaultOptions,
1357
1356
  };
1358
1357
  var defaultPrinter = function (ast, printer) { return printer(ast); };
1359
- var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1358
+ function selectHttpOptionsAndBody(operation, fallbackConfig) {
1359
+ var configs = [];
1360
+ for (var _i = 2; _i < arguments.length; _i++) {
1361
+ configs[_i - 2] = arguments[_i];
1362
+ }
1363
+ configs.unshift(fallbackConfig);
1364
+ return selectHttpOptionsAndBodyInternal.apply(void 0, tslib.__spreadArray([operation,
1365
+ defaultPrinter], configs, false));
1366
+ }
1367
+ function selectHttpOptionsAndBodyInternal(operation, printer) {
1360
1368
  var configs = [];
1361
- for (var _i = 3; _i < arguments.length; _i++) {
1362
- configs[_i - 3] = arguments[_i];
1369
+ for (var _i = 2; _i < arguments.length; _i++) {
1370
+ configs[_i - 2] = arguments[_i];
1363
1371
  }
1364
- var options = tslib.__assign(tslib.__assign({}, fallbackConfig.options), { headers: fallbackConfig.headers, credentials: fallbackConfig.credentials });
1365
- var http = fallbackConfig.http || {};
1372
+ var options = {};
1373
+ var http = {};
1366
1374
  configs.forEach(function (config) {
1367
1375
  options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), headersToLowerCase(config.headers)) });
1368
- if (config.credentials)
1376
+ if (config.credentials) {
1369
1377
  options.credentials = config.credentials;
1378
+ }
1370
1379
  http = tslib.__assign(tslib.__assign({}, http), config.http);
1371
1380
  });
1372
1381
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
@@ -1379,7 +1388,7 @@ var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1379
1388
  options: options,
1380
1389
  body: body,
1381
1390
  };
1382
- };
1391
+ }
1383
1392
  function headersToLowerCase(headers) {
1384
1393
  if (headers) {
1385
1394
  var normalized_1 = Object.create(null);
@@ -1422,7 +1431,7 @@ var selectURI = function (operation, fallbackURI) {
1422
1431
  function rewriteURIForGET(chosenURI, body) {
1423
1432
  var queryParams = [];
1424
1433
  var addQueryParam = function (key, value) {
1425
- queryParams.push(key + "=" + encodeURIComponent(value));
1434
+ queryParams.push("".concat(key, "=").concat(encodeURIComponent(value)));
1426
1435
  };
1427
1436
  if ('query' in body) {
1428
1437
  addQueryParam('query', body.query);
@@ -1494,7 +1503,7 @@ var createHttpLink = function (linkOptions) {
1494
1503
  credentials: context.credentials,
1495
1504
  headers: contextHeaders,
1496
1505
  };
1497
- var _b = selectHttpOptionsAndBody(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1506
+ var _b = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1498
1507
  if (body.variables && !includeUnusedVariables) {
1499
1508
  var unusedNames_1 = new Set(Object.keys(body.variables));
1500
1509
  graphql.visit(operation.query, {
@@ -1687,7 +1696,7 @@ function defaultDataIdFromObject(_a, context) {
1687
1696
  if (id === void 0)
1688
1697
  id = _id;
1689
1698
  if (id !== void 0) {
1690
- return __typename + ":" + ((typeof id === "number" ||
1699
+ return "".concat(__typename, ":").concat((typeof id === "number" ||
1691
1700
  typeof id === "string") ? id : JSON.stringify(id));
1692
1701
  }
1693
1702
  }
@@ -1717,7 +1726,7 @@ function fieldNameFromStoreName(storeFieldName) {
1717
1726
  }
1718
1727
  function selectionSetMatchesResult(selectionSet, result, variables) {
1719
1728
  if (isNonNullObject(result)) {
1720
- return Array.isArray(result)
1729
+ return isArray(result)
1721
1730
  ? result.every(function (item) { return selectionSetMatchesResult(selectionSet, item, variables); })
1722
1731
  : selectionSet.selections.every(function (field) {
1723
1732
  if (isField(field) && shouldInclude(field, variables)) {
@@ -1734,11 +1743,12 @@ function selectionSetMatchesResult(selectionSet, result, variables) {
1734
1743
  function storeValueIsStoreObject(value) {
1735
1744
  return isNonNullObject(value) &&
1736
1745
  !isReference(value) &&
1737
- !Array.isArray(value);
1746
+ !isArray(value);
1738
1747
  }
1739
1748
  function makeProcessedFieldsMerger() {
1740
1749
  return new DeepMerger;
1741
1750
  }
1751
+ var isArray = function (a) { return Array.isArray(a); };
1742
1752
 
1743
1753
  var DELETE = Object.create(null);
1744
1754
  var delModifier = function () { return DELETE; };
@@ -2201,7 +2211,7 @@ function supportsResultCaching(store) {
2201
2211
 
2202
2212
  function shallowCopy(value) {
2203
2213
  if (isNonNullObject(value)) {
2204
- return Array.isArray(value)
2214
+ return isArray(value)
2205
2215
  ? value.slice(0)
2206
2216
  : tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
2207
2217
  }
@@ -2423,7 +2433,7 @@ var StoreReader = (function () {
2423
2433
  !context.store.has(objectOrReference.__ref)) {
2424
2434
  return {
2425
2435
  result: this.canon.empty,
2426
- missing: "Dangling reference to missing " + objectOrReference.__ref + " object",
2436
+ missing: "Dangling reference to missing ".concat(objectOrReference.__ref, " object"),
2427
2437
  };
2428
2438
  }
2429
2439
  var variables = context.variables, policies = context.policies, store = context.store;
@@ -2458,13 +2468,13 @@ var StoreReader = (function () {
2458
2468
  if (fieldValue === void 0) {
2459
2469
  if (!addTypenameToDocument.added(selection)) {
2460
2470
  missing = context.merge(missing, (_a = {},
2461
- _a[resultName] = "Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
2471
+ _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(isReference(objectOrReference)
2462
2472
  ? objectOrReference.__ref + " object"
2463
2473
  : "object " + JSON.stringify(objectOrReference, null, 2)),
2464
2474
  _a));
2465
2475
  }
2466
2476
  }
2467
- else if (Array.isArray(fieldValue)) {
2477
+ else if (isArray(fieldValue)) {
2468
2478
  fieldValue = handleMissing(_this.executeSubSelectedArray({
2469
2479
  field: selection,
2470
2480
  array: fieldValue,
@@ -2523,7 +2533,7 @@ var StoreReader = (function () {
2523
2533
  if (item === null) {
2524
2534
  return null;
2525
2535
  }
2526
- if (Array.isArray(item)) {
2536
+ if (isArray(item)) {
2527
2537
  return handleMissing(_this.executeSubSelectedArray({
2528
2538
  field: field,
2529
2539
  array: item,
@@ -2568,7 +2578,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
2568
2578
  var workSet_1 = new Set([fieldValue]);
2569
2579
  workSet_1.forEach(function (value) {
2570
2580
  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);
2581
+ __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
2582
  Object.values(value).forEach(workSet_1.add, workSet_1);
2573
2583
  }
2574
2584
  });
@@ -2655,10 +2665,10 @@ function keyFieldsFnFromSpecifier(specifier) {
2655
2665
  hasOwn.call(object, schemaKeyPath[0])) {
2656
2666
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
2657
2667
  }
2658
- __DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '" + schemaKeyPath.join('.') + "' while extracting keyFields from " + JSON.stringify(object)) : tsInvariant.invariant(extracted !== void 0, 2);
2668
+ __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
2669
  return extracted;
2660
2670
  });
2661
- return context.typename + ":" + JSON.stringify(keyObject);
2671
+ return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
2662
2672
  });
2663
2673
  }
2664
2674
  function keyArgsFnFromSpecifier(specifier) {
@@ -2717,13 +2727,13 @@ function getSpecifierPaths(spec) {
2717
2727
  var paths_1 = info.paths = [];
2718
2728
  var currentPath_1 = [];
2719
2729
  spec.forEach(function (s, i) {
2720
- if (Array.isArray(s)) {
2730
+ if (isArray(s)) {
2721
2731
  getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
2722
2732
  currentPath_1.length = 0;
2723
2733
  }
2724
2734
  else {
2725
2735
  currentPath_1.push(s);
2726
- if (!Array.isArray(spec[i + 1])) {
2736
+ if (!isArray(spec[i + 1])) {
2727
2737
  paths_1.push(currentPath_1.slice(0));
2728
2738
  currentPath_1.length = 0;
2729
2739
  }
@@ -2738,14 +2748,14 @@ function extractKey(object, key) {
2738
2748
  function extractKeyPath(object, path, extract) {
2739
2749
  extract = extract || extractKey;
2740
2750
  return normalize(path.reduce(function reducer(obj, key) {
2741
- return Array.isArray(obj)
2751
+ return isArray(obj)
2742
2752
  ? obj.map(function (child) { return reducer(child, key); })
2743
2753
  : obj && extract(obj, key);
2744
2754
  }, object));
2745
2755
  }
2746
2756
  function normalize(value) {
2747
2757
  if (isNonNullObject(value)) {
2748
- if (Array.isArray(value)) {
2758
+ if (isArray(value)) {
2749
2759
  return value.map(normalize);
2750
2760
  }
2751
2761
  return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
@@ -2808,7 +2818,7 @@ var Policies = (function () {
2808
2818
  var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
2809
2819
  while (keyFn) {
2810
2820
  var specifierOrId = keyFn(object, context);
2811
- if (Array.isArray(specifierOrId)) {
2821
+ if (isArray(specifierOrId)) {
2812
2822
  keyFn = keyFieldsFnFromSpecifier(specifierOrId);
2813
2823
  }
2814
2824
  else {
@@ -2851,7 +2861,7 @@ var Policies = (function () {
2851
2861
  setMerge(existing, incoming.merge);
2852
2862
  existing.keyFn =
2853
2863
  keyFields === false ? nullKeyFieldsFn :
2854
- Array.isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2864
+ isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2855
2865
  typeof keyFields === "function" ? keyFields :
2856
2866
  existing.keyFn;
2857
2867
  if (fields) {
@@ -2865,7 +2875,7 @@ var Policies = (function () {
2865
2875
  var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
2866
2876
  existing.keyFn =
2867
2877
  keyArgs === false ? simpleKeyArgsFn :
2868
- Array.isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2878
+ isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2869
2879
  typeof keyArgs === "function" ? keyArgs :
2870
2880
  existing.keyFn;
2871
2881
  if (typeof read === "function") {
@@ -2884,7 +2894,7 @@ var Policies = (function () {
2884
2894
  var rootId = "ROOT_" + which.toUpperCase();
2885
2895
  var old = this.rootTypenamesById[rootId];
2886
2896
  if (typename !== old) {
2887
- __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 3);
2897
+ __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root ".concat(which, " __typename more than once")) : tsInvariant.invariant(!old || old === which, 3);
2888
2898
  if (old)
2889
2899
  delete this.rootIdsByTypename[old];
2890
2900
  this.rootIdsByTypename[typename] = rootId;
@@ -2968,7 +2978,7 @@ var Policies = (function () {
2968
2978
  if (supertypeSet.has(supertype)) {
2969
2979
  if (!typenameSupertypeSet.has(supertype)) {
2970
2980
  if (checkingFuzzySubtypes) {
2971
- __DEV__ && tsInvariant.invariant.warn("Inferring subtype " + typename + " of supertype " + supertype);
2981
+ __DEV__ && tsInvariant.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
2972
2982
  }
2973
2983
  typenameSupertypeSet.add(supertype);
2974
2984
  }
@@ -3010,7 +3020,7 @@ var Policies = (function () {
3010
3020
  var args = argsFromFieldSpecifier(fieldSpec);
3011
3021
  while (keyFn) {
3012
3022
  var specifierOrString = keyFn(args, context);
3013
- if (Array.isArray(specifierOrString)) {
3023
+ if (isArray(specifierOrString)) {
3014
3024
  keyFn = keyArgsFnFromSpecifier(specifierOrString);
3015
3025
  }
3016
3026
  else {
@@ -3122,7 +3132,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3122
3132
  }
3123
3133
  }
3124
3134
  if (__DEV__ && options.from === void 0) {
3125
- __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + stringifyForDisplay(Array.from(readFieldArgs)));
3135
+ __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments ".concat(stringifyForDisplay(Array.from(readFieldArgs))));
3126
3136
  }
3127
3137
  if (void 0 === options.variables) {
3128
3138
  options.variables = variables;
@@ -3131,7 +3141,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3131
3141
  }
3132
3142
  function makeMergeObjectsFunction(store) {
3133
3143
  return function mergeObjects(existing, incoming) {
3134
- if (Array.isArray(existing) || Array.isArray(incoming)) {
3144
+ if (isArray(existing) || isArray(incoming)) {
3135
3145
  throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
3136
3146
  }
3137
3147
  if (isNonNullObject(existing) &&
@@ -3162,7 +3172,7 @@ function makeMergeObjectsFunction(store) {
3162
3172
  }
3163
3173
 
3164
3174
  function getContextFlavor(context, clientOnly, deferred) {
3165
- var key = "" + clientOnly + deferred;
3175
+ var key = "".concat(clientOnly).concat(deferred);
3166
3176
  var flavored = context.flavors.get(key);
3167
3177
  if (!flavored) {
3168
3178
  context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
@@ -3204,7 +3214,7 @@ var StoreWriter = (function () {
3204
3214
  context: context,
3205
3215
  });
3206
3216
  if (!isReference(ref)) {
3207
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(6);
3217
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new tsInvariant.InvariantError(6);
3208
3218
  }
3209
3219
  context.incomingById.forEach(function (_a, dataId) {
3210
3220
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -3309,7 +3319,7 @@ var StoreWriter = (function () {
3309
3319
  !context.deferred &&
3310
3320
  !addTypenameToDocument.added(field) &&
3311
3321
  !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));
3322
+ __DEV__ && tsInvariant.invariant.error("Missing field '".concat(resultKeyNameFromField(field), "' while writing result ").concat(JSON.stringify(result, null, 2)).substring(0, 1000));
3313
3323
  }
3314
3324
  });
3315
3325
  try {
@@ -3360,7 +3370,7 @@ var StoreWriter = (function () {
3360
3370
  if (!field.selectionSet || value === null) {
3361
3371
  return __DEV__ ? cloneDeep(value) : value;
3362
3372
  }
3363
- if (Array.isArray(value)) {
3373
+ if (isArray(value)) {
3364
3374
  return value.map(function (item, i) {
3365
3375
  var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
3366
3376
  maybeRecycleChildMergeTree(mergeTree, i);
@@ -3425,7 +3435,7 @@ var StoreWriter = (function () {
3425
3435
  var _a;
3426
3436
  var _this = this;
3427
3437
  if (mergeTree.map.size && !isReference(incoming)) {
3428
- var e_1 = (!Array.isArray(incoming) &&
3438
+ var e_1 = (!isArray(incoming) &&
3429
3439
  (isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
3430
3440
  var i_1 = incoming;
3431
3441
  if (e_1 && !getStorageArgs) {
@@ -3433,7 +3443,7 @@ var StoreWriter = (function () {
3433
3443
  }
3434
3444
  var changedFields_1;
3435
3445
  var getValue_1 = function (from, name) {
3436
- return Array.isArray(from)
3446
+ return isArray(from)
3437
3447
  ? (typeof name === "number" ? from[name] : void 0)
3438
3448
  : context.store.getFieldValue(from, String(name));
3439
3449
  };
@@ -3455,7 +3465,7 @@ var StoreWriter = (function () {
3455
3465
  }
3456
3466
  });
3457
3467
  if (changedFields_1) {
3458
- incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
3468
+ incoming = (isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
3459
3469
  changedFields_1.forEach(function (value, name) {
3460
3470
  incoming[name] = value;
3461
3471
  });
@@ -3531,13 +3541,13 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3531
3541
  var parentType = store.getFieldValue(existingRef, "__typename") ||
3532
3542
  store.getFieldValue(incomingObj, "__typename");
3533
3543
  var fieldName = fieldNameFromStoreName(storeFieldName);
3534
- var typeDotName = parentType + "." + fieldName;
3544
+ var typeDotName = "".concat(parentType, ".").concat(fieldName);
3535
3545
  if (warnings.has(typeDotName))
3536
3546
  return;
3537
3547
  warnings.add(typeDotName);
3538
3548
  var childTypenames = [];
3539
- if (!Array.isArray(existing) &&
3540
- !Array.isArray(incoming)) {
3549
+ if (!isArray(existing) &&
3550
+ !isArray(incoming)) {
3541
3551
  [existing, incoming].forEach(function (child) {
3542
3552
  var typename = store.getFieldValue(child, "__typename");
3543
3553
  if (typeof typename === "string" &&
@@ -3546,10 +3556,10 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3546
3556
  }
3547
3557
  });
3548
3558
  }
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
3559
+ __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
3560
  ? "either ensure all objects of type " +
3551
3561
  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");
3562
+ : "", "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
3563
  }
3554
3564
 
3555
3565
  var InMemoryCache = (function (_super) {
@@ -3856,11 +3866,11 @@ var generateErrorMessage = function (err) {
3856
3866
  var errorMessage = error
3857
3867
  ? error.message
3858
3868
  : 'Error message not found.';
3859
- message += errorMessage + "\n";
3869
+ message += "".concat(errorMessage, "\n");
3860
3870
  });
3861
3871
  }
3862
3872
  if (err.networkError) {
3863
- message += err.networkError.message + "\n";
3873
+ message += "".concat(err.networkError.message, "\n");
3864
3874
  }
3865
3875
  message = message.replace(/\n$/, '');
3866
3876
  return message;
@@ -3895,8 +3905,7 @@ function isNetworkRequestInFlight(networkStatus) {
3895
3905
  return networkStatus ? networkStatus < 7 : false;
3896
3906
  }
3897
3907
 
3898
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3899
- var warnedAboutUpdateQuery = false;
3908
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3900
3909
  var ObservableQuery = (function (_super) {
3901
3910
  tslib.__extends(ObservableQuery, _super);
3902
3911
  function ObservableQuery(_a) {
@@ -3930,11 +3939,10 @@ var ObservableQuery = (function (_super) {
3930
3939
  _this.observers = new Set();
3931
3940
  _this.subscriptions = new Set();
3932
3941
  _this.isTornDown = false;
3933
- _this.options = options;
3942
+ _this.options = tslib.__assign({ initialFetchPolicy: options.fetchPolicy || "cache-first" }, options);
3934
3943
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3935
3944
  var opDef = getOperationDefinition(options.query);
3936
3945
  _this.queryName = opDef && opDef.name && opDef.name.value;
3937
- _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
3938
3946
  _this.queryManager = queryManager;
3939
3947
  _this.queryInfo = queryInfo;
3940
3948
  return _this;
@@ -4042,7 +4050,7 @@ var ObservableQuery = (function (_super) {
4042
4050
  pollInterval: 0,
4043
4051
  };
4044
4052
  var fetchPolicy = this.options.fetchPolicy;
4045
- if (fetchPolicy === 'standby' || fetchPolicy === 'cache-and-network') {
4053
+ if (fetchPolicy === 'cache-and-network') {
4046
4054
  reobserveOptions.fetchPolicy = fetchPolicy;
4047
4055
  }
4048
4056
  else if (fetchPolicy === 'no-cache') {
@@ -4051,11 +4059,11 @@ var ObservableQuery = (function (_super) {
4051
4059
  else {
4052
4060
  reobserveOptions.fetchPolicy = 'network-only';
4053
4061
  }
4054
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4062
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4055
4063
  var queryDef = getQueryDefinition(this.options.query);
4056
4064
  var vars = queryDef.variableDefinitions;
4057
4065
  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 })?");
4066
+ __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
4067
  }
4060
4068
  }
4061
4069
  if (variables && !equality.equal(this.options.variables, variables)) {
@@ -4068,35 +4076,49 @@ var ObservableQuery = (function (_super) {
4068
4076
  var _this = this;
4069
4077
  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
4078
  var qid = this.queryManager.generateQueryId();
4079
+ var queryInfo = this.queryInfo;
4080
+ var originalNetworkStatus = queryInfo.networkStatus;
4081
+ queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4071
4082
  if (combinedOptions.notifyOnNetworkStatusChange) {
4072
- this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4073
4083
  this.observe();
4074
4084
  }
4085
+ var updatedQuerySet = new Set();
4075
4086
  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
- }
4087
+ _this.queryManager.removeQuery(qid);
4088
+ if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
4089
+ queryInfo.networkStatus = originalNetworkStatus;
4090
+ }
4091
+ _this.queryManager.cache.batch({
4092
+ update: function (cache) {
4093
+ var updateQuery = fetchMoreOptions.updateQuery;
4094
+ if (updateQuery) {
4095
+ cache.updateQuery({
4096
+ query: _this.options.query,
4097
+ variables: _this.variables,
4098
+ returnPartialData: true,
4099
+ optimistic: false,
4100
+ }, function (previous) { return updateQuery(previous, {
4101
+ fetchMoreResult: fetchMoreResult.data,
4102
+ variables: combinedOptions.variables,
4103
+ }); });
4104
+ }
4105
+ else {
4106
+ cache.writeQuery({
4107
+ query: combinedOptions.query,
4108
+ variables: combinedOptions.variables,
4109
+ data: fetchMoreResult.data,
4110
+ });
4111
+ }
4112
+ },
4113
+ onWatchUpdated: function (watch) {
4114
+ updatedQuerySet.add(watch.query);
4115
+ },
4116
+ });
4096
4117
  return fetchMoreResult;
4097
4118
  }).finally(function () {
4098
- _this.queryManager.stopQuery(qid);
4099
- _this.reobserve();
4119
+ if (!updatedQuerySet.has(_this.options.query)) {
4120
+ reobserveCacheFirst(_this);
4121
+ }
4100
4122
  });
4101
4123
  };
4102
4124
  ObservableQuery.prototype.subscribeToMore = function (options) {
@@ -4149,7 +4171,7 @@ var ObservableQuery = (function (_super) {
4149
4171
  return Promise.resolve();
4150
4172
  }
4151
4173
  return this.reobserve({
4152
- fetchPolicy: this.initialFetchPolicy,
4174
+ fetchPolicy: this.options.initialFetchPolicy,
4153
4175
  variables: variables,
4154
4176
  }, exports.NetworkStatus.setVariables);
4155
4177
  };
@@ -4181,6 +4203,26 @@ var ObservableQuery = (function (_super) {
4181
4203
  this.options.pollInterval = 0;
4182
4204
  this.updatePolling();
4183
4205
  };
4206
+ ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
4207
+ if (options.nextFetchPolicy) {
4208
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
4209
+ if (typeof options.nextFetchPolicy === "function") {
4210
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
4211
+ reason: reason,
4212
+ options: options,
4213
+ observable: this,
4214
+ initialFetchPolicy: initialFetchPolicy,
4215
+ });
4216
+ }
4217
+ else if (reason === "variables-changed") {
4218
+ options.fetchPolicy = initialFetchPolicy;
4219
+ }
4220
+ else {
4221
+ options.fetchPolicy = options.nextFetchPolicy;
4222
+ }
4223
+ }
4224
+ return options.fetchPolicy;
4225
+ };
4184
4226
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4185
4227
  this.queryManager.setObservableQuery(this);
4186
4228
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -4243,16 +4285,18 @@ var ObservableQuery = (function (_super) {
4243
4285
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
4244
4286
  newNetworkStatus === exports.NetworkStatus.poll;
4245
4287
  var oldVariables = this.options.variables;
4288
+ var oldFetchPolicy = this.options.fetchPolicy;
4289
+ var mergedOptions = mergeOptions(this.options, newOptions || {});
4246
4290
  var options = useDisposableConcast
4247
- ? compact(this.options, newOptions)
4248
- : assign(this.options, compact(newOptions));
4291
+ ? mergedOptions
4292
+ : assign(this.options, mergedOptions);
4249
4293
  if (!useDisposableConcast) {
4250
4294
  this.updatePolling();
4251
4295
  if (newOptions &&
4252
4296
  newOptions.variables &&
4253
- !newOptions.fetchPolicy &&
4254
- !equality.equal(newOptions.variables, oldVariables)) {
4255
- options.fetchPolicy = this.initialFetchPolicy;
4297
+ !equality.equal(newOptions.variables, oldVariables) &&
4298
+ (!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
4299
+ this.applyNextFetchPolicy("variables-changed", options);
4256
4300
  if (newNetworkStatus === void 0) {
4257
4301
  newNetworkStatus = exports.NetworkStatus.setVariables;
4258
4302
  }
@@ -4282,8 +4326,11 @@ var ObservableQuery = (function (_super) {
4282
4326
  this.reportResult(this.getCurrentResult(false), this.variables);
4283
4327
  };
4284
4328
  ObservableQuery.prototype.reportResult = function (result, variables) {
4285
- if (this.getLastError() || this.isDifferentFromLastResult(result)) {
4286
- this.updateLastResult(result, variables);
4329
+ var lastError = this.getLastError();
4330
+ if (lastError || this.isDifferentFromLastResult(result)) {
4331
+ if (lastError || !result.partial || this.options.returnPartialData) {
4332
+ this.updateLastResult(result, variables);
4333
+ }
4287
4334
  iterateObserversSafely(this.observers, 'next', result);
4288
4335
  }
4289
4336
  };
@@ -4313,20 +4360,29 @@ var ObservableQuery = (function (_super) {
4313
4360
  return ObservableQuery;
4314
4361
  }(zenObservableTs.Observable));
4315
4362
  fixObservableSubclass(ObservableQuery);
4363
+ function reobserveCacheFirst(obsQuery) {
4364
+ var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
4365
+ if (fetchPolicy === "cache-and-network" ||
4366
+ fetchPolicy === "network-only") {
4367
+ return obsQuery.reobserve({
4368
+ fetchPolicy: "cache-first",
4369
+ nextFetchPolicy: function () {
4370
+ this.nextFetchPolicy = nextFetchPolicy;
4371
+ if (typeof nextFetchPolicy === "function") {
4372
+ return nextFetchPolicy.apply(this, arguments);
4373
+ }
4374
+ return fetchPolicy;
4375
+ },
4376
+ });
4377
+ }
4378
+ return obsQuery.reobserve();
4379
+ }
4316
4380
  function defaultSubscriptionObserverErrorCallback(error) {
4317
4381
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4318
4382
  }
4319
4383
  function logMissingFieldErrors(missing) {
4320
4384
  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;
4385
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4330
4386
  }
4331
4387
  }
4332
4388
 
@@ -4499,7 +4555,7 @@ var LocalState = (function () {
4499
4555
  }
4500
4556
  else {
4501
4557
  fragment = fragmentMap[selection.name.value];
4502
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 9);
4558
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value)) : tsInvariant.invariant(fragment, 9);
4503
4559
  }
4504
4560
  if (fragment && fragment.typeCondition) {
4505
4561
  typeCondition = fragment.typeCondition.name.value;
@@ -4711,11 +4767,12 @@ var QueryInfo = (function () {
4711
4767
  if (oq) {
4712
4768
  oq["queryInfo"] = this;
4713
4769
  this.listeners.add(this.oqListener = function () {
4714
- if (_this.getDiff().fromOptimisticTransaction) {
4770
+ var diff = _this.getDiff();
4771
+ if (diff.fromOptimisticTransaction) {
4715
4772
  oq["observe"]();
4716
4773
  }
4717
4774
  else {
4718
- oq.reobserve();
4775
+ reobserveCacheFirst(oq);
4719
4776
  }
4720
4777
  });
4721
4778
  }
@@ -4857,10 +4914,10 @@ function shouldWriteResult(result, errorPolicy) {
4857
4914
  return writeWithErrors;
4858
4915
  }
4859
4916
 
4860
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4917
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4861
4918
  var QueryManager = (function () {
4862
4919
  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;
4920
+ 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
4921
  this.clientAwareness = {};
4865
4922
  this.queries = new Map();
4866
4923
  this.fetchCancelFns = new Map();
@@ -4871,6 +4928,7 @@ var QueryManager = (function () {
4871
4928
  this.inFlightLinkObservables = new Map();
4872
4929
  this.cache = cache;
4873
4930
  this.link = link;
4931
+ this.defaultOptions = defaultOptions || Object.create(null);
4874
4932
  this.queryDeduplication = queryDeduplication;
4875
4933
  this.clientAwareness = clientAwareness;
4876
4934
  this.localState = localState || new LocalState({ cache: cache });
@@ -4892,11 +4950,12 @@ var QueryManager = (function () {
4892
4950
  this.fetchCancelFns.clear();
4893
4951
  };
4894
4952
  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;
4953
+ var _b, _c;
4954
+ 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
4955
  return tslib.__awaiter(this, void 0, void 0, function () {
4897
4956
  var mutationId, mutationStoreValue, self;
4898
- return tslib.__generator(this, function (_f) {
4899
- switch (_f.label) {
4957
+ return tslib.__generator(this, function (_h) {
4958
+ switch (_h.label) {
4900
4959
  case 0:
4901
4960
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4902
4961
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4908,8 +4967,8 @@ var QueryManager = (function () {
4908
4967
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4909
4968
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4910
4969
  case 1:
4911
- variables = (_f.sent());
4912
- _f.label = 2;
4970
+ variables = (_h.sent());
4971
+ _h.label = 2;
4913
4972
  case 2:
4914
4973
  mutationStoreValue = this.mutationStore &&
4915
4974
  (this.mutationStore[mutationId] = {
@@ -5010,7 +5069,7 @@ var QueryManager = (function () {
5010
5069
  this.queries.forEach(function (_a, queryId) {
5011
5070
  var observableQuery = _a.observableQuery;
5012
5071
  var queryName = observableQuery && observableQuery.queryName;
5013
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5072
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5014
5073
  return;
5015
5074
  }
5016
5075
  var updater = updateQueries_1[queryName];
@@ -5290,7 +5349,7 @@ var QueryManager = (function () {
5290
5349
  if (__DEV__ && queryNamesAndDocs.size) {
5291
5350
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
5292
5351
  if (!included) {
5293
- __DEV__ && tsInvariant.invariant.warn("Unknown query " + (typeof nameOrDoc === "string" ? "named " : "") + JSON.stringify(nameOrDoc, null, 2) + " requested in refetchQueries options.include array");
5352
+ __DEV__ && tsInvariant.invariant.warn("Unknown query ".concat(typeof nameOrDoc === "string" ? "named " : "").concat(JSON.stringify(nameOrDoc, null, 2), " requested in refetchQueries options.include array"));
5294
5353
  }
5295
5354
  });
5296
5355
  }
@@ -5362,8 +5421,10 @@ var QueryManager = (function () {
5362
5421
  };
5363
5422
  QueryManager.prototype.removeQuery = function (queryId) {
5364
5423
  this.fetchCancelFns.delete(queryId);
5365
- this.getQuery(queryId).stop();
5366
- this.queries.delete(queryId);
5424
+ if (this.queries.has(queryId)) {
5425
+ this.getQuery(queryId).stop();
5426
+ this.queries.delete(queryId);
5427
+ }
5367
5428
  };
5368
5429
  QueryManager.prototype.broadcastQueries = function () {
5369
5430
  if (this.onBroadcast)
@@ -5447,10 +5508,11 @@ var QueryManager = (function () {
5447
5508
  var aqr = {
5448
5509
  data: result.data,
5449
5510
  loading: false,
5450
- networkStatus: queryInfo.networkStatus || exports.NetworkStatus.ready,
5511
+ networkStatus: exports.NetworkStatus.ready,
5451
5512
  };
5452
5513
  if (hasErrors && options.errorPolicy !== "ignore") {
5453
5514
  aqr.errors = result.errors;
5515
+ aqr.networkStatus = exports.NetworkStatus.error;
5454
5516
  }
5455
5517
  return aqr;
5456
5518
  }, function (networkError) {
@@ -5469,7 +5531,8 @@ var QueryManager = (function () {
5469
5531
  var query = this.transform(options.query).document;
5470
5532
  var variables = this.getVariables(query, options.variables);
5471
5533
  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;
5534
+ var defaults = this.defaultOptions.watchQuery;
5535
+ 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
5536
  var normalized = Object.assign({}, options, {
5474
5537
  query: query,
5475
5538
  variables: variables,
@@ -5491,7 +5554,9 @@ var QueryManager = (function () {
5491
5554
  : fromVariables(normalized.variables));
5492
5555
  concast.cleanup(function () {
5493
5556
  _this.fetchCancelFns.delete(queryId);
5494
- applyNextFetchPolicy(options);
5557
+ if (queryInfo.observableQuery) {
5558
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
5559
+ }
5495
5560
  });
5496
5561
  return concast;
5497
5562
  };
@@ -5687,7 +5752,6 @@ function mergeOptions(defaults, options) {
5687
5752
  var ApolloClient = (function () {
5688
5753
  function ApolloClient(options) {
5689
5754
  var _this = this;
5690
- this.defaultOptions = {};
5691
5755
  this.resetStoreCallbacks = [];
5692
5756
  this.clearStoreCallbacks = [];
5693
5757
  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 +5772,7 @@ var ApolloClient = (function () {
5708
5772
  this.cache = cache;
5709
5773
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5710
5774
  this.queryDeduplication = queryDeduplication;
5711
- this.defaultOptions = defaultOptions || {};
5775
+ this.defaultOptions = defaultOptions || Object.create(null);
5712
5776
  this.typeDefs = typeDefs;
5713
5777
  if (ssrForceFetchDelay) {
5714
5778
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5755,6 +5819,7 @@ var ApolloClient = (function () {
5755
5819
  this.queryManager = new QueryManager({
5756
5820
  cache: this.cache,
5757
5821
  link: this.link,
5822
+ defaultOptions: this.defaultOptions,
5758
5823
  queryDeduplication: queryDeduplication,
5759
5824
  ssrMode: ssrMode,
5760
5825
  clientAwareness: {
@@ -5881,7 +5946,7 @@ var ApolloClient = (function () {
5881
5946
  result.queries = queries;
5882
5947
  result.results = results;
5883
5948
  result.catch(function (error) {
5884
- __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
5949
+ __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error ".concat(error));
5885
5950
  });
5886
5951
  return result;
5887
5952
  };
@@ -5957,8 +6022,8 @@ function useApolloClient(override) {
5957
6022
  var context = React.useContext(getApolloContext());
5958
6023
  var client = override || context.client;
5959
6024
  __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);
6025
+ 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
6026
+ 'instance in via options.') : tsInvariant.invariant(!!client, 29);
5962
6027
  return client;
5963
6028
  }
5964
6029
 
@@ -5989,7 +6054,7 @@ function parser(document) {
5989
6054
  if (cached)
5990
6055
  return cached;
5991
6056
  var variables, type, name;
5992
- __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
6057
+ __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
5993
6058
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
5994
6059
  "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
5995
6060
  var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
@@ -6007,8 +6072,8 @@ function parser(document) {
6007
6072
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6008
6073
  (queries.length || mutations.length || subscriptions.length), 31);
6009
6074
  __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. ") +
6075
+ "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6076
+ "subscriptions and ".concat(mutations.length, " mutations. ") +
6012
6077
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
6013
6078
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6014
6079
  if (!queries.length && !mutations.length)
@@ -6018,8 +6083,8 @@ function parser(document) {
6018
6083
  : mutations.length
6019
6084
  ? mutations
6020
6085
  : subscriptions;
6021
- __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
6022
- (definitions.length + " definitions. ") +
6086
+ __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6087
+ "".concat(definitions.length, " definitions. ") +
6023
6088
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 33);
6024
6089
  var definition = definitions[0];
6025
6090
  variables = definition.variableDefinitions || [];
@@ -6037,236 +6102,341 @@ function verifyDocumentType(document, type) {
6037
6102
  var operation = parser(document);
6038
6103
  var requiredOperationName = operationName(type);
6039
6104
  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);
6105
+ __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6106
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6042
6107
  }
6043
6108
 
6109
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6044
6110
  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) {
6077
- resolve();
6078
- 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; });
6111
+ if (options === void 0) { options = Object.create(null); }
6112
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
6113
+ }
6114
+ function useInternalState(client, query) {
6115
+ var stateRef = React.useRef();
6116
+ if (!stateRef.current ||
6117
+ client !== stateRef.current.client ||
6118
+ query !== stateRef.current.query) {
6119
+ stateRef.current = new InternalState(client, query);
6120
+ }
6121
+ var state = stateRef.current;
6122
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
6123
+ state.forceUpdate = function () {
6124
+ setTick(function (tick) { return tick + 1; });
6125
+ };
6126
+ return state;
6127
+ }
6128
+ var InternalState = (function () {
6129
+ function InternalState(client, query) {
6130
+ this.client = client;
6131
+ this.query = query;
6132
+ this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
6133
+ verifyDocumentType(query, exports.DocumentType.Query);
6134
+ }
6135
+ InternalState.prototype.forceUpdate = function () {
6136
+ };
6137
+ InternalState.prototype.useQuery = function (options) {
6138
+ this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6139
+ this.useOptions(options);
6140
+ var obsQuery = this.useObservableQuery();
6141
+ this.useSubscriptionEffect(obsQuery);
6142
+ var result = this.getCurrentResult();
6143
+ this.unsafeHandlePartialRefetch(result);
6144
+ return this.toQueryResult(result);
6145
+ };
6146
+ InternalState.prototype.useOptions = function (options) {
6147
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6148
+ if (!equality.equal(watchQueryOptions, this.watchQueryOptions)) {
6149
+ this.watchQueryOptions = watchQueryOptions;
6150
+ }
6151
+ this.ssrDisabled = !!(options.ssr === false ||
6152
+ options.skip);
6153
+ this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
6154
+ this.onError = options.onError || InternalState.prototype.onError;
6155
+ };
6156
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
6157
+ if (_a === void 0) { _a = {}; }
6158
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var defaultOptions = _a.defaultOptions, otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
6159
+ var toMerge = [];
6160
+ var globalDefaults = this.client.defaultOptions.watchQuery;
6161
+ if (globalDefaults)
6162
+ toMerge.push(globalDefaults);
6163
+ if (defaultOptions)
6164
+ toMerge.push(defaultOptions);
6165
+ var latestOptions = this.observable && this.observable.options;
6166
+ if (latestOptions && toMerge.length) {
6167
+ var defaults_1 = toMerge.reduce(mergeOptions, Object.create(null));
6168
+ toMerge.length = 1;
6169
+ toMerge[0] = defaults_1;
6170
+ Object.keys(defaults_1).forEach(function (defaultOptionName) {
6171
+ var currentOptionValue = latestOptions[defaultOptionName];
6172
+ if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
6173
+ !equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
6174
+ defaults_1[defaultOptionName] = defaultOptionName === "variables"
6175
+ ? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
6176
+ }
6177
+ });
6091
6178
  }
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);
6179
+ toMerge.push(otherOptions);
6180
+ var merged = toMerge.reduce(mergeOptions, Object.create(null));
6181
+ var watchQueryOptions = Object.assign(merged, { query: this.query });
6182
+ if (this.renderPromises &&
6183
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6184
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6185
+ watchQueryOptions.fetchPolicy = 'cache-first';
6186
+ }
6187
+ else if (!watchQueryOptions.fetchPolicy) {
6188
+ watchQueryOptions.fetchPolicy = 'cache-first';
6189
+ }
6190
+ if (skip) {
6191
+ var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
6192
+ Object.assign(watchQueryOptions, {
6193
+ initialFetchPolicy: initialFetchPolicy,
6194
+ fetchPolicy: 'standby',
6195
+ });
6099
6196
  }
6100
- else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6101
- obsQuery.setOptions(watchQueryOptions);
6102
- setObsQuery(obsQuery);
6197
+ if (!watchQueryOptions.variables) {
6198
+ watchQueryOptions.variables = {};
6103
6199
  }
6104
- Object.assign(ref.current, {
6105
- client: client,
6106
- query: query,
6107
- options: options,
6108
- watchQueryOptions: watchQueryOptions,
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
+ reobserve: obsQuery.reobserve.bind(obsQuery),
6214
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6215
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6216
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6217
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6218
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6219
+ }); }, [obsQuery]);
6220
+ if (this.renderPromises) {
6221
+ this.renderPromises.registerSSRObservable(obsQuery);
6222
+ if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
6223
+ this.renderPromises.addQueryPromise({
6224
+ getOptions: function () { return obsQuery.options; },
6225
+ fetchData: function () { return new Promise(function (resolve) {
6226
+ var sub = obsQuery.subscribe({
6227
+ next: function (result) {
6228
+ if (!result.loading) {
6229
+ resolve();
6230
+ sub.unsubscribe();
6231
+ }
6232
+ },
6233
+ error: function () {
6234
+ resolve();
6235
+ sub.unsubscribe();
6236
+ },
6237
+ complete: function () {
6238
+ resolve();
6239
+ },
6240
+ });
6241
+ }); },
6242
+ }, function () { return null; });
6243
+ obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
6244
+ }
6245
+ }
6246
+ var prevOptionsRef = React.useRef({
6247
+ watchQueryOptions: this.watchQueryOptions,
6109
6248
  });
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();
6249
+ React.useEffect(function () {
6250
+ if (_this.renderPromises) ;
6251
+ else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
6252
+ obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
6253
+ prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
6254
+ _this.setResult(obsQuery.getCurrentResult());
6255
+ }
6256
+ }, [obsQuery, this.watchQueryOptions]);
6257
+ return obsQuery;
6258
+ };
6259
+ InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
6260
+ var _this = this;
6261
+ React.useEffect(function () {
6262
+ if (_this.renderPromises) {
6263
+ return;
6264
+ }
6265
+ var onNext = function () {
6266
+ var previousResult = _this.result;
6267
+ var result = obsQuery.getCurrentResult();
6268
+ if (previousResult &&
6269
+ previousResult.loading === result.loading &&
6270
+ previousResult.networkStatus === result.networkStatus &&
6271
+ equality.equal(previousResult.data, result.data)) {
6272
+ return;
6273
+ }
6274
+ _this.setResult(result);
6275
+ };
6276
+ var onError = function (error) {
6118
6277
  var last = obsQuery["last"];
6119
- obsQuery.resetLastResults();
6120
- obsQuery.subscribe(forceUpdate, onError);
6121
- obsQuery["last"] = last;
6122
- if (!error.hasOwnProperty('graphQLErrors')) {
6278
+ subscription.unsubscribe();
6279
+ try {
6280
+ obsQuery.resetLastResults();
6281
+ subscription = obsQuery.subscribe(onNext, onError);
6282
+ }
6283
+ finally {
6284
+ obsQuery["last"] = last;
6285
+ }
6286
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
6123
6287
  throw error;
6124
6288
  }
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 });
6289
+ var previousResult = _this.result;
6290
+ if (!previousResult ||
6291
+ (previousResult && previousResult.loading) ||
6292
+ !equality.equal(error, previousResult.error)) {
6293
+ _this.setResult({
6294
+ data: (previousResult && previousResult.data),
6295
+ error: error,
6296
+ loading: false,
6297
+ networkStatus: exports.NetworkStatus.error,
6298
+ });
6142
6299
  }
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
- }
6300
+ };
6301
+ var subscription = obsQuery.subscribe(onNext, onError);
6302
+ return function () { return subscription.unsubscribe(); };
6303
+ }, [
6304
+ obsQuery,
6305
+ this.renderPromises,
6306
+ this.client.disableNetworkFetches,
6307
+ ]);
6308
+ };
6309
+ InternalState.prototype.setResult = function (nextResult) {
6310
+ var previousResult = this.result;
6311
+ if (previousResult && previousResult.data) {
6312
+ this.previousData = previousResult.data;
6313
+ }
6314
+ this.result = nextResult;
6315
+ this.forceUpdate();
6316
+ this.handleErrorOrCompleted(nextResult);
6317
+ };
6318
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
6164
6319
  if (!result.loading) {
6165
6320
  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);
6321
+ this.onError(result.error);
6167
6322
  }
6168
6323
  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) &&
6324
+ this.onCompleted(result.data);
6325
+ }
6326
+ }
6327
+ };
6328
+ InternalState.prototype.getCurrentResult = function () {
6329
+ var result = this.result;
6330
+ if (!result) {
6331
+ result = this.result = this.observable.getCurrentResult();
6332
+ this.handleErrorOrCompleted(result);
6333
+ }
6334
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
6335
+ this.queryHookOptions.ssr === false) {
6336
+ result = {
6337
+ loading: true,
6338
+ data: void 0,
6339
+ error: void 0,
6340
+ networkStatus: exports.NetworkStatus.loading,
6341
+ };
6342
+ }
6343
+ else if (this.queryHookOptions.skip ||
6344
+ this.watchQueryOptions.fetchPolicy === 'standby') {
6345
+ result = {
6346
+ loading: false,
6347
+ data: void 0,
6348
+ error: void 0,
6349
+ networkStatus: exports.NetworkStatus.ready,
6350
+ };
6351
+ }
6352
+ return result;
6353
+ };
6354
+ InternalState.prototype.toQueryResult = function (result) {
6355
+ var queryResult = this.toQueryResultCache.get(result);
6356
+ if (queryResult)
6357
+ return queryResult;
6358
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
6359
+ 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 }));
6360
+ if (!queryResult.error && isNonEmptyArray(result.errors)) {
6361
+ queryResult.error = new ApolloError({ graphQLErrors: result.errors });
6362
+ }
6363
+ return queryResult;
6364
+ };
6365
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6366
+ if (result.partial &&
6367
+ this.queryHookOptions.partialRefetch &&
6186
6368
  !result.loading &&
6187
6369
  (!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 () { });
6370
+ this.observable.options.fetchPolicy !== 'cache-only') {
6371
+ Object.assign(result, {
6372
+ loading: true,
6373
+ networkStatus: exports.NetworkStatus.refetch,
6374
+ });
6375
+ this.observable.refetch();
6195
6376
  }
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
- }
6377
+ };
6378
+ return InternalState;
6379
+ }());
6216
6380
 
6217
6381
  var EAGER_METHODS = [
6218
6382
  'refetch',
6383
+ 'reobserve',
6219
6384
  'fetchMore',
6220
6385
  'updateQuery',
6221
6386
  'startPolling',
6222
6387
  'subscribeToMore',
6223
6388
  ];
6224
6389
  function useLazyQuery(query, options) {
6225
- var _a = React.useState({
6226
- called: false,
6227
- resolves: [],
6228
- }), 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
- 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
- if (!execution.called) {
6253
- result = tslib.__assign(tslib.__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
6390
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
6391
+ var execOptionsRef = React.useRef();
6392
+ var defaultOptions = internalState.client.defaultOptions.watchQuery;
6393
+ var initialFetchPolicy = (options && options.fetchPolicy) ||
6394
+ (execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
6395
+ (defaultOptions && defaultOptions.fetchPolicy) ||
6396
+ "cache-first";
6397
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
6398
+ var result = Object.assign(useQueryResult, {
6399
+ called: !!execOptionsRef.current,
6400
+ });
6401
+ var eagerMethods = React.useMemo(function () {
6402
+ var eagerMethods = {};
6254
6403
  var _loop_1 = function (key) {
6255
6404
  var method = result[key];
6256
- result[key] = function () {
6257
- var args = [];
6258
- for (var _i = 0; _i < arguments.length; _i++) {
6259
- args[_i] = arguments[_i];
6405
+ eagerMethods[key] = function () {
6406
+ if (!execOptionsRef.current) {
6407
+ execOptionsRef.current = Object.create(null);
6408
+ internalState.forceUpdate();
6260
6409
  }
6261
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { called: true })); });
6262
- return method.apply(void 0, args);
6410
+ return method.apply(this, arguments);
6263
6411
  };
6264
6412
  };
6265
6413
  for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
6266
6414
  var key = EAGER_METHODS_1[_i];
6267
6415
  _loop_1(key);
6268
6416
  }
6269
- }
6417
+ return eagerMethods;
6418
+ }, []);
6419
+ Object.assign(result, eagerMethods);
6420
+ var execute = React.useCallback(function (executeOptions) {
6421
+ var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
6422
+ fetchPolicy: initialFetchPolicy,
6423
+ }).then(function (apolloQueryResult) {
6424
+ apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
6425
+ if (apolloQueryResult.error ||
6426
+ isNonEmptyArray(apolloQueryResult.errors)) {
6427
+ var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
6428
+ if (errorPolicy === "none") {
6429
+ throw apolloQueryResult.error || new ApolloError({
6430
+ graphQLErrors: apolloQueryResult.errors,
6431
+ });
6432
+ }
6433
+ }
6434
+ return internalState.toQueryResult(apolloQueryResult);
6435
+ }).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
6436
+ internalState.forceUpdate();
6437
+ promise.catch(function () { });
6438
+ return promise;
6439
+ }, []);
6270
6440
  return [execute, result];
6271
6441
  }
6272
6442
 
@@ -6282,79 +6452,73 @@ function useMutation(mutation, options) {
6282
6452
  result: result,
6283
6453
  mutationId: 0,
6284
6454
  isMounted: true,
6285
- execute: null,
6286
6455
  client: client,
6287
6456
  mutation: mutation,
6288
6457
  options: options,
6289
6458
  });
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,
6459
+ {
6460
+ Object.assign(ref.current, { client: client, options: options, mutation: mutation });
6461
+ }
6462
+ var execute = React.useCallback(function (executeOptions) {
6463
+ if (executeOptions === void 0) { executeOptions = {}; }
6464
+ var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
6465
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6466
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6467
+ setResult(ref.current.result = {
6468
+ loading: true,
6469
+ error: void 0,
6470
+ data: void 0,
6471
+ called: true,
6472
+ client: client,
6473
+ });
6474
+ }
6475
+ var mutationId = ++ref.current.mutationId;
6476
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
6477
+ return client.mutate(clientOptions).then(function (response) {
6478
+ var _a, _b;
6479
+ var data = response.data, errors = response.errors;
6480
+ var error = errors && errors.length > 0
6481
+ ? new ApolloError({ graphQLErrors: errors })
6482
+ : void 0;
6483
+ if (mutationId === ref.current.mutationId &&
6484
+ !clientOptions.ignoreResults) {
6485
+ var result_1 = {
6308
6486
  called: true,
6487
+ loading: false,
6488
+ data: data,
6489
+ error: error,
6309
6490
  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
- }
6491
+ };
6492
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6493
+ setResult(ref.current.result = result_1);
6348
6494
  }
6349
- if (baseOptions.onError) {
6350
- baseOptions.onError(error);
6351
- return { data: void 0, errors: error };
6495
+ }
6496
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6497
+ (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
6498
+ return response;
6499
+ }).catch(function (error) {
6500
+ var _a, _b;
6501
+ if (mutationId === ref.current.mutationId &&
6502
+ ref.current.isMounted) {
6503
+ var result_2 = {
6504
+ loading: false,
6505
+ error: error,
6506
+ data: void 0,
6507
+ called: true,
6508
+ client: client,
6509
+ };
6510
+ if (!equality.equal(ref.current.result, result_2)) {
6511
+ setResult(ref.current.result = result_2);
6352
6512
  }
6353
- throw error;
6354
- });
6355
- };
6356
- return ref.current.execute;
6357
- }, [client, mutation, options]);
6513
+ }
6514
+ if (baseOptions.onError || clientOptions.onError) {
6515
+ (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
6516
+ (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
6517
+ return { data: void 0, errors: error };
6518
+ }
6519
+ throw error;
6520
+ });
6521
+ }, []);
6358
6522
  var reset = React.useCallback(function () {
6359
6523
  setResult({ called: false, loading: false, client: client });
6360
6524
  }, []);
@@ -6391,14 +6555,16 @@ function useSubscription(subscription, options) {
6391
6555
  if (typeof shouldResubscribe === 'function') {
6392
6556
  shouldResubscribe = !!shouldResubscribe(options);
6393
6557
  }
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);
6558
+ if (options === null || options === void 0 ? void 0 : options.skip) {
6559
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6560
+ setResult({
6561
+ loading: false,
6562
+ data: void 0,
6563
+ error: void 0,
6564
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6565
+ });
6566
+ setObservable(null);
6567
+ }
6402
6568
  }
6403
6569
  else if (shouldResubscribe !== false && (client !== ref.current.client ||
6404
6570
  subscription !== ref.current.subscription ||
@@ -6491,7 +6657,6 @@ exports.HttpLink = HttpLink;
6491
6657
  exports.InMemoryCache = InMemoryCache;
6492
6658
  exports.MissingFieldError = MissingFieldError;
6493
6659
  exports.ObservableQuery = ObservableQuery;
6494
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
6495
6660
  exports.checkFetcher = checkFetcher;
6496
6661
  exports.concat = concat;
6497
6662
  exports.createHttpLink = createHttpLink;
@@ -6516,6 +6681,7 @@ exports.parser = parser;
6516
6681
  exports.resetApolloContext = getApolloContext;
6517
6682
  exports.rewriteURIForGET = rewriteURIForGET;
6518
6683
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
6684
+ exports.selectHttpOptionsAndBodyInternal = selectHttpOptionsAndBodyInternal;
6519
6685
  exports.selectURI = selectURI;
6520
6686
  exports.serializeFetchParameter = serializeFetchParameter;
6521
6687
  exports.split = split;