@apollo/client 3.6.0-beta.0 → 3.6.0-beta.11

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 (171) hide show
  1. package/apollo-client.cjs +583 -458
  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 +25 -19
  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 +366 -306
  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 +256 -196
  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 +1 -1
  135. package/react/ssr/RenderPromises.d.ts.map +1 -1
  136. package/react/ssr/RenderPromises.js +2 -2
  137. package/react/ssr/RenderPromises.js.map +1 -1
  138. package/react/ssr/ssr.cjs +5 -5
  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/utilities.cjs +15 -15
  170. package/utilities/utilities.cjs.map +1 -1
  171. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -18,11 +18,11 @@ function _interopNamespace(e) {
18
18
  if (e && e.__esModule) return e;
19
19
  var n = Object.create(null);
20
20
  if (e) {
21
- Object.keys(e).forEach(function (k) {
21
+ for (var k in e) {
22
22
  n[k] = e[k];
23
- });
23
+ }
24
24
  }
25
- n['default'] = e;
25
+ n["default"] = e;
26
26
  return Object.freeze(n);
27
27
  }
28
28
 
@@ -45,7 +45,7 @@ function shouldInclude(_a, variables) {
45
45
  var evaledValue = false;
46
46
  if (ifArgument.value.kind === 'Variable') {
47
47
  evaledValue = variables && variables[ifArgument.value.name.value];
48
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 37);
48
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 37);
49
49
  }
50
50
  else {
51
51
  evaledValue = ifArgument.value.value;
@@ -82,12 +82,12 @@ function getInclusionDirectives(directives) {
82
82
  return;
83
83
  var directiveArguments = directive.arguments;
84
84
  var directiveName = directive.name.value;
85
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 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);
86
86
  var ifArgument = directiveArguments[0];
87
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 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);
88
88
  var ifValue = ifArgument.value;
89
89
  __DEV__ ? tsInvariant.invariant(ifValue &&
90
- (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 &&
91
91
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
92
92
  result.push({ directive: directive, ifArgument: ifArgument });
93
93
  });
@@ -100,7 +100,7 @@ function getFragmentQueryDocument(document, fragmentName) {
100
100
  var fragments = [];
101
101
  document.definitions.forEach(function (definition) {
102
102
  if (definition.kind === 'OperationDefinition') {
103
- 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, "'") : '', ". ") +
104
104
  'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(41);
105
105
  }
106
106
  if (definition.kind === 'FragmentDefinition') {
@@ -108,7 +108,7 @@ function getFragmentQueryDocument(document, fragmentName) {
108
108
  }
109
109
  });
110
110
  if (typeof actualFragmentName === 'undefined') {
111
- __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.") : tsInvariant.invariant(fragments.length === 1, 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);
112
112
  actualFragmentName = fragments[0].name.value;
113
113
  }
114
114
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -145,7 +145,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
145
145
  return selection;
146
146
  case 'FragmentSpread': {
147
147
  var fragment = fragmentMap && fragmentMap[selection.name.value];
148
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 43);
148
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value, ".")) : tsInvariant.invariant(fragment, 43);
149
149
  return fragment;
150
150
  }
151
151
  default:
@@ -227,7 +227,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
227
227
  argObj[name.value] = null;
228
228
  }
229
229
  else {
230
- 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, "\"") +
231
231
  'is not supported. Use variables instead of inline arguments to ' +
232
232
  'overcome this limitation.') : new tsInvariant.InvariantError(52);
233
233
  }
@@ -279,7 +279,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
279
279
  filterKeys.forEach(function (key) {
280
280
  filteredArgs_1[key] = args[key];
281
281
  });
282
- return directives['connection']['key'] + "(" + stringify(filteredArgs_1) + ")";
282
+ return "".concat(directives['connection']['key'], "(").concat(stringify(filteredArgs_1), ")");
283
283
  }
284
284
  else {
285
285
  return directives['connection']['key'];
@@ -288,17 +288,17 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
288
288
  var completeFieldName = fieldName;
289
289
  if (args) {
290
290
  var stringifiedArgs = stringify(args);
291
- completeFieldName += "(" + stringifiedArgs + ")";
291
+ completeFieldName += "(".concat(stringifiedArgs, ")");
292
292
  }
293
293
  if (directives) {
294
294
  Object.keys(directives).forEach(function (key) {
295
295
  if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
296
296
  return;
297
297
  if (directives[key] && Object.keys(directives[key]).length) {
298
- completeFieldName += "@" + key + "(" + stringify(directives[key]) + ")";
298
+ completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
299
299
  }
300
300
  else {
301
- completeFieldName += "@" + key;
301
+ completeFieldName += "@".concat(key);
302
302
  }
303
303
  });
304
304
  }
@@ -368,11 +368,11 @@ function checkDocument(doc) {
368
368
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
369
369
  .map(function (definition) {
370
370
  if (definition.kind !== 'OperationDefinition') {
371
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(45);
371
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(45);
372
372
  }
373
373
  return definition;
374
374
  });
375
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 46);
375
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 46);
376
376
  return doc;
377
377
  }
