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

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 (142) hide show
  1. package/apollo-client.cjs +305 -254
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +15 -15
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/inmemory/helpers.js +1 -1
  7. package/cache/inmemory/helpers.js.map +1 -1
  8. package/cache/inmemory/key-extractor.js +2 -2
  9. package/cache/inmemory/key-extractor.js.map +1 -1
  10. package/cache/inmemory/policies.js +3 -3
  11. package/cache/inmemory/policies.js.map +1 -1
  12. package/cache/inmemory/readFromStore.js +3 -3
  13. package/cache/inmemory/readFromStore.js.map +1 -1
  14. package/cache/inmemory/writeToStore.js +6 -6
  15. package/cache/inmemory/writeToStore.js.map +1 -1
  16. package/core/ApolloClient.js +1 -1
  17. package/core/ApolloClient.js.map +1 -1
  18. package/core/LocalState.js +1 -1
  19. package/core/LocalState.js.map +1 -1
  20. package/core/ObservableQuery.d.ts.map +1 -1
  21. package/core/ObservableQuery.js +8 -5
  22. package/core/ObservableQuery.js.map +1 -1
  23. package/core/QueryManager.js +1 -1
  24. package/core/QueryManager.js.map +1 -1
  25. package/core/core.cjs +16 -13
  26. package/core/core.cjs.map +1 -1
  27. package/errors/errors.cjs +2 -2
  28. package/errors/errors.cjs.map +1 -1
  29. package/errors/index.js +2 -2
  30. package/errors/index.js.map +1 -1
  31. package/invariantErrorCodes.js +27 -27
  32. package/link/batch/batch.cjs +48 -38
  33. package/link/batch/batch.cjs.map +1 -1
  34. package/link/batch/batching.d.ts +2 -6
  35. package/link/batch/batching.d.ts.map +1 -1
  36. package/link/batch/batching.js +48 -38
  37. package/link/batch/batching.js.map +1 -1
  38. package/link/batch-http/batch-http.cjs +1 -1
  39. package/link/batch-http/batch-http.cjs.map +1 -1
  40. package/link/batch-http/batchHttpLink.js +2 -2
  41. package/link/batch-http/batchHttpLink.js.map +1 -1
  42. package/link/http/createHttpLink.js +2 -2
  43. package/link/http/createHttpLink.js.map +1 -1
  44. package/link/http/http.cjs +24 -13
  45. package/link/http/http.cjs.map +1 -1
  46. package/link/http/index.d.ts +1 -1
  47. package/link/http/index.d.ts.map +1 -1
  48. package/link/http/index.js +1 -1
  49. package/link/http/index.js.map +1 -1
  50. package/link/http/parseAndCheckHttpResponse.js +3 -3
  51. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  52. package/link/http/rewriteURIForGET.js +1 -1
  53. package/link/http/rewriteURIForGET.js.map +1 -1
  54. package/link/http/selectHttpOptionsAndBody.d.ts +5 -1
  55. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  56. package/link/http/selectHttpOptionsAndBody.js +19 -8
  57. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  58. package/link/http/serializeFetchParameter.js +1 -1
  59. package/link/http/serializeFetchParameter.js.map +1 -1
  60. package/link/subscriptions/index.d.ts +9 -0
  61. package/link/subscriptions/index.d.ts.map +1 -0
  62. package/link/subscriptions/index.js +39 -0
  63. package/link/subscriptions/index.js.map +1 -0
  64. package/link/subscriptions/package.json +8 -0
  65. package/link/subscriptions/subscriptions.cjs +45 -0
  66. package/link/subscriptions/subscriptions.cjs.map +1 -0
  67. package/link/utils/utils.cjs +1 -1
  68. package/link/utils/utils.cjs.map +1 -1
  69. package/link/utils/validateOperation.js +1 -1
  70. package/link/utils/validateOperation.js.map +1 -1
  71. package/main.cjs +4 -4
  72. package/package.json +23 -22
  73. package/react/components/components.cjs +3 -3
  74. package/react/context/context.cjs +3 -3
  75. package/react/hoc/hoc.cjs +9 -9
  76. package/react/hoc/hoc.cjs.map +1 -1
  77. package/react/hoc/mutation-hoc.js +2 -2
  78. package/react/hoc/mutation-hoc.js.map +1 -1
  79. package/react/hoc/query-hoc.js +1 -1
  80. package/react/hoc/query-hoc.js.map +1 -1
  81. package/react/hoc/subscription-hoc.js +1 -1
  82. package/react/hoc/subscription-hoc.js.map +1 -1
  83. package/react/hoc/withApollo.js +1 -1
  84. package/react/hoc/withApollo.js.map +1 -1
  85. package/react/hooks/hooks.cjs +225 -188
  86. package/react/hooks/hooks.cjs.map +1 -1
  87. package/react/hooks/useApolloClient.js +2 -2
  88. package/react/hooks/useApolloClient.js.map +1 -1
  89. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  90. package/react/hooks/useLazyQuery.js +20 -27
  91. package/react/hooks/useLazyQuery.js.map +1 -1
  92. package/react/hooks/useMutation.d.ts.map +1 -1
  93. package/react/hooks/useMutation.js +59 -65
  94. package/react/hooks/useMutation.js.map +1 -1
  95. package/react/hooks/useQuery.d.ts.map +1 -1
  96. package/react/hooks/useQuery.js +137 -88
  97. package/react/hooks/useQuery.js.map +1 -1
  98. package/react/hooks/useSubscription.d.ts.map +1 -1
  99. package/react/hooks/useSubscription.js +10 -8
  100. package/react/hooks/useSubscription.js.map +1 -1
  101. package/react/parser/index.js +7 -7
  102. package/react/parser/index.js.map +1 -1
  103. package/react/parser/parser.cjs +7 -7
  104. package/react/parser/parser.cjs.map +1 -1
  105. package/react/react.cjs +2 -2
  106. package/react/ssr/RenderPromises.d.ts +2 -2
  107. package/react/ssr/RenderPromises.d.ts.map +1 -1
  108. package/react/ssr/RenderPromises.js +7 -5
  109. package/react/ssr/RenderPromises.js.map +1 -1
  110. package/react/ssr/ssr.cjs +10 -8
  111. package/react/ssr/ssr.cjs.map +1 -1
  112. package/react/types/types.d.ts +1 -1
  113. package/react/types/types.d.ts.map +1 -1
  114. package/react/types/types.js.map +1 -1
  115. package/testing/core/core.cjs +2 -2
  116. package/testing/core/core.cjs.map +1 -1
  117. package/testing/core/mocking/mockFetch.js +1 -1
  118. package/testing/core/mocking/mockFetch.js.map +1 -1
  119. package/testing/core/mocking/mockLink.js +2 -2
  120. package/testing/core/mocking/mockLink.js.map +1 -1
  121. package/testing/core/observableToPromise.js +1 -1
  122. package/testing/core/observableToPromise.js.map +1 -1
  123. package/testing/testing.cjs +5 -5
  124. package/utilities/common/makeUniqueId.js +1 -1
  125. package/utilities/common/makeUniqueId.js.map +1 -1
  126. package/utilities/globals/fix-graphql.js +1 -1
  127. package/utilities/globals/global.d.ts.map +1 -1
  128. package/utilities/globals/global.js +1 -1
  129. package/utilities/globals/global.js.map +1 -1
  130. package/utilities/globals/globals.cjs +1 -1
  131. package/utilities/globals/globals.cjs.map +1 -1
  132. package/utilities/graphql/directives.js +4 -4
  133. package/utilities/graphql/directives.js.map +1 -1
  134. package/utilities/graphql/fragments.js +3 -3
  135. package/utilities/graphql/fragments.js.map +1 -1
  136. package/utilities/graphql/getFromAST.js +2 -2
  137. package/utilities/graphql/getFromAST.js.map +1 -1
  138. package/utilities/graphql/storeUtils.js +5 -5
  139. package/utilities/graphql/storeUtils.js.map +1 -1
  140. package/utilities/utilities.cjs +15 -15
  141. package/utilities/utilities.cjs.map +1 -1
  142. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -13,17 +13,16 @@ var context = require('@wry/context');