378
378
  function getOperationDefinition(doc) {
@@ -703,7 +703,7 @@ function removeClientSetsFromDocument(document) {
703
703
  return modifiedDoc;
704
704
  }
705
705
 
706
- var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
706
+ var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
707
707
  function mergeDeep() {
708
708
  var sources = [];
709
709
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -740,7 +740,7 @@ var DeepMerger = (function () {
740
740
  }
741
741
  if (isNonNullObject(source) && isNonNullObject(target)) {
742
742
  Object.keys(source).forEach(function (sourceKey) {
743
- if (hasOwnProperty$3.call(target, sourceKey)) {
743
+ if (hasOwnProperty$4.call(target, sourceKey)) {
744
744
  var targetValue = target[sourceKey];
745
745
  if (source[sourceKey] !== targetValue) {
746
746
  var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
@@ -1077,7 +1077,7 @@ var prefixCounts = new Map();
1077
1077
  function makeUniqueId(prefix) {
1078
1078
  var count = prefixCounts.get(prefix) || 1;
1079
1079
  prefixCounts.set(prefix, count + 1);
1080
- return prefix + ":" + count + ":" + Math.random().toString(36).slice(2);
1080
+ return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
1081
1081
  }
1082
1082
 
1083
1083
  function stringifyForDisplay(value) {
@@ -1142,7 +1142,7 @@ function validateOperation(operation) {
1142
1142
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1143
1143
  var key = _a[_i];
1144
1144
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1145
- 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);
1146
1146
  }
1147
1147
  }
1148
1148
  return operation;
@@ -1291,9 +1291,9 @@ var concat = ApolloLink.concat;
1291
1291
 
1292
1292
  var execute = ApolloLink.execute;
1293
1293
 
1294
- var version = '3.6.0-beta.0';
1294
+ var version = '3.6.0-beta.11';
1295
1295
 
1296
- var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1296
+ var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1297
1297
  function parseAndCheckHttpResponse(operations) {
1298
1298
  return function (response) { return response
1299
1299
  .text()
@@ -1312,14 +1312,14 @@ function parseAndCheckHttpResponse(operations) {
1312
1312
  })
1313
1313
  .then(function (result) {
1314
1314
  if (response.status >= 300) {
1315
- throwServerError(response, result, "Response not successful: Received status code " + response.status);
1315
+ throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1316
1316
  }
1317
1317
  if (!Array.isArray(result) &&
1318
- !hasOwnProperty$2.call(result, 'data') &&
1319
- !hasOwnProperty$2.call(result, 'errors')) {
1320
- 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)
1321
1321
  ? operations.map(function (op) { return op.operationName; })
1322
- : operations.operationName) + "'.");
1322
+ : operations.operationName, "'."));
1323
1323
  }
1324
1324
  return result;
1325
1325
  }); };
@@ -1331,7 +1331,7 @@ var serializeFetchParameter = function (p, label) {
1331
1331
  serialized = JSON.stringify(p);
1332
1332
  }
1333
1333
  catch (e) {
1334
- 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);
1335
1335
  parseError.parseError = e;
1336
1336
  throw parseError;
1337
1337
  }
@@ -1355,17 +1355,27 @@ var fallbackHttpConfig = {
1355
1355
  options: defaultOptions,
1356
1356
  };
1357
1357
  var defaultPrinter = function (ast, printer) { return printer(ast); };
1358
- var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1358
+ function selectHttpOptionsAndBody(operation, fallbackConfig) {
1359
1359
  var configs = [];
1360
- for (var _i = 3; _i < arguments.length; _i++) {
1361
- configs[_i - 3] = arguments[_i];
1360
+ for (var _i = 2; _i < arguments.length; _i++) {
1361
+ configs[_i - 2] = arguments[_i];
1362
1362
  }
1363
- var options = tslib.__assign(tslib.__assign({}, fallbackConfig.options), { headers: fallbackConfig.headers, credentials: fallbackConfig.credentials });
1364
- var http = fallbackConfig.http || {};
1363
+ configs.unshift(fallbackConfig);
1364
+ return selectHttpOptionsAndBodyInternal.apply(void 0, tslib.__spreadArray([operation,
1365
+ defaultPrinter], configs, false));
1366
+ }
1367
+ function selectHttpOptionsAndBodyInternal(operation, printer) {
1368
+ var configs = [];
1369
+ for (var _i = 2; _i < arguments.length; _i++) {
1370
+ configs[_i - 2] = arguments[_i];
1371
+ }
1372
+ var options = {};
1373
+ var http = {};
1365
1374
  configs.forEach(function (config) {
1366
1375
  options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), headersToLowerCase(config.headers)) });
1367
- if (config.credentials)
1376
+ if (config.credentials) {
1368
1377
  options.credentials = config.credentials;
1378
+ }
1369
1379
  http = tslib.__assign(tslib.__assign({}, http), config.http);
1370
1380
  });
1371
1381
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
@@ -1378,7 +1388,7 @@ var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1378
1388
  options: options,
1379
1389
  body: body,
1380
1390
  };
1381
- };
1391
+ }
1382
1392
  function headersToLowerCase(headers) {
1383
1393
  if (headers) {
1384
1394
  var normalized_1 = Object.create(null);
@@ -1421,7 +1431,7 @@ var selectURI = function (operation, fallbackURI) {
1421
1431
  function rewriteURIForGET(chosenURI, body) {
1422
1432
  var queryParams = [];
1423
1433
  var addQueryParam = function (key, value) {
1424
- queryParams.push(key + "=" + encodeURIComponent(value));
1434
+ queryParams.push("".concat(key, "=").concat(encodeURIComponent(value)));
1425
1435
  };
1426
1436
  if ('query' in body) {
1427
1437
  addQueryParam('query', body.query);
@@ -1493,7 +1503,7 @@ var createHttpLink = function (linkOptions) {
1493
1503
  credentials: context.credentials,
1494
1504
  headers: contextHeaders,
1495
1505
  };
1496
- 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;
1497
1507
  if (body.variables && !includeUnusedVariables) {
1498
1508
  var unusedNames_1 = new Set(Object.keys(body.variables));
1499
1509
  graphql.visit(operation.query, {
@@ -1686,7 +1696,7 @@ function defaultDataIdFromObject(_a, context) {
1686
1696
  if (id === void 0)
1687
1697
  id = _id;
1688
1698
  if (id !== void 0) {
1689
- return __typename + ":" + ((typeof id === "number" ||
1699
+ return "".concat(__typename, ":").concat((typeof id === "number" ||
1690
1700
  typeof id === "string") ? id : JSON.stringify(id));
1691
1701
  }
1692
1702
  }
@@ -1716,7 +1726,7 @@ function fieldNameFromStoreName(storeFieldName) {
1716
1726
  }
1717
1727
  function selectionSetMatchesResult(selectionSet, result, variables) {
1718
1728
  if (isNonNullObject(result)) {
1719
- return Array.isArray(result)
1729
+ return isArray(result)
1720
1730
  ? result.every(function (item) { return selectionSetMatchesResult(selectionSet, item, variables); })
1721
1731
  : selectionSet.selections.every(function (field) {
1722
1732
  if (isField(field) && shouldInclude(field, variables)) {
@@ -1733,11 +1743,12 @@ function selectionSetMatchesResult(selectionSet, result, variables) {
1733
1743
  function storeValueIsStoreObject(value) {
1734
1744
  return isNonNullObject(value) &&
1735
1745
  !isReference(value) &&
1736
- !Array.isArray(value);
1746
+ !isArray(value);
1737
1747
  }
1738
1748
  function makeProcessedFieldsMerger() {
1739
1749
  return new DeepMerger;
1740
1750
  }
1751
+ var isArray = function (a) { return Array.isArray(a); };
1741
1752
 
1742
1753
  var DELETE = Object.create(null);
1743
1754
  var delModifier = function () { return DELETE; };
@@ -2200,7 +2211,7 @@ function supportsResultCaching(store) {
2200
2211
 
2201
2212
  function shallowCopy(value) {
2202
2213
  if (isNonNullObject(value)) {
2203
- return Array.isArray(value)
2214
+ return isArray(value)
2204
2215
  ? value.slice(0)
2205
2216
  : tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
2206
2217
  }
@@ -2422,7 +2433,7 @@ var StoreReader = (function () {
2422
2433
  !context.store.has(objectOrReference.__ref)) {
2423
2434
  return {
2424
2435
  result: this.canon.empty,
2425
- missing: "Dangling reference to missing " + objectOrReference.__ref + " object",
2436
+ missing: "Dangling reference to missing ".concat(objectOrReference.__ref, " object"),
2426
2437
  };
2427
2438
  }
2428
2439
  var variables = context.variables, policies = context.policies, store = context.store;
@@ -2457,13 +2468,13 @@ var StoreReader = (function () {
2457
2468
  if (fieldValue === void 0) {
2458
2469
  if (!addTypenameToDocument.added(selection)) {
2459
2470
  missing = context.merge(missing, (_a = {},
2460
- _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)
2461
2472
  ? objectOrReference.__ref + " object"
2462
2473
  : "object " + JSON.stringify(objectOrReference, null, 2)),
2463
2474
  _a));
2464
2475
  }
2465
2476
  }
2466
- else if (Array.isArray(fieldValue)) {
2477
+ else if (isArray(fieldValue)) {
2467
2478
  fieldValue = handleMissing(_this.executeSubSelectedArray({
2468
2479
  field: selection,
2469
2480
  array: fieldValue,
@@ -2522,7 +2533,7 @@ var StoreReader = (function () {
2522
2533
  if (item === null) {
2523
2534
  return null;
2524
2535
  }
2525
- if (Array.isArray(item)) {
2536
+ if (isArray(item)) {
2526
2537
  return handleMissing(_this.executeSubSelectedArray({
2527
2538
  field: field,
2528
2539
  array: item,
@@ -2567,7 +2578,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
2567
2578
  var workSet_1 = new Set([fieldValue]);
2568
2579
  workSet_1.forEach(function (value) {
2569
2580
  if (isNonNullObject(value)) {
2570
- __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!isReference(value), 5);
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);
2571
2582
  Object.values(value).forEach(workSet_1.add, workSet_1);
2572
2583
  }
2573
2584
  });
@@ -2654,10 +2665,10 @@ function keyFieldsFnFromSpecifier(specifier) {
2654
2665
  hasOwn.call(object, schemaKeyPath[0])) {
2655
2666
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
2656
2667
  }
2657
- __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);
2658
2669
  return extracted;
2659
2670
  });
2660
- return context.typename + ":" + JSON.stringify(keyObject);
2671
+ return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
2661
2672
  });
2662
2673
  }
2663
2674
  function keyArgsFnFromSpecifier(specifier) {
@@ -2716,13 +2727,13 @@ function getSpecifierPaths(spec) {
2716
2727
  var paths_1 = info.paths = [];
2717
2728
  var currentPath_1 = [];
2718
2729
  spec.forEach(function (s, i) {
2719
- if (Array.isArray(s)) {
2730
+ if (isArray(s)) {
2720
2731
  getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
2721
2732
  currentPath_1.length = 0;
2722
2733
  }
2723
2734
  else {
2724
2735
  currentPath_1.push(s);
2725
- if (!Array.isArray(spec[i + 1])) {
2736
+ if (!isArray(spec[i + 1])) {
2726
2737
  paths_1.push(currentPath_1.slice(0));
2727
2738
  currentPath_1.length = 0;
2728
2739
  }
@@ -2737,14 +2748,14 @@ function extractKey(object, key) {
2737
2748
  function extractKeyPath(object, path, extract) {
2738
2749
  extract = extract || extractKey;
2739
2750
  return normalize(path.reduce(function reducer(obj, key) {
2740
- return Array.isArray(obj)
2751
+ return isArray(obj)
2741
2752
  ? obj.map(function (child) { return reducer(child, key); })
2742
2753
  : obj && extract(obj, key);
2743
2754
  }, object));
2744
2755
  }
2745
2756
  function normalize(value) {
2746
2757
  if (isNonNullObject(value)) {
2747
- if (Array.isArray(value)) {
2758
+ if (isArray(value)) {
2748
2759
  return value.map(normalize);
2749
2760
  }
2750
2761
  return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
@@ -2807,7 +2818,7 @@ var Policies = (function () {
2807
2818
  var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
2808
2819
  while (keyFn) {
2809
2820
  var specifierOrId = keyFn(object, context);
2810
- if (Array.isArray(specifierOrId)) {
2821
+ if (isArray(specifierOrId)) {
2811
2822
  keyFn = keyFieldsFnFromSpecifier(specifierOrId);
2812
2823
  }
2813
2824
  else {
@@ -2850,7 +2861,7 @@ var Policies = (function () {
2850
2861
  setMerge(existing, incoming.merge);
2851
2862
  existing.keyFn =
2852
2863
  keyFields === false ? nullKeyFieldsFn :
2853
- Array.isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2864
+ isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
2854
2865
  typeof keyFields === "function" ? keyFields :
2855
2866
  existing.keyFn;
2856
2867
  if (fields) {
@@ -2864,7 +2875,7 @@ var Policies = (function () {
2864
2875
  var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
2865
2876
  existing.keyFn =
2866
2877
  keyArgs === false ? simpleKeyArgsFn :
2867
- Array.isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2878
+ isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
2868
2879
  typeof keyArgs === "function" ? keyArgs :
2869
2880
  existing.keyFn;
2870
2881
  if (typeof read === "function") {
@@ -2883,7 +2894,7 @@ var Policies = (function () {
2883
2894
  var rootId = "ROOT_" + which.toUpperCase();
2884
2895
  var old = this.rootTypenamesById[rootId];
2885
2896
  if (typename !== old) {
2886
- __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);
2887
2898
  if (old)
2888
2899
  delete this.rootIdsByTypename[old];
2889
2900
  this.rootIdsByTypename[typename] = rootId;
@@ -2967,7 +2978,7 @@ var Policies = (function () {
2967
2978
  if (supertypeSet.has(supertype)) {
2968
2979
  if (!typenameSupertypeSet.has(supertype)) {
2969
2980
  if (checkingFuzzySubtypes) {
2970
- __DEV__ && tsInvariant.invariant.warn("Inferring subtype " + typename + " of supertype " + supertype);
2981
+ __DEV__ && tsInvariant.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
2971
2982
  }
2972
2983
  typenameSupertypeSet.add(supertype);
2973
2984
  }
@@ -3009,7 +3020,7 @@ var Policies = (function () {
3009
3020
  var args = argsFromFieldSpecifier(fieldSpec);
3010
3021
  while (keyFn) {
3011
3022
  var specifierOrString = keyFn(args, context);
3012
- if (Array.isArray(specifierOrString)) {
3023
+ if (isArray(specifierOrString)) {
3013
3024
  keyFn = keyArgsFnFromSpecifier(specifierOrString);
3014
3025
  }
3015
3026
  else {
@@ -3121,7 +3132,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3121
3132
  }
3122
3133
  }
3123
3134
  if (__DEV__ && options.from === void 0) {
3124
- __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))));
3125
3136
  }
3126
3137
  if (void 0 === options.variables) {
3127
3138
  options.variables = variables;
@@ -3130,7 +3141,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3130
3141
  }
3131
3142
  function makeMergeObjectsFunction(store) {
3132
3143
  return function mergeObjects(existing, incoming) {
3133
- if (Array.isArray(existing) || Array.isArray(incoming)) {
3144
+ if (isArray(existing) || isArray(incoming)) {
3134
3145
  throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
3135
3146
  }
3136
3147
  if (isNonNullObject(existing) &&
@@ -3161,7 +3172,7 @@ function makeMergeObjectsFunction(store) {
3161
3172
  }
3162
3173
 
3163
3174
  function getContextFlavor(context, clientOnly, deferred) {
3164
- var key = "" + clientOnly + deferred;
3175
+ var key = "".concat(clientOnly).concat(deferred);
3165
3176
  var flavored = context.flavors.get(key);
3166
3177
  if (!flavored) {
3167
3178
  context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
@@ -3203,7 +3214,7 @@ var StoreWriter = (function () {
3203
3214
  context: context,
3204
3215
  });
3205
3216
  if (!isReference(ref)) {
3206
- 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);
3207
3218
  }
3208
3219
  context.incomingById.forEach(function (_a, dataId) {
3209
3220
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -3308,7 +3319,7 @@ var StoreWriter = (function () {
3308
3319
  !context.deferred &&
3309
3320
  !addTypenameToDocument.added(field) &&
3310
3321
  !policies.getReadFunction(typename, field.name.value)) {
3311
- __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));
3312
3323
  }
3313
3324
  });
3314
3325
  try {
@@ -3359,7 +3370,7 @@ var StoreWriter = (function () {
3359
3370
  if (!field.selectionSet || value === null) {
3360
3371
  return __DEV__ ? cloneDeep(value) : value;
3361
3372
  }
3362
- if (Array.isArray(value)) {
3373
+ if (isArray(value)) {
3363
3374
  return value.map(function (item, i) {
3364
3375
  var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
3365
3376
  maybeRecycleChildMergeTree(mergeTree, i);
@@ -3424,7 +3435,7 @@ var StoreWriter = (function () {
3424
3435
  var _a;
3425
3436
  var _this = this;
3426
3437
  if (mergeTree.map.size && !isReference(incoming)) {
3427
- var e_1 = (!Array.isArray(incoming) &&
3438
+ var e_1 = (!isArray(incoming) &&
3428
3439
  (isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
3429
3440
  var i_1 = incoming;
3430
3441
  if (e_1 && !getStorageArgs) {
@@ -3432,7 +3443,7 @@ var StoreWriter = (function () {
3432
3443
  }
3433
3444
  var changedFields_1;
3434
3445
  var getValue_1 = function (from, name) {
3435
- return Array.isArray(from)
3446
+ return isArray(from)
3436
3447
  ? (typeof name === "number" ? from[name] : void 0)
3437
3448
  : context.store.getFieldValue(from, String(name));
3438
3449
  };
@@ -3454,7 +3465,7 @@ var StoreWriter = (function () {
3454
3465
  }
3455
3466
  });
3456
3467
  if (changedFields_1) {
3457
- 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));
3458
3469
  changedFields_1.forEach(function (value, name) {
3459
3470
  incoming[name] = value;
3460
3471
  });
@@ -3530,13 +3541,13 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3530
3541
  var parentType = store.getFieldValue(existingRef, "__typename") ||
3531
3542
  store.getFieldValue(incomingObj, "__typename");
3532
3543
  var fieldName = fieldNameFromStoreName(storeFieldName);
3533
- var typeDotName = parentType + "." + fieldName;
3544
+ var typeDotName = "".concat(parentType, ".").concat(fieldName);
3534
3545
  if (warnings.has(typeDotName))
3535
3546
  return;
3536
3547
  warnings.add(typeDotName);
3537
3548
  var childTypenames = [];
3538
- if (!Array.isArray(existing) &&
3539
- !Array.isArray(incoming)) {
3549
+ if (!isArray(existing) &&
3550
+ !isArray(incoming)) {
3540
3551
  [existing, incoming].forEach(function (child) {
3541
3552
  var typename = store.getFieldValue(child, "__typename");
3542
3553
  if (typeof typename === "string" &&
@@ -3545,10 +3556,10 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3545
3556
  }
3546
3557
  });
3547
3558
  }
3548
- __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
3549
3560
  ? "either ensure all objects of type " +
3550
3561
  childTypenames.join(" and ") + " have an ID or a custom merge function, or "
3551
- : "") + "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"));
3552
3563
  }
3553
3564
 
3554
3565
  var InMemoryCache = (function (_super) {
@@ -3855,11 +3866,11 @@ var generateErrorMessage = function (err) {
3855
3866
  var errorMessage = error
3856
3867
  ? error.message
3857
3868
  : 'Error message not found.';
3858
- message += errorMessage + "\n";
3869
+ message += "".concat(errorMessage, "\n");
3859
3870
  });
3860
3871
  }
3861
3872
  if (err.networkError) {
3862
- message += err.networkError.message + "\n";
3873
+ message += "".concat(err.networkError.message, "\n");
3863
3874
  }
3864
3875
  message = message.replace(/\n$/, '');
3865
3876
  return message;
@@ -3894,8 +3905,7 @@ function isNetworkRequestInFlight(networkStatus) {
3894
3905
  return networkStatus ? networkStatus < 7 : false;
3895
3906
  }
3896
3907
 
3897
- var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
3898
- var warnedAboutUpdateQuery = false;
3908
+ var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
3899
3909
  var ObservableQuery = (function (_super) {
3900
3910
  tslib.__extends(ObservableQuery, _super);
3901
3911
  function ObservableQuery(_a) {
@@ -3929,11 +3939,10 @@ var ObservableQuery = (function (_super) {
3929
3939
  _this.observers = new Set();
3930
3940
  _this.subscriptions = new Set();
3931
3941
  _this.isTornDown = false;
3932
- _this.options = options;
3942
+ _this.options = tslib.__assign({ initialFetchPolicy: options.fetchPolicy || "cache-first" }, options);
3933
3943
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3934
3944
  var opDef = getOperationDefinition(options.query);
3935
3945
  _this.queryName = opDef && opDef.name && opDef.name.value;
3936
- _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
3937
3946
  _this.queryManager = queryManager;
3938
3947
  _this.queryInfo = queryInfo;
3939
3948
  return _this;
@@ -4041,7 +4050,7 @@ var ObservableQuery = (function (_super) {
4041
4050
  pollInterval: 0,
4042
4051
  };
4043
4052
  var fetchPolicy = this.options.fetchPolicy;
4044
- if (fetchPolicy === 'standby' || fetchPolicy === 'cache-and-network') {
4053
+ if (fetchPolicy === 'cache-and-network') {
4045
4054
  reobserveOptions.fetchPolicy = fetchPolicy;
4046
4055
  }
4047
4056
  else if (fetchPolicy === 'no-cache') {
@@ -4050,11 +4059,11 @@ var ObservableQuery = (function (_super) {
4050
4059
  else {
4051
4060
  reobserveOptions.fetchPolicy = 'network-only';
4052
4061
  }
4053
- if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
4062
+ if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
4054
4063
  var queryDef = getQueryDefinition(this.options.query);
4055
4064
  var vars = queryDef.variableDefinitions;
4056
4065
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4057
- __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 })?"));
4058
4067
  }
4059
4068
  }
4060
4069
  if (variables && !equality.equal(this.options.variables, variables)) {
@@ -4067,35 +4076,49 @@ var ObservableQuery = (function (_super) {
4067
4076
  var _this = this;
4068
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" });
4069
4078
  var qid = this.queryManager.generateQueryId();
4079
+ var queryInfo = this.queryInfo;
4080
+ var originalNetworkStatus = queryInfo.networkStatus;
4081
+ queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4070
4082
  if (combinedOptions.notifyOnNetworkStatusChange) {
4071
- this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
4072
4083
  this.observe();
4073
4084
  }
4085
+ var updatedQuerySet = new Set();
4074
4086
  return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
4075
- var data = fetchMoreResult.data;
4076
- var updateQuery = fetchMoreOptions.updateQuery;
4077
- if (updateQuery) {
4078
- if (__DEV__ &&
4079
- !warnedAboutUpdateQuery) {
4080
- __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.");
4081
- warnedAboutUpdateQuery = true;
4082
- }
4083
- _this.updateQuery(function (previous) { return updateQuery(previous, {
4084
- fetchMoreResult: data,
4085
- variables: combinedOptions.variables,
4086
- }); });
4087
- }
4088
- else {
4089
- _this.queryManager.cache.writeQuery({
4090
- query: combinedOptions.query,
4091
- variables: combinedOptions.variables,
4092
- data: data,
4093
- });
4094
- }
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
+ });
4095
4117
  return fetchMoreResult;
4096
4118
  }).finally(function () {
4097
- _this.queryManager.stopQuery(qid);
4098
- _this.reobserve();
4119
+ if (!updatedQuerySet.has(_this.options.query)) {
4120
+ reobserveCacheFirst(_this);
4121
+ }
4099
4122
  });
4100
4123
  };
4101
4124
  ObservableQuery.prototype.subscribeToMore = function (options) {
@@ -4148,7 +4171,7 @@ var ObservableQuery = (function (_super) {
4148
4171
  return Promise.resolve();
4149
4172
  }
4150
4173
  return this.reobserve({
4151
- fetchPolicy: this.initialFetchPolicy,
4174
+ fetchPolicy: this.options.initialFetchPolicy,
4152
4175
  variables: variables,
4153
4176
  }, exports.NetworkStatus.setVariables);
4154
4177
  };
@@ -4180,6 +4203,26 @@ var ObservableQuery = (function (_super) {
4180
4203
  this.options.pollInterval = 0;
4181
4204
  this.updatePolling();
4182
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
+ };
4183
4226
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4184
4227
  this.queryManager.setObservableQuery(this);
4185
4228
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -4242,16 +4285,18 @@ var ObservableQuery = (function (_super) {
4242
4285
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
4243
4286
  newNetworkStatus === exports.NetworkStatus.poll;
4244
4287
  var oldVariables = this.options.variables;
4288
+ var oldFetchPolicy = this.options.fetchPolicy;
4289
+ var mergedOptions = mergeOptions(this.options, newOptions || {});
4245
4290
  var options = useDisposableConcast
4246
- ? compact(this.options, newOptions)
4247
- : assign(this.options, compact(newOptions));
4291
+ ? mergedOptions
4292
+ : assign(this.options, mergedOptions);
4248
4293
  if (!useDisposableConcast) {
4249
4294
  this.updatePolling();
4250
4295
  if (newOptions &&
4251
4296
  newOptions.variables &&
4252
- !newOptions.fetchPolicy &&
4253
- !equality.equal(newOptions.variables, oldVariables)) {
4254
- options.fetchPolicy = this.initialFetchPolicy;
4297
+ !equality.equal(newOptions.variables, oldVariables) &&
4298
+ (!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
4299
+ this.applyNextFetchPolicy("variables-changed", options);
4255
4300
  if (newNetworkStatus === void 0) {
4256
4301
  newNetworkStatus = exports.NetworkStatus.setVariables;
4257
4302
  }
@@ -4281,8 +4326,11 @@ var ObservableQuery = (function (_super) {
4281
4326
  this.reportResult(this.getCurrentResult(false), this.variables);
4282
4327
  };
4283
4328
  ObservableQuery.prototype.reportResult = function (result, variables) {
4284
- if (this.getLastError() || this.isDifferentFromLastResult(result)) {
4285
- 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
+ }
4286
4334
  iterateObserversSafely(this.observers, 'next', result);
4287
4335
  }
4288
4336
  };
@@ -4312,20 +4360,29 @@ var ObservableQuery = (function (_super) {
4312
4360
  return ObservableQuery;
4313
4361
  }(zenObservableTs.Observable));
4314
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
+ }
4315
4380
  function defaultSubscriptionObserverErrorCallback(error) {
4316
4381
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4317
4382
  }
4318
4383
  function logMissingFieldErrors(missing) {
4319
4384
  if (__DEV__ && missing) {
4320
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + JSON.stringify(missing), missing);
4321
- }
4322
- }
4323
- function applyNextFetchPolicy(options) {
4324
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
4325
- if (nextFetchPolicy) {
4326
- options.fetchPolicy = typeof nextFetchPolicy === "function"
4327
- ? nextFetchPolicy.call(options, fetchPolicy)
4328
- : nextFetchPolicy;
4385
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4329
4386
  }
4330
4387
  }
4331
4388
 
@@ -4498,7 +4555,7 @@ var LocalState = (function () {
4498
4555
  }
4499
4556
  else {
4500
4557
  fragment = fragmentMap[selection.name.value];
4501
- __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);
4502
4559
  }
4503
4560
  if (fragment && fragment.typeCondition) {
4504
4561
  typeCondition = fragment.typeCondition.name.value;
@@ -4710,11 +4767,12 @@ var QueryInfo = (function () {
4710
4767
  if (oq) {
4711
4768
  oq["queryInfo"] = this;
4712
4769
  this.listeners.add(this.oqListener = function () {
4713
- if (_this.getDiff().fromOptimisticTransaction) {
4770
+ var diff = _this.getDiff();
4771
+ if (diff.fromOptimisticTransaction) {
4714
4772
  oq["observe"]();
4715
4773
  }
4716
4774
  else {
4717
- oq.reobserve();
4775
+ reobserveCacheFirst(oq);
4718
4776
  }
4719
4777
  });
4720
4778
  }
@@ -4856,10 +4914,10 @@ function shouldWriteResult(result, errorPolicy) {
4856
4914
  return writeWithErrors;
4857
4915
  }
4858
4916
 
4859
- var hasOwnProperty = Object.prototype.hasOwnProperty;
4917
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
4860
4918
  var QueryManager = (function () {
4861
4919
  function QueryManager(_a) {
4862
- 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;
4863
4921
  this.clientAwareness = {};
4864
4922
  this.queries = new Map();
4865
4923
  this.fetchCancelFns = new Map();
@@ -4870,6 +4928,7 @@ var QueryManager = (function () {
4870
4928
  this.inFlightLinkObservables = new Map();
4871
4929
  this.cache = cache;
4872
4930
  this.link = link;
4931
+ this.defaultOptions = defaultOptions || Object.create(null);
4873
4932
  this.queryDeduplication = queryDeduplication;
4874
4933
  this.clientAwareness = clientAwareness;
4875
4934
  this.localState = localState || new LocalState({ cache: cache });
@@ -4891,11 +4950,12 @@ var QueryManager = (function () {
4891
4950
  this.fetchCancelFns.clear();
4892
4951
  };
4893
4952
  QueryManager.prototype.mutate = function (_a) {
4894
- 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;
4895
4955
  return tslib.__awaiter(this, void 0, void 0, function () {
4896
4956
  var mutationId, mutationStoreValue, self;
4897
- return tslib.__generator(this, function (_f) {
4898
- switch (_f.label) {
4957
+ return tslib.__generator(this, function (_h) {
4958
+ switch (_h.label) {
4899
4959
  case 0:
4900
4960
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4901
4961
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
@@ -4907,8 +4967,8 @@ var QueryManager = (function () {
4907
4967
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4908
4968
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4909
4969
  case 1:
4910
- variables = (_f.sent());
4911
- _f.label = 2;
4970
+ variables = (_h.sent());
4971
+ _h.label = 2;
4912
4972
  case 2:
4913
4973
  mutationStoreValue = this.mutationStore &&
4914
4974
  (this.mutationStore[mutationId] = {
@@ -5009,7 +5069,7 @@ var QueryManager = (function () {
5009
5069
  this.queries.forEach(function (_a, queryId) {
5010
5070
  var observableQuery = _a.observableQuery;
5011
5071
  var queryName = observableQuery && observableQuery.queryName;
5012
- if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
5072
+ if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
5013
5073
  return;
5014
5074
  }
5015
5075
  var updater = updateQueries_1[queryName];
@@ -5289,7 +5349,7 @@ var QueryManager = (function () {
5289
5349
  if (__DEV__ && queryNamesAndDocs.size) {
5290
5350
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
5291
5351
  if (!included) {
5292
- __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"));
5293
5353
  }
5294
5354
  });
5295
5355
  }
@@ -5361,8 +5421,10 @@ var QueryManager = (function () {
5361
5421
  };
5362
5422
  QueryManager.prototype.removeQuery = function (queryId) {
5363
5423
  this.fetchCancelFns.delete(queryId);
5364
- this.getQuery(queryId).stop();
5365
- this.queries.delete(queryId);
5424
+ if (this.queries.has(queryId)) {
5425
+ this.getQuery(queryId).stop();
5426
+ this.queries.delete(queryId);
5427
+ }
5366
5428
  };
5367
5429
  QueryManager.prototype.broadcastQueries = function () {
5368
5430
  if (this.onBroadcast)
@@ -5446,10 +5508,11 @@ var QueryManager = (function () {
5446
5508
  var aqr = {
5447
5509
  data: result.data,
5448
5510
  loading: false,
5449
- networkStatus: queryInfo.networkStatus || exports.NetworkStatus.ready,
5511
+ networkStatus: exports.NetworkStatus.ready,
5450
5512
  };
5451
5513
  if (hasErrors && options.errorPolicy !== "ignore") {
5452
5514
  aqr.errors = result.errors;
5515
+ aqr.networkStatus = exports.NetworkStatus.error;
5453
5516
  }
5454
5517
  return aqr;
5455
5518
  }, function (networkError) {
@@ -5468,7 +5531,8 @@ var QueryManager = (function () {
5468
5531
  var query = this.transform(options.query).document;
5469
5532
  var variables = this.getVariables(query, options.variables);
5470
5533
  var queryInfo = this.getQuery(queryId);
5471
- 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;
5472
5536
  var normalized = Object.assign({}, options, {
5473
5537
  query: query,
5474
5538
  variables: variables,
@@ -5490,7 +5554,9 @@ var QueryManager = (function () {
5490
5554
  : fromVariables(normalized.variables));
5491
5555
  concast.cleanup(function () {
5492
5556
  _this.fetchCancelFns.delete(queryId);
5493
- applyNextFetchPolicy(options);
5557
+ if (queryInfo.observableQuery) {
5558
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
5559
+ }
5494
5560
  });
5495
5561
  return concast;
5496
5562
  };
@@ -5686,7 +5752,6 @@ function mergeOptions(defaults, options) {
5686
5752
  var ApolloClient = (function () {
5687
5753
  function ApolloClient(options) {
5688
5754
  var _this = this;
5689
- this.defaultOptions = {};
5690
5755
  this.resetStoreCallbacks = [];
5691
5756
  this.clearStoreCallbacks = [];
5692
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' &&
@@ -5707,7 +5772,7 @@ var ApolloClient = (function () {
5707
5772
  this.cache = cache;
5708
5773
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
5709
5774
  this.queryDeduplication = queryDeduplication;
5710
- this.defaultOptions = defaultOptions || {};
5775
+ this.defaultOptions = defaultOptions || Object.create(null);
5711
5776
  this.typeDefs = typeDefs;
5712
5777
  if (ssrForceFetchDelay) {
5713
5778
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -5754,6 +5819,7 @@ var ApolloClient = (function () {
5754
5819
  this.queryManager = new QueryManager({
5755
5820
  cache: this.cache,
5756
5821
  link: this.link,
5822
+ defaultOptions: this.defaultOptions,
5757
5823
  queryDeduplication: queryDeduplication,
5758
5824
  ssrMode: ssrMode,
5759
5825
  clientAwareness: {
@@ -5880,7 +5946,7 @@ var ApolloClient = (function () {
5880
5946
  result.queries = queries;
5881
5947
  result.results = results;
5882
5948
  result.catch(function (error) {
5883
- __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));
5884
5950
  });
5885
5951
  return result;
5886
5952
  };
@@ -5956,8 +6022,8 @@ function useApolloClient(override) {
5956
6022
  var context = React.useContext(getApolloContext());
5957
6023
  var client = override || context.client;
5958
6024
  __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5959
- 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient' +
5960
- '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);
5961
6027
  return client;
5962
6028
  }
5963
6029
 
@@ -5988,7 +6054,7 @@ function parser(document) {
5988
6054
  if (cached)
5989
6055
  return cached;
5990
6056
  var variables, type, name;
5991
- __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 ") +
5992
6058
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
5993
6059
  "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
5994
6060
  var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
@@ -6006,8 +6072,8 @@ function parser(document) {
6006
6072
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6007
6073
  (queries.length || mutations.length || subscriptions.length), 31);
6008
6074
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6009
- (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
6010
- ("subscriptions and " + mutations.length + " mutations. ") +
6075
+ "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6076
+ "subscriptions and ".concat(mutations.length, " mutations. ") +
6011
6077
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
6012
6078
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6013
6079
  if (!queries.length && !mutations.length)
@@ -6017,8 +6083,8 @@ function parser(document) {
6017
6083
  : mutations.length
6018
6084
  ? mutations
6019
6085
  : subscriptions;
6020
- __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
6021
- (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. ") +
6022
6088
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 33);
6023
6089
  var definition = definitions[0];
6024
6090
  variables = definition.variableDefinitions || [];
@@ -6036,278 +6102,341 @@ function verifyDocumentType(document, type) {
6036
6102
  var operation = parser(document);
6037
6103
  var requiredOperationName = operationName(type);
6038
6104
  var usedOperationName = operationName(operation.type);
6039
- __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
6040
- (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);
6041
6107
  }
6042
6108
 
6109
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
6043
6110
  function useQuery(query, options) {
6044
- var _a;
6045
- var context = React.useContext(getApolloContext());
6046
- var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6047
- verifyDocumentType(query, exports.DocumentType.Query);
6048
- var _b = React.useState(function () {
6049
- var watchQueryOptions = createWatchQueryOptions(query, options);
6050
- var obsQuery = null;
6051
- if (context.renderPromises) {
6052
- obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
6053
- }
6054
- if (!obsQuery) {
6055
- obsQuery = client.watchQuery(watchQueryOptions);
6056
- if (context.renderPromises) {
6057
- context.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
6058
- }
6059
- }
6060
- if (context.renderPromises &&
6061
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6062
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6063
- obsQuery.getCurrentResult().loading) {
6064
- context.renderPromises.addQueryPromise({
6065
- getOptions: function () { return createWatchQueryOptions(query, options); },
6066
- fetchData: function () { return new Promise(function (resolve) {
6067
- var sub = obsQuery.subscribe({
6068
- next: function (result) {
6069
- if (!result.loading) {
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
+ });
6178
+ }
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
+ });
6196
+ }
6197
+ if (!watchQueryOptions.variables) {
6198
+ watchQueryOptions.variables = {};
6199
+ }
6200
+ return watchQueryOptions;
6201
+ };
6202
+ InternalState.prototype.onCompleted = function (data) { };
6203
+ InternalState.prototype.onError = function (error) { };
6204
+ InternalState.prototype.useObservableQuery = function () {
6205
+ var _this = this;
6206
+ var obsQuery = this.observable =
6207
+ this.renderPromises
6208
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
6209
+ || this.observable
6210
+ || this.client.watchQuery(this.watchQueryOptions);
6211
+ this.obsQueryFields = React.useMemo(function () { return ({
6212
+ refetch: obsQuery.refetch.bind(obsQuery),
6213
+ 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 () {
6070
6234
  resolve();
6071
6235
  sub.unsubscribe();
6072
- }
6073
- },
6074
- error: function () {
6075
- resolve();
6076
- sub.unsubscribe();
6077
- },
6078
- complete: function () {
6079
- resolve();
6080
- },
6081
- });
6082
- }); },
6083
- }, function () { return null; });
6236
+ },
6237
+ complete: function () {
6238
+ resolve();
6239
+ },
6240
+ });
6241
+ }); },
6242
+ }, function () { return null; });
6243
+ obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
6244
+ }
6084
6245
  }
6246
+ var prevOptionsRef = React.useRef({
6247
+ watchQueryOptions: this.watchQueryOptions,
6248
+ });
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]);
6085
6257
  return obsQuery;
6086
- }), obsQuery = _b[0], setObsQuery = _b[1];
6087
- var _c = React.useState(function () {
6088
- var _a, _b;
6089
- var result = obsQuery.getCurrentResult();
6090
- if (!result.loading && options) {
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) {
6277
+ var last = obsQuery["last"];
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')) {
6287
+ throw error;
6288
+ }
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
+ });
6299
+ }
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) {
6319
+ if (!result.loading) {
6091
6320
  if (result.error) {
6092
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6321
+ this.onError(result.error);
6093
6322
  }
6094
6323
  else if (result.data) {
6095
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6324
+ this.onCompleted(result.data);
6096
6325
  }
6097
6326
  }
6098
- return result;
6099
- }), result = _c[0], setResult = _c[1];
6100
- var ref = React.useRef({
6101
- client: client,
6102
- query: query,
6103
- options: options,
6104
- result: result,
6105
- previousData: void 0,
6106
- watchQueryOptions: createWatchQueryOptions(query, options),
6107
- });
6108
- React.useEffect(function () {
6109
- var _a, _b;
6110
- var watchQueryOptions = createWatchQueryOptions(query, options);
6111
- var nextResult;
6112
- if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
6113
- var obsQuery_1 = client.watchQuery(watchQueryOptions);
6114
- setObsQuery(obsQuery_1);
6115
- nextResult = obsQuery_1.getCurrentResult();
6116
- }
6117
- else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6118
- obsQuery.setOptions(watchQueryOptions).catch(function () { });
6119
- nextResult = obsQuery.getCurrentResult();
6120
- ref.current.watchQueryOptions = watchQueryOptions;
6121
- }
6122
- if (nextResult) {
6123
- var previousResult = ref.current.result;
6124
- if (previousResult.data) {
6125
- ref.current.previousData = previousResult.data;
6126
- }
6127
- setResult(ref.current.result = nextResult);
6128
- if (!nextResult.loading && options) {
6129
- if (!result.loading) {
6130
- if (result.error) {
6131
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6132
- }
6133
- else if (result.data) {
6134
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6135
- }
6136
- }
6137
- }
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);
6138
6333
  }
6139
- Object.assign(ref.current, { client: client, query: query, options: options });
6140
- }, [obsQuery, client, query, options]);
6141
- React.useEffect(function () {
6142
- if (context.renderPromises) {
6143
- return;
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
+ };
6144
6342
  }
6145
- var subscription = obsQuery.subscribe(onNext, onError);
6146
- function onNext() {
6147
- var _a, _b;
6148
- var previousResult = ref.current.result;
6149
- var result = obsQuery.getCurrentResult();
6150
- if (previousResult &&
6151
- previousResult.loading === result.loading &&
6152
- previousResult.networkStatus === result.networkStatus &&
6153
- equality.equal(previousResult.data, result.data)) {
6154
- return;
6155
- }
6156
- if (previousResult.data) {
6157
- ref.current.previousData = previousResult.data;
6158
- }
6159
- setResult(ref.current.result = result);
6160
- if (!result.loading) {
6161
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
6162
- }
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
+ };
6163
6351
  }
6164
- function onError(error) {
6165
- var _a, _b;
6166
- var last = obsQuery["last"];
6167
- subscription.unsubscribe();
6168
- try {
6169
- obsQuery.resetLastResults();
6170
- subscription = obsQuery.subscribe(onNext, onError);
6171
- }
6172
- finally {
6173
- obsQuery["last"] = last;
6174
- }
6175
- if (!error.hasOwnProperty('graphQLErrors')) {
6176
- throw error;
6177
- }
6178
- var previousResult = ref.current.result;
6179
- if ((previousResult && previousResult.loading) ||
6180
- !equality.equal(error, previousResult.error)) {
6181
- setResult(ref.current.result = {
6182
- data: previousResult.data,
6183
- error: error,
6184
- loading: false,
6185
- networkStatus: exports.NetworkStatus.error,
6186
- });
6187
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
6188
- }
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 });
6189
6362
  }
6190
- return function () { return subscription.unsubscribe(); };
6191
- }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
6192
- var partial;
6193
- (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
6194
- {
6195
- if (partial &&
6196
- (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
6363
+ return queryResult;
6364
+ };
6365
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
6366
+ if (result.partial &&
6367
+ this.queryHookOptions.partialRefetch &&
6197
6368
  !result.loading &&
6198
6369
  (!result.data || Object.keys(result.data).length === 0) &&
6199
- obsQuery.options.fetchPolicy !== 'cache-only') {
6200
- result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
6201
- obsQuery.refetch();
6202
- }
6203
- if (context.renderPromises &&
6204
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6205
- !(options === null || options === void 0 ? void 0 : options.skip) &&
6206
- result.loading) {
6207
- obsQuery.setOptions(createWatchQueryOptions(query, options)).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();
6208
6376
  }
6209
- }
6210
- if ((context.renderPromises || client.disableNetworkFetches) &&
6211
- (options === null || options === void 0 ? void 0 : options.ssr) === false) {
6212
- result = ref.current.result = {
6213
- loading: true,
6214
- data: void 0,
6215
- error: void 0,
6216
- networkStatus: exports.NetworkStatus.loading,
6217
- };
6218
- }
6219
- else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6220
- result = {
6221
- loading: false,
6222
- data: void 0,
6223
- error: void 0,
6224
- networkStatus: exports.NetworkStatus.ready,
6225
- };
6226
- }
6227
- if (result.errors && result.errors.length) {
6228
- result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6229
- }
6230
- var obsQueryFields = React.useMemo(function () { return ({
6231
- refetch: obsQuery.refetch.bind(obsQuery),
6232
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
6233
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
6234
- startPolling: obsQuery.startPolling.bind(obsQuery),
6235
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
6236
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6237
- }); }, [obsQuery]);
6238
- return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: obsQuery.variables, client: client, called: true, previousData: ref.current.previousData }), result);
6239
- }
6240
- function createWatchQueryOptions(query, options) {
6241
- var _a;
6242
- if (options === void 0) { options = {}; }
6243
- var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var watchQueryOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6244
- if (skip) {
6245
- watchQueryOptions.fetchPolicy = 'standby';
6246
- }
6247
- else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
6248
- (watchQueryOptions.fetchPolicy === 'network-only' ||
6249
- watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6250
- watchQueryOptions.fetchPolicy = 'cache-first';
6251
- }
6252
- else if (!watchQueryOptions.fetchPolicy) {
6253
- watchQueryOptions.fetchPolicy = 'cache-first';
6254
- }
6255
- return tslib.__assign({ query: query }, watchQueryOptions);
6256
- }
6377
+ };
6378
+ return InternalState;
6379
+ }());
6257
6380
 
6258
6381
  var EAGER_METHODS = [
6259
6382
  'refetch',
6383
+ 'reobserve',
6260
6384
  'fetchMore',
6261
6385
  'updateQuery',
6262
6386
  'startPolling',
6263
6387
  'subscribeToMore',
6264
6388
  ];
6265
6389
  function useLazyQuery(query, options) {
6266
- var _a = React.useState({
6267
- called: false,
6268
- resolves: [],
6269
- }), execution = _a[0], setExecution = _a[1];
6270
- var execute = React.useCallback(function (executeOptions) {
6271
- var resolve;
6272
- var promise = new Promise(function (resolve1) { return (resolve = resolve1); });
6273
- setExecution(function (execution) {
6274
- if (execution.called) {
6275
- result && result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables);
6276
- }
6277
- return {
6278
- called: true,
6279
- resolves: tslib.__spreadArray(tslib.__spreadArray([], execution.resolves, true), [resolve], false),
6280
- options: executeOptions,
6281
- };
6282
- });
6283
- return promise;
6284
- }, []);
6285
- 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 }));
6286
- React.useEffect(function () {
6287
- var resolves = execution.resolves;
6288
- if (!result.loading && resolves.length) {
6289
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { resolves: [] })); });
6290
- resolves.forEach(function (resolve) { return resolve(result); });
6291
- }
6292
- }, [result, execution]);
6293
- if (!execution.called) {
6294
- 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 = {};
6295
6403
  var _loop_1 = function (key) {
6296
6404
  var method = result[key];
6297
- result[key] = function () {
6298
- var args = [];
6299
- for (var _i = 0; _i < arguments.length; _i++) {
6300
- args[_i] = arguments[_i];
6405
+ eagerMethods[key] = function () {
6406
+ if (!execOptionsRef.current) {
6407
+ execOptionsRef.current = Object.create(null);
6408
+ internalState.forceUpdate();
6301
6409
  }
6302
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { called: true })); });
6303
- return method.apply(void 0, args);
6410
+ return method.apply(this, arguments);
6304
6411
  };
6305
6412
  };
6306
6413
  for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
6307
6414
  var key = EAGER_METHODS_1[_i];
6308
6415
  _loop_1(key);
6309
6416
  }
6310
- }
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
+ }, []);
6311
6440
  return [execute, result];
6312
6441
  }
6313
6442
 
@@ -6323,79 +6452,73 @@ function useMutation(mutation, options) {
6323
6452
  result: result,
6324
6453
  mutationId: 0,
6325
6454
  isMounted: true,
6326
- execute: null,
6327
6455
  client: client,
6328
6456
  mutation: mutation,
6329
6457
  options: options,
6330
6458
  });
6331
- var execute = React.useMemo(function () {
6332
- if (ref.current.execute != null &&
6333
- ref.current.client === client &&
6334
- equality.equal(options, ref.current.options) &&
6335
- equality.equal(mutation, ref.current.mutation)) {
6336
- return ref.current.execute;
6337
- }
6338
- ref.current.client = client;
6339
- ref.current.options = options;
6340
- ref.current.mutation = mutation;
6341
- ref.current.execute = function (executeOptions) {
6342
- if (executeOptions === void 0) { executeOptions = {}; }
6343
- var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6344
- if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6345
- setResult(ref.current.result = {
6346
- loading: true,
6347
- error: void 0,
6348
- 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 = {
6349
6486
  called: true,
6487
+ loading: false,
6488
+ data: data,
6489
+ error: error,
6350
6490
  client: client,
6351
- });
6352
- }
6353
- var mutationId = ++ref.current.mutationId;
6354
- var clientOptions = mergeOptions(baseOptions, executeOptions);
6355
- return client.mutate(clientOptions).then(function (response) {
6356
- var _a;
6357
- var data = response.data, errors = response.errors;
6358
- var error = errors && errors.length > 0
6359
- ? new ApolloError({ graphQLErrors: errors })
6360
- : void 0;
6361
- if (mutationId === ref.current.mutationId &&
6362
- !baseOptions.ignoreResults) {
6363
- var result_1 = {
6364
- called: true,
6365
- loading: false,
6366
- data: data,
6367
- error: error,
6368
- client: client,
6369
- };
6370
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6371
- setResult(ref.current.result = result_1);
6372
- }
6373
- }
6374
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6375
- return response;
6376
- }).catch(function (error) {
6377
- if (mutationId === ref.current.mutationId &&
6378
- ref.current.isMounted) {
6379
- var result_2 = {
6380
- loading: false,
6381
- error: error,
6382
- data: void 0,
6383
- called: true,
6384
- client: client,
6385
- };
6386
- if (!equality.equal(ref.current.result, result_2)) {
6387
- setResult(ref.current.result = result_2);
6388
- }
6491
+ };
6492
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6493
+ setResult(ref.current.result = result_1);
6389
6494
  }
6390
- if (baseOptions.onError) {
6391
- baseOptions.onError(error);
6392
- 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);
6393
6512
  }
6394
- throw error;
6395
- });
6396
- };
6397
- return ref.current.execute;
6398
- }, [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
+ }, []);
6399
6522
  var reset = React.useCallback(function () {
6400
6523
  setResult({ called: false, loading: false, client: client });
6401
6524
  }, []);
@@ -6432,14 +6555,16 @@ function useSubscription(subscription, options) {
6432
6555
  if (typeof shouldResubscribe === 'function') {
6433
6556
  shouldResubscribe = !!shouldResubscribe(options);
6434
6557
  }
6435
- 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)) {
6436
- setResult({
6437
- loading: false,
6438
- data: void 0,
6439
- error: void 0,
6440
- variables: options === null || options === void 0 ? void 0 : options.variables,
6441
- });
6442
- 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
+ }
6443
6568
  }
6444
6569
  else if (shouldResubscribe !== false && (client !== ref.current.client ||
6445
6570
  subscription !== ref.current.subscription ||
@@ -6532,7 +6657,6 @@ exports.HttpLink = HttpLink;
6532
6657
  exports.InMemoryCache = InMemoryCache;
6533
6658
  exports.MissingFieldError = MissingFieldError;
6534
6659
  exports.ObservableQuery = ObservableQuery;
6535
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
6536
6660
  exports.checkFetcher = checkFetcher;
6537
6661
  exports.concat = concat;
6538
6662
  exports.createHttpLink = createHttpLink;
@@ -6557,6 +6681,7 @@ exports.parser = parser;
6557
6681
  exports.resetApolloContext = getApolloContext;
6558
6682
  exports.rewriteURIForGET = rewriteURIForGET;
6559
6683
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
6684
+ exports.selectHttpOptionsAndBodyInternal = selectHttpOptionsAndBodyInternal;
6560
6685
  exports.selectURI = selectURI;
6561
6686
  exports.serializeFetchParameter = serializeFetchParameter;
6562
6687
  exports.split = split;