13
13
  var trie = require('@wry/trie');
14
14
  var graphqlTag = require('graphql-tag');
15
15
  var React = require('react');
16
- var shim = require('use-sync-external-store/shim');
17
16
 
18
17
  function _interopNamespace(e) {
19
18
  if (e && e.__esModule) return e;
20
19
  var n = Object.create(null);
21
20
  if (e) {
22
- Object.keys(e).forEach(function (k) {
21
+ for (var k in e) {
23
22
  n[k] = e[k];
24
- });
23
+ }
25
24
  }
26
- n['default'] = e;
25
+ n["default"] = e;
27
26
  return Object.freeze(n);
28
27
  }
29
28
 
@@ -46,7 +45,7 @@ function shouldInclude(_a, variables) {
46
45
  var evaledValue = false;
47
46
  if (ifArgument.value.kind === 'Variable') {
48
47
  evaledValue = variables && variables[ifArgument.value.name.value];
49
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 37);
48
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 37);
50
49
  }
51
50
  else {
52
51
  evaledValue = ifArgument.value.value;
@@ -83,12 +82,12 @@ function getInclusionDirectives(directives) {
83
82
  return;
84
83
  var directiveArguments = directive.arguments;
85
84
  var directiveName = directive.name.value;
86
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
85
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
87
86
  var ifArgument = directiveArguments[0];
88
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
87
+ __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
89
88
  var ifValue = ifArgument.value;
90
89
  __DEV__ ? tsInvariant.invariant(ifValue &&
91
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.") : tsInvariant.invariant(ifValue &&
90
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
92
91
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
93
92
  result.push({ directive: directive, ifArgument: ifArgument });
94
93
  });
@@ -101,7 +100,7 @@ function getFragmentQueryDocument(document, fragmentName) {
101
100
  var fragments = [];
102
101
  document.definitions.forEach(function (definition) {
103
102
  if (definition.kind === 'OperationDefinition') {
104
- throw __DEV__ ? new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
103
+ throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
105
104
  'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(41);
106
105
  }
107
106
  if (definition.kind === 'FragmentDefinition') {
@@ -109,7 +108,7 @@ function getFragmentQueryDocument(document, fragmentName) {
109
108
  }
110
109
  });
111
110
  if (typeof actualFragmentName === 'undefined') {
112
- __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.") : tsInvariant.invariant(fragments.length === 1, 42);
111
+ __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : tsInvariant.invariant(fragments.length === 1, 42);
113
112
  actualFragmentName = fragments[0].name.value;
114
113
  }
115
114
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -146,7 +145,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
146
145
  return selection;
147
146
  case 'FragmentSpread': {
148
147
  var fragment = fragmentMap && fragmentMap[selection.name.value];
149
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 43);
148
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value, ".")) : tsInvariant.invariant(fragment, 43);
150
149
  return fragment;
151
150
  }
152
151
  default:
@@ -228,7 +227,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
228
227
  argObj[name.value] = null;
229
228
  }
230
229
  else {
231
- throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
230
+ throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
232
231
  'is not supported. Use variables instead of inline arguments to ' +
233
232
  'overcome this limitation.') : new tsInvariant.InvariantError(52);
234
233
  }
@@ -280,7 +279,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
280
279
  filterKeys.forEach(function (key) {
281
280
  filteredArgs_1[key] = args[key];
282
281
  });
283
- return directives['connection']['key'] + "(" + stringify(filteredArgs_1) + ")";
282
+ return "".concat(directives['connection']['key'], "(").concat(stringify(filteredArgs_1), ")");
284
283
  }
285
284
  else {
286
285
  return directives['connection']['key'];
@@ -289,17 +288,17 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
289
288
  var completeFieldName = fieldName;
290
289
  if (args) {
291
290
  var stringifiedArgs = stringify(args);
292
- completeFieldName += "(" + stringifiedArgs + ")";
291
+ completeFieldName += "(".concat(stringifiedArgs, ")");
293
292
  }
294
293
  if (directives) {
295
294
  Object.keys(directives).forEach(function (key) {
296
295
  if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
297
296
  return;
298
297
  if (directives[key] && Object.keys(directives[key]).length) {
299
- completeFieldName += "@" + key + "(" + stringify(directives[key]) + ")";
298
+ completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
300
299
  }
301
300
  else {
302
- completeFieldName += "@" + key;
301
+ completeFieldName += "@".concat(key);
303
302
  }
304
303
  });
305
304
  }
@@ -369,11 +368,11 @@ function checkDocument(doc) {
369
368
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
370
369
  .map(function (definition) {
371
370
  if (definition.kind !== 'OperationDefinition') {
372
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(45);
371
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(45);
373
372
  }
374
373
  return definition;
375
374
  });
376
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 46);
375
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 46);
377
376
  return doc;
378
377
  }
379
378
  function getOperationDefinition(doc) {
@@ -1078,7 +1077,7 @@ var prefixCounts = new Map();
1078
1077
  function makeUniqueId(prefix) {
1079
1078
  var count = prefixCounts.get(prefix) || 1;
1080
1079
  prefixCounts.set(prefix, count + 1);
1081
- return prefix + ":" + count + ":" + Math.random().toString(36).slice(2);
1080
+ return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
1082
1081
  }
1083
1082
 
1084
1083
  function stringifyForDisplay(value) {
@@ -1143,7 +1142,7 @@ function validateOperation(operation) {
1143
1142
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1144
1143
  var key = _a[_i];
1145
1144
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1146
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(24);
1145
+ throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: ".concat(key)) : new tsInvariant.InvariantError(24);
1147
1146
  }
1148
1147
  }
1149
1148
  return operation;
@@ -1292,7 +1291,7 @@ var concat = ApolloLink.concat;
1292
1291
 
1293
1292
  var execute = ApolloLink.execute;
1294
1293
 
1295
- var version = '3.6.0-beta.1';
1294
+ var version = '3.6.0-beta.5';
1296
1295
 
1297
1296
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1298
1297
  function parseAndCheckHttpResponse(operations) {
@@ -1313,14 +1312,14 @@ function parseAndCheckHttpResponse(operations) {
1313
1312
  })
1314
1313
  .then(function (result) {
1315
1314
  if (response.status >= 300) {
1316
- throwServerError(response, result, "Response not successful: Received status code " + response.status);
1315
+ throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1317
1316
  }
1318
1317
  if (!Array.isArray(result) &&
1319
1318
  !hasOwnProperty$2.call(result, 'data') &&
1320
1319
  !hasOwnProperty$2.call(result, 'errors')) {
1321
- throwServerError(response, result, "Server response was missing for query '" + (Array.isArray(operations)
1320
+ throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1322
1321
  ? operations.map(function (op) { return op.operationName; })
1323
- : operations.operationName) + "'.");
1322
+ : operations.operationName, "'."));
1324
1323
  }
1325
1324
  return result;
1326
1325
  }); };
@@ -1332,7 +1331,7 @@ var serializeFetchParameter = function (p, label) {
1332
1331
  serialized = JSON.stringify(p);
1333
1332
  }
1334
1333
  catch (e) {
1335
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(21);
1334
+ var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new tsInvariant.InvariantError(21);
1336
1335
  parseError.parseError = e;
1337
1336
  throw parseError;
1338
1337
  }
@@ -1356,17 +1355,27 @@ var fallbackHttpConfig = {
1356
1355
  options: defaultOptions,
1357
1356
  };
1358
1357
  var defaultPrinter = function (ast, printer) { return printer(ast); };
1359
- var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1358
+ function selectHttpOptionsAndBody(operation, fallbackConfig) {
1359
+ var configs = [];
1360
+ for (var _i = 2; _i < arguments.length; _i++) {
1361
+ configs[_i - 2] = arguments[_i];
1362
+ }
1363
+ configs.unshift(fallbackConfig);
1364
+ return selectHttpOptionsAndBodyInternal.apply(void 0, tslib.__spreadArray([operation,
1365
+ defaultPrinter], configs, false));
1366
+ }
1367
+ function selectHttpOptionsAndBodyInternal(operation, printer) {
1360
1368
  var configs = [];
1361
- for (var _i = 3; _i < arguments.length; _i++) {
1362
- configs[_i - 3] = arguments[_i];
1369
+ for (var _i = 2; _i < arguments.length; _i++) {
1370
+ configs[_i - 2] = arguments[_i];
1363
1371
  }
1364
- var options = tslib.__assign(tslib.__assign({}, fallbackConfig.options), { headers: fallbackConfig.headers, credentials: fallbackConfig.credentials });
1365
- var http = fallbackConfig.http || {};
1372
+ var options = {};
1373
+ var http = {};
1366
1374
  configs.forEach(function (config) {
1367
1375
  options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), headersToLowerCase(config.headers)) });
1368
- if (config.credentials)
1376
+ if (config.credentials) {
1369
1377
  options.credentials = config.credentials;
1378
+ }
1370
1379
  http = tslib.__assign(tslib.__assign({}, http), config.http);
1371
1380
  });
1372
1381
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
@@ -1379,7 +1388,7 @@ var selectHttpOptionsAndBody = function (operation, printer, fallbackConfig) {
1379
1388
  options: options,
1380
1389
  body: body,
1381
1390
  };
1382
- };
1391
+ }
1383
1392
  function headersToLowerCase(headers) {
1384
1393
  if (headers) {
1385
1394
  var normalized_1 = Object.create(null);
@@ -1422,7 +1431,7 @@ var selectURI = function (operation, fallbackURI) {
1422
1431
  function rewriteURIForGET(chosenURI, body) {
1423
1432
  var queryParams = [];
1424
1433
  var addQueryParam = function (key, value) {
1425
- queryParams.push(key + "=" + encodeURIComponent(value));
1434
+ queryParams.push("".concat(key, "=").concat(encodeURIComponent(value)));
1426
1435
  };
1427
1436
  if ('query' in body) {
1428
1437
  addQueryParam('query', body.query);
@@ -1494,7 +1503,7 @@ var createHttpLink = function (linkOptions) {
1494
1503
  credentials: context.credentials,
1495
1504
  headers: contextHeaders,
1496
1505
  };
1497
- var _b = selectHttpOptionsAndBody(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1506
+ var _b = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1498
1507
  if (body.variables && !includeUnusedVariables) {
1499
1508
  var unusedNames_1 = new Set(Object.keys(body.variables));
1500
1509
  graphql.visit(operation.query, {
@@ -1687,7 +1696,7 @@ function defaultDataIdFromObject(_a, context) {
1687
1696
  if (id === void 0)
1688
1697
  id = _id;
1689
1698
  if (id !== void 0) {
1690
- return __typename + ":" + ((typeof id === "number" ||
1699
+ return "".concat(__typename, ":").concat((typeof id === "number" ||
1691
1700
  typeof id === "string") ? id : JSON.stringify(id));
1692
1701
  }
1693
1702
  }
@@ -2423,7 +2432,7 @@ var StoreReader = (function () {
2423
2432
  !context.store.has(objectOrReference.__ref)) {
2424
2433
  return {
2425
2434
  result: this.canon.empty,
2426
- missing: "Dangling reference to missing " + objectOrReference.__ref + " object",
2435
+ missing: "Dangling reference to missing ".concat(objectOrReference.__ref, " object"),
2427
2436
  };
2428
2437
  }
2429
2438
  var variables = context.variables, policies = context.policies, store = context.store;
@@ -2458,7 +2467,7 @@ var StoreReader = (function () {
2458
2467
  if (fieldValue === void 0) {
2459
2468
  if (!addTypenameToDocument.added(selection)) {
2460
2469
  missing = context.merge(missing, (_a = {},
2461
- _a[resultName] = "Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
2470
+ _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(isReference(objectOrReference)
2462
2471
  ? objectOrReference.__ref + " object"
2463
2472
  : "object " + JSON.stringify(objectOrReference, null, 2)),
2464
2473
  _a));
@@ -2568,7 +2577,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
2568
2577
  var workSet_1 = new Set([fieldValue]);
2569
2578
  workSet_1.forEach(function (value) {
2570
2579
  if (isNonNullObject(value)) {
2571
- __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!isReference(value), 5);
2580
+ __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : tsInvariant.invariant(!isReference(value), 5);
2572
2581
  Object.values(value).forEach(workSet_1.add, workSet_1);
2573
2582
  }
2574
2583
  });
@@ -2655,10 +2664,10 @@ function keyFieldsFnFromSpecifier(specifier) {
2655
2664
  hasOwn.call(object, schemaKeyPath[0])) {
2656
2665
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
2657
2666
  }
2658
- __DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '" + schemaKeyPath.join('.') + "' while extracting keyFields from " + JSON.stringify(object)) : tsInvariant.invariant(extracted !== void 0, 2);
2667
+ __DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '".concat(schemaKeyPath.join('.'), "' while extracting keyFields from ").concat(JSON.stringify(object))) : tsInvariant.invariant(extracted !== void 0, 2);
2659
2668
  return extracted;
2660
2669
  });
2661
- return context.typename + ":" + JSON.stringify(keyObject);
2670
+ return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
2662
2671
  });
2663
2672
  }
2664
2673
  function keyArgsFnFromSpecifier(specifier) {
@@ -2884,7 +2893,7 @@ var Policies = (function () {
2884
2893
  var rootId = "ROOT_" + which.toUpperCase();
2885
2894
  var old = this.rootTypenamesById[rootId];
2886
2895
  if (typename !== old) {
2887
- __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 3);
2896
+ __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root ".concat(which, " __typename more than once")) : tsInvariant.invariant(!old || old === which, 3);
2888
2897
  if (old)
2889
2898
  delete this.rootIdsByTypename[old];
2890
2899
  this.rootIdsByTypename[typename] = rootId;
@@ -2968,7 +2977,7 @@ var Policies = (function () {
2968
2977
  if (supertypeSet.has(supertype)) {
2969
2978
  if (!typenameSupertypeSet.has(supertype)) {
2970
2979
  if (checkingFuzzySubtypes) {
2971
- __DEV__ && tsInvariant.invariant.warn("Inferring subtype " + typename + " of supertype " + supertype);
2980
+ __DEV__ && tsInvariant.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
2972
2981
  }
2973
2982
  typenameSupertypeSet.add(supertype);
2974
2983
  }
@@ -3122,7 +3131,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3122
3131
  }
3123
3132
  }
3124
3133
  if (__DEV__ && options.from === void 0) {
3125
- __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + stringifyForDisplay(Array.from(readFieldArgs)));
3134
+ __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments ".concat(stringifyForDisplay(Array.from(readFieldArgs))));
3126
3135
  }
3127
3136
  if (void 0 === options.variables) {
3128
3137
  options.variables = variables;
@@ -3162,7 +3171,7 @@ function makeMergeObjectsFunction(store) {
3162
3171
  }
3163
3172
 
3164
3173
  function getContextFlavor(context, clientOnly, deferred) {
3165
- var key = "" + clientOnly + deferred;
3174
+ var key = "".concat(clientOnly).concat(deferred);
3166
3175
  var flavored = context.flavors.get(key);
3167
3176
  if (!flavored) {
3168
3177
  context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
@@ -3204,7 +3213,7 @@ var StoreWriter = (function () {
3204
3213
  context: context,
3205
3214
  });
3206
3215
  if (!isReference(ref)) {
3207
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(6);
3216
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new tsInvariant.InvariantError(6);
3208
3217
  }
3209
3218
  context.incomingById.forEach(function (_a, dataId) {
3210
3219
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -3309,7 +3318,7 @@ var StoreWriter = (function () {
3309
3318
  !context.deferred &&
3310
3319
  !addTypenameToDocument.added(field) &&
3311
3320
  !policies.getReadFunction(typename, field.name.value)) {
3312
- __DEV__ && tsInvariant.invariant.error(("Missing field '" + resultKeyNameFromField(field) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
3321
+ __DEV__ && tsInvariant.invariant.error("Missing field '".concat(resultKeyNameFromField(field), "' while writing result ").concat(JSON.stringify(result, null, 2)).substring(0, 1000));
3313
3322
  }
3314
3323
  });
3315
3324
  try {
@@ -3531,7 +3540,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3531
3540
  var parentType = store.getFieldValue(existingRef, "__typename") ||
3532
3541
  store.getFieldValue(incomingObj, "__typename");
3533
3542
  var fieldName = fieldNameFromStoreName(storeFieldName);
3534
- var typeDotName = parentType + "." + fieldName;
3543
+ var typeDotName = "".concat(parentType, ".").concat(fieldName);
3535
3544
  if (warnings.has(typeDotName))
3536
3545
  return;
3537
3546
  warnings.add(typeDotName);
@@ -3546,10 +3555,10 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3546
3555
  }
3547
3556
  });
3548
3557
  }
3549
- __DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the " + fieldName + " field of a " + parentType + " object.\n\nTo address this problem (which is not a bug in Apollo Client), " + (childTypenames.length
3558
+ __DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the ".concat(fieldName, " field of a ").concat(parentType, " object.\n\nTo address this problem (which is not a bug in Apollo Client), ").concat(childTypenames.length
3550
3559
  ? "either ensure all objects of type " +
3551
3560
  childTypenames.join(" and ") + " have an ID or a custom merge function, or "
3552
- : "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
3561
+ : "", "define a custom merge function for the ").concat(typeDotName, " field, so InMemoryCache can safely merge these objects:\n\n existing: ").concat(JSON.stringify(existing).slice(0, 1000), "\n incoming: ").concat(JSON.stringify(incoming).slice(0, 1000), "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n"));
3553
3562
  }
3554
3563
 
3555
3564
  var InMemoryCache = (function (_super) {
@@ -3856,11 +3865,11 @@ var generateErrorMessage = function (err) {
3856
3865
  var errorMessage = error
3857
3866
  ? error.message
3858
3867
  : 'Error message not found.';
3859
- message += errorMessage + "\n";
3868
+ message += "".concat(errorMessage, "\n");
3860
3869
  });
3861
3870
  }
3862
3871
  if (err.networkError) {
3863
- message += err.networkError.message + "\n";
3872
+ message += "".concat(err.networkError.message, "\n");
3864
3873
  }
3865
3874
  message = message.replace(/\n$/, '');
3866
3875
  return message;
@@ -4042,7 +4051,7 @@ var ObservableQuery = (function (_super) {
4042
4051
  pollInterval: 0,
4043
4052
  };
4044
4053
  var fetchPolicy = this.options.fetchPolicy;
4045
- if (fetchPolicy === 'standby' || fetchPolicy === 'cache-and-network') {
4054
+ if (fetchPolicy === 'cache-and-network') {
4046
4055
  reobserveOptions.fetchPolicy = fetchPolicy;
4047
4056
  }
4048
4057
  else if (fetchPolicy === 'no-cache') {
@@ -4055,7 +4064,7 @@ var ObservableQuery = (function (_super) {
4055
4064
  var queryDef = getQueryDefinition(this.options.query);
4056
4065
  var vars = queryDef.variableDefinitions;
4057
4066
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4058
- __DEV__ && tsInvariant.invariant.warn("Called refetch(" + JSON.stringify(variables) + ") for query " + (((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef)) + ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?");
4067
+ __DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
4059
4068
  }
4060
4069
  }
4061
4070
  if (variables && !equality.equal(this.options.variables, variables)) {
@@ -4282,8 +4291,11 @@ var ObservableQuery = (function (_super) {
4282
4291
  this.reportResult(this.getCurrentResult(false), this.variables);
4283
4292
  };
4284
4293
  ObservableQuery.prototype.reportResult = function (result, variables) {
4285
- if (this.getLastError() || this.isDifferentFromLastResult(result)) {
4286
- this.updateLastResult(result, variables);
4294
+ var lastError = this.getLastError();
4295
+ if (lastError || this.isDifferentFromLastResult(result)) {
4296
+ if (lastError || !result.partial || this.options.returnPartialData) {
4297
+ this.updateLastResult(result, variables);
4298
+ }
4287
4299
  iterateObserversSafely(this.observers, 'next', result);
4288
4300
  }
4289
4301
  };
@@ -4318,7 +4330,7 @@ function defaultSubscriptionObserverErrorCallback(error) {
4318
4330
  }
4319
4331
  function logMissingFieldErrors(missing) {
4320
4332
  if (__DEV__ && missing) {
4321
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + JSON.stringify(missing), missing);
4333
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4322
4334
  }
4323
4335
  }
4324
4336
  function applyNextFetchPolicy(options) {
@@ -4499,7 +4511,7 @@ var LocalState = (function () {
4499
4511
  }
4500
4512
  else {
4501
4513
  fragment = fragmentMap[selection.name.value];
4502
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 9);
4514
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value)) : tsInvariant.invariant(fragment, 9);
4503
4515
  }
4504
4516
  if (fragment && fragment.typeCondition) {
4505
4517
  typeCondition = fragment.typeCondition.name.value;
@@ -5290,7 +5302,7 @@ var QueryManager = (function () {
5290
5302
  if (__DEV__ && queryNamesAndDocs.size) {
5291
5303
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
5292
5304
  if (!included) {
5293
- __DEV__ && tsInvariant.invariant.warn("Unknown query " + (typeof nameOrDoc === "string" ? "named " : "") + JSON.stringify(nameOrDoc, null, 2) + " requested in refetchQueries options.include array");
5305
+ __DEV__ && tsInvariant.invariant.warn("Unknown query ".concat(typeof nameOrDoc === "string" ? "named " : "").concat(JSON.stringify(nameOrDoc, null, 2), " requested in refetchQueries options.include array"));
5294
5306
  }
5295
5307
  });
5296
5308
  }
@@ -5881,7 +5893,7 @@ var ApolloClient = (function () {
5881
5893
  result.queries = queries;
5882
5894
  result.results = results;
5883
5895
  result.catch(function (error) {
5884
- __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
5896
+ __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error ".concat(error));
5885
5897
  });
5886
5898
  return result;
5887
5899
  };
@@ -5957,8 +5969,8 @@ function useApolloClient(override) {
5957
5969
  var context = React.useContext(getApolloContext());
5958
5970
  var client = override || context.client;
5959
5971
  __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5960
- 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient' +
5961
- 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 29);
5972
+ 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
5973
+ 'instance in via options.') : tsInvariant.invariant(!!client, 29);
5962
5974
  return client;
5963
5975
  }
5964
5976
 
@@ -5989,7 +6001,7 @@ function parser(document) {
5989
6001
  if (cached)
5990
6002
  return cached;
5991
6003
  var variables, type, name;
5992
- __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
6004
+ __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
5993
6005
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
5994
6006
  "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
5995
6007
  var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
@@ -6007,8 +6019,8 @@ function parser(document) {
6007
6019
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6008
6020
  (queries.length || mutations.length || subscriptions.length), 31);
6009
6021
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6010
- (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
6011
- ("subscriptions and " + mutations.length + " mutations. ") +
6022
+ "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6023
+ "subscriptions and ".concat(mutations.length, " mutations. ") +
6012
6024
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
6013
6025
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6014
6026
  if (!queries.length && !mutations.length)
@@ -6018,8 +6030,8 @@ function parser(document) {
6018
6030
  : mutations.length
6019
6031
  ? mutations
6020
6032
  : subscriptions;
6021
- __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
6022
- (definitions.length + " definitions. ") +
6033
+ __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6034
+ "".concat(definitions.length, " definitions. ") +
6023
6035
  "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 33);
6024
6036
  var definition = definitions[0];
6025
6037
  variables = definition.variableDefinitions || [];
@@ -6037,23 +6049,18 @@ function verifyDocumentType(document, type) {
6037
6049
  var operation = parser(document);
6038
6050
  var requiredOperationName = operationName(type);
6039
6051
  var usedOperationName = operationName(operation.type);
6040
- __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
6041
- (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6052
+ __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6053
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6042
6054
  }
6043
6055
 
6044
6056
  function useQuery(query, options) {
6045
6057
  var _a;
6046
6058
  var context = React.useContext(getApolloContext());
6047
6059
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6060
+ var defaultWatchQueryOptions = client.defaultOptions.watchQuery;
6048
6061
  verifyDocumentType(query, exports.DocumentType.Query);
6049
- var ref = React.useRef({
6050
- client: client,
6051
- query: query,
6052
- options: options,
6053
- watchQueryOptions: createWatchQueryOptions(query, options),
6054
- });
6055
6062
  var _b = React.useState(function () {
6056
- var watchQueryOptions = createWatchQueryOptions(query, options);
6063
+ var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6057
6064
  var obsQuery = null;
6058
6065
  if (context.renderPromises) {
6059
6066
  obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
@@ -6069,7 +6076,7 @@ function useQuery(query, options) {
6069
6076
  !(options === null || options === void 0 ? void 0 : options.skip) &&
6070
6077
  obsQuery.getCurrentResult().loading) {
6071
6078
  context.renderPromises.addQueryPromise({
6072
- getOptions: function () { return createWatchQueryOptions(query, options); },
6079
+ getOptions: function () { return createWatchQueryOptions(query, options, defaultWatchQueryOptions); },
6073
6080
  fetchData: function () { return new Promise(function (resolve) {
6074
6081
  var sub = obsQuery.subscribe({
6075
6082
  next: function (result) {
@@ -6091,96 +6098,112 @@ function useQuery(query, options) {
6091
6098
  }
6092
6099
  return obsQuery;
6093
6100
  }), obsQuery = _b[0], setObsQuery = _b[1];
6101
+ var _c = React.useState(function () {
6102
+ var _a, _b;
6103
+ var result = obsQuery.getCurrentResult();
6104
+ if (!result.loading && options) {
6105
+ if (result.error) {
6106
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6107
+ }
6108
+ else if (result.data) {
6109
+ (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6110
+ }
6111
+ }
6112
+ return result;
6113
+ }), result = _c[0], setResult = _c[1];
6114
+ var ref = React.useRef({
6115
+ client: client,
6116
+ query: query,
6117
+ options: options,
6118
+ result: result,
6119
+ previousData: void 0,
6120
+ watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),
6121
+ });
6094
6122
  React.useEffect(function () {
6095
- var watchQueryOptions = createWatchQueryOptions(query, options);
6123
+ var _a, _b;
6124
+ var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
6125
+ var nextResult;
6096
6126
  if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
6097
6127
  var obsQuery_1 = client.watchQuery(watchQueryOptions);
6098
6128
  setObsQuery(obsQuery_1);
6129
+ nextResult = obsQuery_1.getCurrentResult();
6099
6130
  }
6100
6131
  else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6101
- obsQuery.setOptions(watchQueryOptions);
6102
- setObsQuery(obsQuery);
6103
- }
6104
- Object.assign(ref.current, {
6105
- client: client,
6106
- query: query,
6107
- options: options,
6108
- watchQueryOptions: watchQueryOptions,
6109
- });
6110
- }, [obsQuery, client, query, options]);
6111
- var _c = React.useMemo(function () {
6112
- var previousResult;
6113
- var subscribe = function (forceUpdate) {
6114
- var subscription = obsQuery.subscribe(forceUpdate, onError);
6115
- function onError(error) {
6116
- forceUpdate();
6117
- subscription.unsubscribe();
6118
- var last = obsQuery["last"];
6119
- obsQuery.resetLastResults();
6120
- obsQuery.subscribe(forceUpdate, onError);
6121
- obsQuery["last"] = last;
6122
- if (!error.hasOwnProperty('graphQLErrors')) {
6123
- throw error;
6132
+ obsQuery.setOptions(watchQueryOptions).catch(function () { });
6133
+ nextResult = obsQuery.getCurrentResult();
6134
+ ref.current.watchQueryOptions = watchQueryOptions;
6135
+ }
6136
+ if (nextResult) {
6137
+ var previousResult = ref.current.result;
6138
+ if (previousResult.data) {
6139
+ ref.current.previousData = previousResult.data;
6140
+ }
6141
+ setResult(ref.current.result = nextResult);
6142
+ if (!nextResult.loading && options) {
6143
+ if (nextResult.error) {
6144
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, nextResult.error);
6124
6145
  }
6125
- }
6126
- return function () {
6127
- subscription.unsubscribe();
6128
- };
6129
- };
6130
- var getSnapshot = function () {
6131
- var result = obsQuery.getCurrentResult();
6132
- if (result.errors && result.errors.length) {
6133
- result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6134
- }
6135
- if (!previousResult ||
6136
- previousResult.loading !== result.loading ||
6137
- previousResult.networkStatus !== result.networkStatus ||
6138
- !equality.equal(previousResult.data, result.data) ||
6139
- !equality.equal(previousResult.error, result.error)) {
6140
- if (previousResult) {
6141
- result = tslib.__assign(tslib.__assign({}, result), { previousData: previousResult.data || previousResult.previousData });
6146
+ else if (nextResult.data) {
6147
+ (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, nextResult.data);
6142
6148
  }
6143
- previousResult = result;
6144
6149
  }
6145
- return previousResult;
6146
- };
6147
- return [subscribe, getSnapshot];
6148
- }, [obsQuery]), subscribe = _c[0], getSnapshot = _c[1];
6149
- var obsQueryMethods = React.useMemo(function () { return ({
6150
- refetch: obsQuery.refetch.bind(obsQuery),
6151
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
6152
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
6153
- startPolling: obsQuery.startPolling.bind(obsQuery),
6154
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
6155
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6156
- }); }, [obsQuery]);
6157
- var result = shim.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
6150
+ }
6151
+ Object.assign(ref.current, { client: client, query: query });
6152
+ }, [obsQuery, client, query, options]);
6158
6153
  React.useEffect(function () {
6159
- var _a, _b, _c, _d, _e, _f;
6160
- if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) ||
6161
- ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) === 'standby') {
6154
+ if (context.renderPromises) {
6162
6155
  return;
6163
6156
  }
6164
- if (!result.loading) {
6165
- if (result.error) {
6166
- (_d = (_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.onError) === null || _d === void 0 ? void 0 : _d.call(_c, result.error);
6157
+ var subscription = obsQuery.subscribe(onNext, onError);
6158
+ function onNext() {
6159
+ var _a, _b;
6160
+ var previousResult = ref.current.result;
6161
+ var result = obsQuery.getCurrentResult();
6162
+ if (previousResult &&
6163
+ previousResult.loading === result.loading &&
6164
+ previousResult.networkStatus === result.networkStatus &&
6165
+ equality.equal(previousResult.data, result.data)) {
6166
+ return;
6167
6167
  }
6168
- else if (result.data) {
6169
- (_f = (_e = ref.current.options) === null || _e === void 0 ? void 0 : _e.onCompleted) === null || _f === void 0 ? void 0 : _f.call(_e, result.data);
6168
+ if (previousResult.data) {
6169
+ ref.current.previousData = previousResult.data;
6170
+ }
6171
+ setResult(ref.current.result = result);
6172
+ if (!result.loading) {
6173
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
6174
+ }
6175
+ }
6176
+ function onError(error) {
6177
+ var _a, _b;
6178
+ var last = obsQuery["last"];
6179
+ subscription.unsubscribe();
6180
+ try {
6181
+ obsQuery.resetLastResults();
6182
+ subscription = obsQuery.subscribe(onNext, onError);
6183
+ }
6184
+ finally {
6185
+ obsQuery["last"] = last;
6186
+ }
6187
+ if (!error.hasOwnProperty('graphQLErrors')) {
6188
+ throw error;
6189
+ }
6190
+ var previousResult = ref.current.result;
6191
+ if ((previousResult && previousResult.loading) ||
6192
+ !equality.equal(error, previousResult.error)) {
6193
+ setResult(ref.current.result = {
6194
+ data: previousResult.data,
6195
+ error: error,
6196
+ loading: false,
6197
+ networkStatus: exports.NetworkStatus.error,
6198
+ });
6199
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
6170
6200
  }
6171
6201
  }
6172
- }, [result]);
6202
+ return function () { return subscription.unsubscribe(); };
6203
+ }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
6173
6204
  var partial;
6174
6205
  (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
6175
- if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6176
- result = {
6177
- loading: false,
6178
- data: void 0,
6179
- error: void 0,
6180
- networkStatus: exports.NetworkStatus.ready,
6181
- };
6182
- }
6183
- else {
6206
+ {
6184
6207
  if (partial &&
6185
6208
  (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
6186
6209
  !result.loading &&
@@ -6189,17 +6212,52 @@ function useQuery(query, options) {
6189
6212
  result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
6190
6213
  obsQuery.refetch();
6191
6214
  }
6192
- if (context.renderPromises && (options === null || options === void 0 ? void 0 : options.ssr) !== false && result.loading) {
6193
- obsQuery.setOptions(createWatchQueryOptions(query, options))
6194
- .catch(function () { });
6215
+ if (context.renderPromises &&
6216
+ (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6217
+ !(options === null || options === void 0 ? void 0 : options.skip) &&
6218
+ result.loading) {
6219
+ obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(function () { });
6195
6220
  }
6221
+ Object.assign(ref.current, { options: options });
6222
+ }
6223
+ if ((context.renderPromises || client.disableNetworkFetches) &&
6224
+ (options === null || options === void 0 ? void 0 : options.ssr) === false) {
6225
+ result = ref.current.result = {
6226
+ loading: true,
6227
+ data: void 0,
6228
+ error: void 0,
6229
+ networkStatus: exports.NetworkStatus.loading,
6230
+ };
6196
6231
  }
6197
- return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryMethods), { variables: obsQuery.variables, client: client, called: true }), result);
6232
+ else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6233
+ result = {
6234
+ loading: false,
6235
+ data: void 0,
6236
+ error: void 0,
6237
+ networkStatus: exports.NetworkStatus.ready,
6238
+ };
6239
+ }
6240
+ if (result.errors && result.errors.length) {
6241
+ result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6242
+ }
6243
+ var obsQueryFields = React.useMemo(function () { return ({
6244
+ refetch: obsQuery.refetch.bind(obsQuery),
6245
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6246
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6247
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6248
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6249
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6250
+ }); }, [obsQuery]);
6251
+ return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables, client: client, called: true, previousData: ref.current.previousData }), result);
6198
6252
  }
6199
- function createWatchQueryOptions(query, options) {
6253
+ function createWatchQueryOptions(query, options, defaultOptions) {
6200
6254
  var _a;
6201
6255
  if (options === void 0) { options = {}; }
6202
- var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var watchQueryOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6256
+ var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var otherOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6257
+ var watchQueryOptions = tslib.__assign({ query: query }, otherOptions);
6258
+ if (defaultOptions) {
6259
+ watchQueryOptions = mergeOptions(defaultOptions, watchQueryOptions);
6260
+ }
6203
6261
  if (skip) {
6204
6262
  watchQueryOptions.fetchPolicy = 'standby';
6205
6263
  }
@@ -6211,7 +6269,10 @@ function createWatchQueryOptions(query, options) {
6211
6269
  else if (!watchQueryOptions.fetchPolicy) {
6212
6270
  watchQueryOptions.fetchPolicy = 'cache-first';
6213
6271
  }
6214
- return tslib.__assign({ query: query }, watchQueryOptions);
6272
+ if (!watchQueryOptions.variables) {
6273
+ watchQueryOptions.variables = {};
6274
+ }
6275
+ return watchQueryOptions;
6215
6276
  }
6216
6277
 
6217
6278
  var EAGER_METHODS = [
@@ -6224,36 +6285,16 @@ var EAGER_METHODS = [
6224
6285
  function useLazyQuery(query, options) {
6225
6286
  var _a = React.useState({
6226
6287
  called: false,
6227
- resolves: [],
6228
6288
  }), execution = _a[0], setExecution = _a[1];
6229
- var execute = React.useCallback(function (executeOptions) {
6230
- var resolve;
6231
- var promise = new Promise(function (resolve1) { return (resolve = resolve1); });
6232
- setExecution(function (execution) {
6233
- if (execution.called) {
6234
- result && result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables);
6235
- }
6236
- return {
6237
- called: true,
6238
- resolves: tslib.__spreadArray(tslib.__spreadArray([], execution.resolves, true), [resolve], false),
6239
- options: executeOptions,
6240
- };
6241
- });
6242
- return promise;
6243
- }, []);
6244
6289
  var result = useQuery(query, tslib.__assign(tslib.__assign(tslib.__assign({}, options), execution.options), { fetchPolicy: execution.called ? options === null || options === void 0 ? void 0 : options.fetchPolicy : 'standby', skip: undefined }));
6245
- React.useEffect(function () {
6246
- var resolves = execution.resolves;
6247
- if (!result.loading && resolves.length) {
6248
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { resolves: [] })); });
6249
- resolves.forEach(function (resolve) { return resolve(result); });
6250
- }
6251
- }, [result, execution]);
6252
6290
  if (!execution.called) {
6253
6291
  result = tslib.__assign(tslib.__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
6292
+ }
6293
+ var eagerMethods = React.useMemo(function () {
6294
+ var eagerMethods = {};
6254
6295
  var _loop_1 = function (key) {
6255
6296
  var method = result[key];
6256
- result[key] = function () {
6297
+ eagerMethods[key] = function () {
6257
6298
  var args = [];
6258
6299
  for (var _i = 0; _i < arguments.length; _i++) {
6259
6300
  args[_i] = arguments[_i];
@@ -6266,7 +6307,20 @@ function useLazyQuery(query, options) {
6266
6307
  var key = EAGER_METHODS_1[_i];
6267
6308
  _loop_1(key);
6268
6309
  }
6269
- }
6310
+ return eagerMethods;
6311
+ }, []);
6312
+ result.error = result.error || void 0;
6313
+ Object.assign(result, eagerMethods);
6314
+ var execute = React.useCallback(function (executeOptions) {
6315
+ setExecution({ called: true, options: executeOptions });
6316
+ var promise = result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables).then(function (result1) {
6317
+ var result2 = tslib.__assign(tslib.__assign({}, result), { data: result1.data, error: result1.error, called: true, loading: false });
6318
+ Object.assign(result2, eagerMethods);
6319
+ return result2;
6320
+ });
6321
+ promise.catch(function () { });
6322
+ return promise;
6323
+ }, []);
6270
6324
  return [execute, result];
6271
6325
  }
6272
6326
 
@@ -6282,79 +6336,73 @@ function useMutation(mutation, options) {
6282
6336
  result: result,
6283
6337
  mutationId: 0,
6284
6338
  isMounted: true,
6285
- execute: null,
6286
6339
  client: client,
6287
6340
  mutation: mutation,
6288
6341
  options: options,
6289
6342
  });
6290
- var execute = React.useMemo(function () {
6291
- if (ref.current.execute != null &&
6292
- ref.current.client === client &&
6293
- equality.equal(options, ref.current.options) &&
6294
- equality.equal(mutation, ref.current.mutation)) {
6295
- return ref.current.execute;
6296
- }
6297
- ref.current.client = client;
6298
- ref.current.options = options;
6299
- ref.current.mutation = mutation;
6300
- ref.current.execute = function (executeOptions) {
6301
- if (executeOptions === void 0) { executeOptions = {}; }
6302
- var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6303
- if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6304
- setResult(ref.current.result = {
6305
- loading: true,
6306
- error: void 0,
6307
- data: void 0,
6343
+ {
6344
+ Object.assign(ref.current, { client: client, options: options, mutation: mutation });
6345
+ }
6346
+ var execute = React.useCallback(function (executeOptions) {
6347
+ if (executeOptions === void 0) { executeOptions = {}; }
6348
+ var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
6349
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6350
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6351
+ setResult(ref.current.result = {
6352
+ loading: true,
6353
+ error: void 0,
6354
+ data: void 0,
6355
+ called: true,
6356
+ client: client,
6357
+ });
6358
+ }
6359
+ var mutationId = ++ref.current.mutationId;
6360
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
6361
+ return client.mutate(clientOptions).then(function (response) {
6362
+ var _a, _b;
6363
+ var data = response.data, errors = response.errors;
6364
+ var error = errors && errors.length > 0
6365
+ ? new ApolloError({ graphQLErrors: errors })
6366
+ : void 0;
6367
+ if (mutationId === ref.current.mutationId &&
6368
+ !clientOptions.ignoreResults) {
6369
+ var result_1 = {
6308
6370
  called: true,
6371
+ loading: false,
6372
+ data: data,
6373
+ error: error,
6309
6374
  client: client,
6310
- });
6311
- }
6312
- var mutationId = ++ref.current.mutationId;
6313
- var clientOptions = mergeOptions(baseOptions, executeOptions);
6314
- return client.mutate(clientOptions).then(function (response) {
6315
- var _a;
6316
- var data = response.data, errors = response.errors;
6317
- var error = errors && errors.length > 0
6318
- ? new ApolloError({ graphQLErrors: errors })
6319
- : void 0;
6320
- if (mutationId === ref.current.mutationId &&
6321
- !baseOptions.ignoreResults) {
6322
- var result_1 = {
6323
- called: true,
6324
- loading: false,
6325
- data: data,
6326
- error: error,
6327
- client: client,
6328
- };
6329
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6330
- setResult(ref.current.result = result_1);
6331
- }
6332
- }
6333
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6334
- return response;
6335
- }).catch(function (error) {
6336
- if (mutationId === ref.current.mutationId &&
6337
- ref.current.isMounted) {
6338
- var result_2 = {
6339
- loading: false,
6340
- error: error,
6341
- data: void 0,
6342
- called: true,
6343
- client: client,
6344
- };
6345
- if (!equality.equal(ref.current.result, result_2)) {
6346
- setResult(ref.current.result = result_2);
6347
- }
6375
+ };
6376
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6377
+ setResult(ref.current.result = result_1);
6348
6378
  }
6349
- if (baseOptions.onError) {
6350
- baseOptions.onError(error);
6351
- return { data: void 0, errors: error };
6379
+ }
6380
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6381
+ (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
6382
+ return response;
6383
+ }).catch(function (error) {
6384
+ var _a, _b;
6385
+ if (mutationId === ref.current.mutationId &&
6386
+ ref.current.isMounted) {
6387
+ var result_2 = {
6388
+ loading: false,
6389
+ error: error,
6390
+ data: void 0,
6391
+ called: true,
6392
+ client: client,
6393
+ };
6394
+ if (!equality.equal(ref.current.result, result_2)) {
6395
+ setResult(ref.current.result = result_2);
6352
6396
  }
6353
- throw error;
6354
- });
6355
- };
6356
- return ref.current.execute;
6357
- }, [client, mutation, options]);
6397
+ }
6398
+ if (baseOptions.onError || clientOptions.onError) {
6399
+ (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
6400
+ (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
6401
+ return { data: void 0, errors: error };
6402
+ }
6403
+ throw error;
6404
+ });
6405
+ }, []);
6358
6406
  var reset = React.useCallback(function () {
6359
6407
  setResult({ called: false, loading: false, client: client });
6360
6408
  }, []);
@@ -6391,14 +6439,16 @@ function useSubscription(subscription, options) {
6391
6439
  if (typeof shouldResubscribe === 'function') {
6392
6440
  shouldResubscribe = !!shouldResubscribe(options);
6393
6441
  }
6394
- if ((options === null || options === void 0 ? void 0 : options.skip) && !(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6395
- setResult({
6396
- loading: false,
6397
- data: void 0,
6398
- error: void 0,
6399
- variables: options === null || options === void 0 ? void 0 : options.variables,
6400
- });
6401
- setObservable(null);
6442
+ if (options === null || options === void 0 ? void 0 : options.skip) {
6443
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6444
+ setResult({
6445
+ loading: false,
6446
+ data: void 0,
6447
+ error: void 0,
6448
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6449
+ });
6450
+ setObservable(null);
6451
+ }
6402
6452
  }
6403
6453
  else if (shouldResubscribe !== false && (client !== ref.current.client ||
6404
6454
  subscription !== ref.current.subscription ||
@@ -6516,6 +6566,7 @@ exports.parser = parser;
6516
6566
  exports.resetApolloContext = getApolloContext;
6517
6567
  exports.rewriteURIForGET = rewriteURIForGET;
6518
6568
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
6569
+ exports.selectHttpOptionsAndBodyInternal = selectHttpOptionsAndBodyInternal;
6519
6570
  exports.selectURI = selectURI;
6520
6571
  exports.serializeFetchParameter = serializeFetchParameter;
6521
6572
  exports.split = split;