@apollo/client 3.7.3 → 3.8.0-alpha.1

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 (105) hide show
  1. package/README.md +7 -7
  2. package/apollo-client.cjs +271 -30
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/config/jest/setup.d.ts +1 -1
  6. package/config/jest/setup.d.ts.map +1 -1
  7. package/config/jest/setup.js +1 -0
  8. package/config/jest/setup.js.map +1 -1
  9. package/core/ObservableQuery.d.ts +2 -1
  10. package/core/ObservableQuery.d.ts.map +1 -1
  11. package/core/ObservableQuery.js +8 -4
  12. package/core/ObservableQuery.js.map +1 -1
  13. package/core/core.cjs +9 -5
  14. package/core/core.cjs.map +1 -1
  15. package/core/core.cjs.native.js +9 -5
  16. package/core/watchQueryOptions.d.ts +1 -0
  17. package/core/watchQueryOptions.d.ts.map +1 -1
  18. package/core/watchQueryOptions.js.map +1 -1
  19. package/invariantErrorCodes.js +35 -23
  20. package/package.json +17 -5
  21. package/react/cache/SuspenseCache.d.ts +18 -0
  22. package/react/cache/SuspenseCache.d.ts.map +1 -0
  23. package/react/cache/SuspenseCache.js +49 -0
  24. package/react/cache/SuspenseCache.js.map +1 -0
  25. package/react/cache/index.d.ts +2 -0
  26. package/react/cache/index.d.ts.map +1 -0
  27. package/react/cache/index.js +2 -0
  28. package/react/cache/index.js.map +1 -0
  29. package/react/context/ApolloContext.d.ts +2 -0
  30. package/react/context/ApolloContext.d.ts.map +1 -1
  31. package/react/context/ApolloContext.js.map +1 -1
  32. package/react/context/ApolloProvider.d.ts +2 -0
  33. package/react/context/ApolloProvider.d.ts.map +1 -1
  34. package/react/context/ApolloProvider.js +4 -1
  35. package/react/context/ApolloProvider.js.map +1 -1
  36. package/react/context/context.cjs +4 -1
  37. package/react/context/context.cjs.map +1 -1
  38. package/react/context/context.cjs.native.js +4 -1
  39. package/react/hooks/compareResults.d.ts +3 -0
  40. package/react/hooks/compareResults.d.ts.map +1 -0
  41. package/react/hooks/compareResults.js +63 -0
  42. package/react/hooks/compareResults.js.map +1 -0
  43. package/react/hooks/hooks.cjs +189 -3
  44. package/react/hooks/hooks.cjs.map +1 -1
  45. package/react/hooks/hooks.cjs.native.js +189 -3
  46. package/react/hooks/index.d.ts +1 -0
  47. package/react/hooks/index.d.ts.map +1 -1
  48. package/react/hooks/index.js +1 -0
  49. package/react/hooks/index.js.map +1 -1
  50. package/react/hooks/internal/index.d.ts +2 -0
  51. package/react/hooks/internal/index.d.ts.map +1 -0
  52. package/react/hooks/internal/index.js +2 -0
  53. package/react/hooks/internal/index.js.map +1 -0
  54. package/react/hooks/internal/useDeepMemo.d.ts +3 -0
  55. package/react/hooks/internal/useDeepMemo.d.ts.map +1 -0
  56. package/react/hooks/internal/useDeepMemo.js +10 -0
  57. package/react/hooks/internal/useDeepMemo.js.map +1 -0
  58. package/react/hooks/useQuery.d.ts.map +1 -1
  59. package/react/hooks/useQuery.js +5 -3
  60. package/react/hooks/useQuery.js.map +1 -1
  61. package/react/hooks/useSuspenseCache.d.ts +2 -0
  62. package/react/hooks/useSuspenseCache.d.ts.map +1 -0
  63. package/react/hooks/useSuspenseCache.js +10 -0
  64. package/react/hooks/useSuspenseCache.js.map +1 -0
  65. package/react/hooks/useSuspenseQuery.d.ts +10 -0
  66. package/react/hooks/useSuspenseQuery.d.ts.map +1 -0
  67. package/react/hooks/useSuspenseQuery.js +179 -0
  68. package/react/hooks/useSuspenseQuery.js.map +1 -0
  69. package/react/index.d.ts +1 -0
  70. package/react/index.d.ts.map +1 -1
  71. package/react/index.js +1 -0
  72. package/react/index.js.map +1 -1
  73. package/react/parser/index.js +5 -5
  74. package/react/parser/parser.cjs +5 -5
  75. package/react/parser/parser.cjs.map +1 -1
  76. package/react/parser/parser.cjs.native.js +5 -5
  77. package/react/react.cjs +49 -2
  78. package/react/react.cjs.map +1 -1
  79. package/react/react.cjs.native.js +49 -2
  80. package/react/types/types.d.ts +9 -1
  81. package/react/types/types.d.ts.map +1 -1
  82. package/react/types/types.js.map +1 -1
  83. package/testing/core/core.cjs +1 -1
  84. package/testing/core/core.cjs.map +1 -1
  85. package/testing/core/core.cjs.native.js +1 -1
  86. package/testing/core/mocking/mockLink.js +1 -1
  87. package/testing/react/MockedProvider.d.ts +3 -0
  88. package/testing/react/MockedProvider.d.ts.map +1 -1
  89. package/testing/react/MockedProvider.js +8 -3
  90. package/testing/react/MockedProvider.js.map +1 -1
  91. package/testing/testing.cjs +54 -3
  92. package/testing/testing.cjs.map +1 -1
  93. package/testing/testing.cjs.native.js +54 -3
  94. package/utilities/globals/globals.cjs +1 -1
  95. package/utilities/globals/globals.cjs.map +1 -1
  96. package/utilities/globals/globals.cjs.native.js +1 -1
  97. package/utilities/globals/index.js +1 -1
  98. package/utilities/graphql/directives.js +4 -4
  99. package/utilities/graphql/fragments.js +3 -3
  100. package/utilities/graphql/getFromAST.js +8 -8
  101. package/utilities/graphql/storeUtils.js +1 -1
  102. package/utilities/utilities.cjs +16 -16
  103. package/utilities/utilities.cjs.map +1 -1
  104. package/utilities/utilities.cjs.native.js +16 -16
  105. package/version.js +1 -1
package/README.md CHANGED
@@ -21,13 +21,13 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
21
21
 
22
22
  ## Maintainers
23
23
 
24
- - [@benjamn](https://github.com/benjamn)
25
- - [@alessbell](https://github.com/alessbell)
26
- - [@bignimbus](https://github.com/bignimbus)
27
- - [@hwillson](https://github.com/hwillson)
28
- - [@jpvajda](https://github.com/jpvajda)
29
- - [@mrdoombringer](https://github.com/mrdoombringer)
30
- - [@jerelmiller](https://github.com/jerelmiller)
24
+ |Name|Username|
25
+ |---|---|
26
+ |Ben Newman|[@benjamn](https://github.com/benjamn)|
27
+ |Alessia Bellisario|[@alessbell](https://github.com/alessbell)|
28
+ |Jeff Auriemma|[@bignimbus](https://github.com/bignimbus)|
29
+ |Hugh Willson|[@hwillson](https://github.com/hwillson)|
30
+ |Jerel Miller|[@jerelmiller](https://github.com/jerelmiller)|
31
31
 
32
32
  ## Who is Apollo?
33
33
 
package/apollo-client.cjs CHANGED
@@ -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 @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 39);
48
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 41);
49
49
  }
50
50
  else {
51
51
  evaledValue = ifArgument.value.value;
@@ -81,13 +81,13 @@ function getInclusionDirectives(directives) {
81
81
  return;
82
82
  var directiveArguments = directive.arguments;
83
83
  var directiveName = directive.name.value;
84
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 40);
84
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 42);
85
85
  var ifArgument = directiveArguments[0];
86
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 41);
86
+ __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 43);
87
87
  var ifValue = ifArgument.value;
88
88
  __DEV__ ? tsInvariant.invariant(ifValue &&
89
89
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
90
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 42);
90
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 44);
91
91
  result.push({ directive: directive, ifArgument: ifArgument });
92
92
  });
93
93
  }
@@ -100,14 +100,14 @@ function getFragmentQueryDocument(document, fragmentName) {
100
100
  document.definitions.forEach(function (definition) {
101
101
  if (definition.kind === 'OperationDefinition') {
102
102
  throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
103
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(43);
103
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(45);
104
104
  }
105
105
  if (definition.kind === 'FragmentDefinition') {
106
106
  fragments.push(definition);
107
107
  }
108
108
  });
109
109
  if (typeof actualFragmentName === 'undefined') {
110
- __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, 44);
110
+ __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, 46);
111
111
  actualFragmentName = fragments[0].name.value;
112
112
  }
113
113
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -148,7 +148,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
148
148
  return fragmentMap(fragmentName);
149
149
  }
150
150
  var fragment = fragmentMap && fragmentMap[fragmentName];
151
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 45);
151
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 47);
152
152
  return fragment || null;
153
153
  }
154
154
  default:
@@ -232,7 +232,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
232
232
  else {
233
233
  throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
234
234
  'is not supported. Use variables instead of inline arguments to ' +
235
- 'overcome this limitation.') : new tsInvariant.InvariantError(54);
235
+ 'overcome this limitation.') : new tsInvariant.InvariantError(56);
236
236
  }
237
237
  }
238
238
  function storeKeyNameFromField(field, variables) {
@@ -366,16 +366,16 @@ function isInlineFragment(selection) {
366
366
  }
367
367
 
368
368
  function checkDocument(doc) {
369
- __DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 46);
369
+ __DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 48);
370
370
  var operations = doc.definitions
371
371
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
372
372
  .map(function (definition) {
373
373
  if (definition.kind !== 'OperationDefinition') {
374
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(47);
374
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(49);
375
375
  }
376
376
  return definition;
377
377
  });
378
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 48);
378
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 50);
379
379
  return doc;
380
380
  }
381
381
  function getOperationDefinition(doc) {
@@ -394,14 +394,14 @@ function getFragmentDefinitions(doc) {
394
394
  }
395
395
  function getQueryDefinition(doc) {
396
396
  var queryDef = getOperationDefinition(doc);
397
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 49);
397
+ __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 51);
398
398
  return queryDef;
399
399
  }
400
400
  function getFragmentDefinition(doc) {
401
- __DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 50);
402
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 51);
401
+ __DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 52);
402
+ __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 53);
403
403
  var fragmentDef = doc.definitions[0];
404
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 52);
404
+ __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 54);
405
405
  return fragmentDef;
406
406
  }
407
407
  function getMainDefinition(queryDoc) {
@@ -424,7 +424,7 @@ function getMainDefinition(queryDoc) {
424
424
  if (fragmentDefinition) {
425
425
  return fragmentDefinition;
426
426
  }
427
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(53);
427
+ throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(55);
428
428
  }
429
429
  function getDefaultValues(definition) {
430
430
  var defaultValues = Object.create(null);
@@ -1345,7 +1345,7 @@ var concat = ApolloLink.concat;
1345
1345
 
1346
1346
  var execute = ApolloLink.execute;
1347
1347
 
1348
- var version = '3.7.3';
1348
+ var version = '3.8.0-alpha.1';
1349
1349
 
1350
1350
  function isNodeResponse(value) {
1351
1351
  return !!value.body;
@@ -4274,13 +4274,14 @@ var ObservableQuery = (function (_super) {
4274
4274
  function ObservableQuery(_a) {
4275
4275
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
4276
4276
  var _this = _super.call(this, function (observer) {
4277
+ var _a = options.fetchOnFirstSubscribe, fetchOnFirstSubscribe = _a === void 0 ? true : _a;
4277
4278
  try {
4278
4279
  var subObserver = observer._subscription._observer;
4279
4280
  if (subObserver && !subObserver.error) {
4280
4281
  subObserver.error = defaultSubscriptionObserverErrorCallback;
4281
4282
  }
4282
4283
  }
4283
- catch (_a) { }
4284
+ catch (_b) { }
4284
4285
  var first = !_this.observers.size;
4285
4286
  _this.observers.add(observer);
4286
4287
  var last = _this.last;
@@ -4290,7 +4291,7 @@ var ObservableQuery = (function (_super) {
4290
4291
  else if (last && last.result) {
4291
4292
  observer.next && observer.next(last.result);
4292
4293
  }
4293
- if (first) {
4294
+ if (first && fetchOnFirstSubscribe) {
4294
4295
  _this.reobserve().catch(function () { });
4295
4296
  }
4296
4297
  return function () {
@@ -4653,7 +4654,7 @@ var ObservableQuery = (function (_super) {
4653
4654
  }
4654
4655
  return this.last;
4655
4656
  };
4656
- ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
4657
+ ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
4657
4658
  var _this = this;
4658
4659
  this.isTornDown = false;
4659
4660
  var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
@@ -4696,7 +4697,10 @@ var ObservableQuery = (function (_super) {
4696
4697
  this.observer = observer;
4697
4698
  }
4698
4699
  concast.addObserver(observer);
4699
- return concast.promise;
4700
+ return concast;
4701
+ };
4702
+ ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
4703
+ return this.reobserveAsConcast(newOptions, newNetworkStatus).promise;
4700
4704
  };
4701
4705
  ObservableQuery.prototype.observe = function () {
4702
4706
  this.reportResult(this.getCurrentResult(false), this.variables);
@@ -6424,13 +6428,16 @@ var ApolloConsumer = function (props) {
6424
6428
  };
6425
6429
 
6426
6430
  var ApolloProvider = function (_a) {
6427
- var client = _a.client, children = _a.children;
6431
+ var client = _a.client, suspenseCache = _a.suspenseCache, children = _a.children;
6428
6432
  var ApolloContext = getApolloContext();
6429
6433
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6430
6434
  if (context === void 0) { context = {}; }
6431
6435
  if (client && context.client !== client) {
6432
6436
  context = Object.assign({}, context, { client: client });
6433
6437
  }
6438
+ if (suspenseCache) {
6439
+ context = Object.assign({}, context, { suspenseCache: suspenseCache });
6440
+ }
6434
6441
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
6435
6442
  'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 28);
6436
6443
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
@@ -6520,7 +6527,7 @@ function parser(document) {
6520
6527
  var variables, type, name;
6521
6528
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6522
6529
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6523
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 32);
6530
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 34);
6524
6531
  var fragments = [];
6525
6532
  var queries = [];
6526
6533
  var mutations = [];
@@ -6548,11 +6555,11 @@ function parser(document) {
6548
6555
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6549
6556
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6550
6557
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6551
- (queries.length || mutations.length || subscriptions.length), 33);
6558
+ (queries.length || mutations.length || subscriptions.length), 35);
6552
6559
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6553
6560
  "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6554
6561
  "subscriptions and ".concat(mutations.length, " mutations. ") +
6555
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 34);
6562
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 36);
6556
6563
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6557
6564
  if (!queries.length && !mutations.length)
6558
6565
  type = exports.DocumentType.Subscription;
@@ -6563,7 +6570,7 @@ function parser(document) {
6563
6570
  : subscriptions;
6564
6571
  __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6565
6572
  "".concat(definitions.length, " definitions. ") +
6566
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 35);
6573
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 37);
6567
6574
  var definition = definitions[0];
6568
6575
  variables = definition.variableDefinitions || [];
6569
6576
  if (definition.name && definition.name.kind === 'Name') {
@@ -6581,7 +6588,7 @@ function verifyDocumentType(document, type) {
6581
6588
  var requiredOperationName = operationName(type);
6582
6589
  var usedOperationName = operationName(operation.type);
6583
6590
  __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6584
- "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 36);
6591
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 38);
6585
6592
  }
6586
6593
 
6587
6594
  var hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -6808,16 +6815,18 @@ var InternalState = (function () {
6808
6815
  }
6809
6816
  this.result = nextResult;
6810
6817
  this.forceUpdate();
6811
- this.handleErrorOrCompleted(nextResult);
6818
+ this.handleErrorOrCompleted(nextResult, previousResult);
6812
6819
  };
6813
- InternalState.prototype.handleErrorOrCompleted = function (result) {
6820
+ InternalState.prototype.handleErrorOrCompleted = function (result, previousResult) {
6814
6821
  var _this = this;
6815
6822
  if (!result.loading) {
6816
6823
  Promise.resolve().then(function () {
6817
6824
  if (result.error) {
6818
6825
  _this.onError(result.error);
6819
6826
  }
6820
- else if (result.data) {
6827
+ else if (result.data &&
6828
+ (previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus) !== result.networkStatus &&
6829
+ result.networkStatus === exports.NetworkStatus.ready) {
6821
6830
  _this.onCompleted(result.data);
6822
6831
  }
6823
6832
  }).catch(function (error) {
@@ -7186,6 +7195,236 @@ function diffToResult(diff) {
7186
7195
  return result;
7187
7196
  }
7188
7197
 
7198
+ function useDeepMemo(memoFn, deps) {
7199
+ var ref = React.useRef();
7200
+ if (!ref.current || !equality.equal(ref.current.deps, deps)) {
7201
+ ref.current = { value: memoFn(), deps: deps };
7202
+ }
7203
+ return ref.current.value;
7204
+ }
7205
+
7206
+ function useSuspenseCache() {
7207
+ var suspenseCache = React.useContext(getApolloContext()).suspenseCache;
7208
+ __DEV__ ? tsInvariant.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context. Wrap the root component ' +
7209
+ 'in an <ApolloProvider> and provide a suspenseCache.') : tsInvariant.invariant(suspenseCache, 32);
7210
+ return suspenseCache;
7211
+ }
7212
+
7213
+ var SUPPORTED_FETCH_POLICIES = [
7214
+ 'cache-first',
7215
+ 'network-only',
7216
+ 'no-cache',
7217
+ 'cache-and-network',
7218
+ ];
7219
+ var DEFAULT_FETCH_POLICY = 'cache-first';
7220
+ var DEFAULT_SUSPENSE_POLICY = 'always';
7221
+ var DEFAULT_ERROR_POLICY = 'none';
7222
+ function useSuspenseQuery_experimental(query, options) {
7223
+ if (options === void 0) { options = Object.create(null); }
7224
+ var suspenseCache = useSuspenseCache();
7225
+ var client = useApolloClient(options.client);
7226
+ var watchQueryOptions = useWatchQueryOptions({ query: query, options: options, client: client });
7227
+ var previousWatchQueryOptionsRef = React.useRef(watchQueryOptions);
7228
+ var deferred = useIsDeferred(query);
7229
+ var fetchPolicy = watchQueryOptions.fetchPolicy, errorPolicy = watchQueryOptions.errorPolicy, returnPartialData = watchQueryOptions.returnPartialData, variables = watchQueryOptions.variables;
7230
+ var cacheEntry = suspenseCache.lookup(query, variables);
7231
+ var observable = React.useState(function () {
7232
+ return (cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.observable) || client.watchQuery(watchQueryOptions);
7233
+ })[0];
7234
+ var result = useObservableQueryResult(observable);
7235
+ var hasFullResult = result.data && !result.partial;
7236
+ var hasPartialResult = result.data && result.partial;
7237
+ var usePartialResult = returnPartialData && hasPartialResult;
7238
+ if (result.error &&
7239
+ errorPolicy === 'none' &&
7240
+ (!deferred || !hasPartialResult)) {
7241
+ throw result.error;
7242
+ }
7243
+ if (result.loading) {
7244
+ if (!cacheEntry) {
7245
+ cacheEntry = suspenseCache.add(query, variables, {
7246
+ promise: maybeWrapConcastWithCustomPromise(observable.reobserveAsConcast(watchQueryOptions), { deferred: deferred }),
7247
+ observable: observable,
7248
+ });
7249
+ }
7250
+ var hasUsableResult = usePartialResult ||
7251
+ (fetchPolicy === 'cache-and-network' && hasFullResult);
7252
+ if (!hasUsableResult && !cacheEntry.fulfilled) {
7253
+ throw cacheEntry.promise;
7254
+ }
7255
+ }
7256
+ React.useEffect(function () {
7257
+ var variables = watchQueryOptions.variables, query = watchQueryOptions.query;
7258
+ var previousOpts = previousWatchQueryOptionsRef.current;
7259
+ if (variables !== previousOpts.variables || query !== previousOpts.query) {
7260
+ suspenseCache.remove(previousOpts.query, previousOpts.variables);
7261
+ suspenseCache.add(query, variables, {
7262
+ promise: observable.reobserve({ query: query, variables: variables }),
7263
+ observable: observable,
7264
+ });
7265
+ previousWatchQueryOptionsRef.current = watchQueryOptions;
7266
+ }
7267
+ }, [watchQueryOptions]);
7268
+ React.useEffect(function () {
7269
+ return function () {
7270
+ suspenseCache.remove(query, variables);
7271
+ };
7272
+ }, []);
7273
+ return React.useMemo(function () {
7274
+ return {
7275
+ data: result.data,
7276
+ error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
7277
+ fetchMore: function (options) {
7278
+ var promise = observable.fetchMore(options);
7279
+ suspenseCache.add(query, watchQueryOptions.variables, {
7280
+ promise: promise,
7281
+ observable: observable,
7282
+ });
7283
+ return promise;
7284
+ },
7285
+ refetch: function (variables) {
7286
+ var promise = observable.refetch(variables);
7287
+ suspenseCache.add(query, watchQueryOptions.variables, {
7288
+ promise: promise,
7289
+ observable: observable,
7290
+ });
7291
+ return promise;
7292
+ },
7293
+ };
7294
+ }, [result, observable, errorPolicy]);
7295
+ }
7296
+ function validateOptions(options) {
7297
+ var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
7298
+ verifyDocumentType(query, exports.DocumentType.Query);
7299
+ validateFetchPolicy(fetchPolicy);
7300
+ validatePartialDataReturn(fetchPolicy, returnPartialData);
7301
+ }
7302
+ function validateFetchPolicy(fetchPolicy) {
7303
+ __DEV__ ? tsInvariant.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : tsInvariant.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), 33);
7304
+ }
7305
+ function validatePartialDataReturn(fetchPolicy, returnPartialData) {
7306
+ if (fetchPolicy === 'no-cache' && returnPartialData) {
7307
+ __DEV__ && tsInvariant.invariant.warn('Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.');
7308
+ }
7309
+ }
7310
+ function toApolloError(result) {
7311
+ return isNonEmptyArray(result.errors)
7312
+ ? new ApolloError({ graphQLErrors: result.errors })
7313
+ : result.error;
7314
+ }
7315
+ function maybeWrapConcastWithCustomPromise(concast, _a) {
7316
+ var deferred = _a.deferred;
7317
+ if (deferred) {
7318
+ return new Promise(function (resolve, reject) {
7319
+ var subscription = concast.subscribe({
7320
+ next: function (value) {
7321
+ resolve(value);
7322
+ subscription.unsubscribe();
7323
+ },
7324
+ error: reject,
7325
+ });
7326
+ });
7327
+ }
7328
+ return concast.promise;
7329
+ }
7330
+ function useWatchQueryOptions(_a) {
7331
+ var query = _a.query, options = _a.options, client = _a.client;
7332
+ var defaultOptions = client.defaultOptions.watchQuery;
7333
+ var watchQueryOptions = useDeepMemo(function () {
7334
+ var errorPolicy = options.errorPolicy, fetchPolicy = options.fetchPolicy, _a = options.suspensePolicy, suspensePolicy = _a === void 0 ? DEFAULT_SUSPENSE_POLICY : _a, variables = options.variables, watchQueryOptions = tslib.__rest(options, ["errorPolicy", "fetchPolicy", "suspensePolicy", "variables"]);
7335
+ return tslib.__assign(tslib.__assign({}, watchQueryOptions), { query: query, errorPolicy: errorPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.errorPolicy) || DEFAULT_ERROR_POLICY, fetchPolicy: fetchPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.fetchPolicy) || DEFAULT_FETCH_POLICY, notifyOnNetworkStatusChange: suspensePolicy === 'always', fetchOnFirstSubscribe: false, variables: compact(tslib.__assign(tslib.__assign({}, defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.variables), variables)) });
7336
+ }, [options, query, defaultOptions]);
7337
+ if (__DEV__) {
7338
+ validateOptions(watchQueryOptions);
7339
+ }
7340
+ return watchQueryOptions;
7341
+ }
7342
+ function useIsDeferred(query) {
7343
+ return React.useMemo(function () { return hasDirectives(['defer'], query); }, [query]);
7344
+ }
7345
+ function useObservableQueryResult(observable) {
7346
+ var resultRef = React.useRef();
7347
+ var isMountedRef = React.useRef(false);
7348
+ if (!resultRef.current) {
7349
+ resultRef.current = observable.getCurrentResult();
7350
+ }
7351
+ React.useLayoutEffect(function () {
7352
+ isMountedRef.current = true;
7353
+ return function () {
7354
+ isMountedRef.current = false;
7355
+ };
7356
+ }, []);
7357
+ return useSyncExternalStore(React.useCallback(function (forceUpdate) {
7358
+ function handleUpdate() {
7359
+ var previousResult = resultRef.current;
7360
+ var result = observable.getCurrentResult();
7361
+ if (previousResult.loading === result.loading &&
7362
+ previousResult.networkStatus === result.networkStatus &&
7363
+ equality.equal(previousResult.data, result.data)) {
7364
+ return;
7365
+ }
7366
+ resultRef.current = result;
7367
+ if (isMountedRef.current) {
7368
+ forceUpdate();
7369
+ }
7370
+ }
7371
+ var subscription = observable.subscribe({
7372
+ next: handleUpdate,
7373
+ error: handleUpdate,
7374
+ });
7375
+ return function () {
7376
+ subscription.unsubscribe();
7377
+ };
7378
+ }, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
7379
+ }
7380
+
7381
+ var SuspenseCache = (function () {
7382
+ function SuspenseCache() {
7383
+ this.queries = new Map();
7384
+ }
7385
+ SuspenseCache.prototype.add = function (query, variables, _a) {
7386
+ var promise = _a.promise, observable = _a.observable;
7387
+ var variablesKey = this.getVariablesKey(variables);
7388
+ var map = this.queries.get(query) || new Map();
7389
+ var entry = {
7390
+ observable: observable,
7391
+ fulfilled: false,
7392
+ promise: promise
7393
+ .catch(function () {
7394
+ })
7395
+ .finally(function () {
7396
+ entry.fulfilled = true;
7397
+ }),
7398
+ };
7399
+ map.set(variablesKey, entry);
7400
+ this.queries.set(query, map);
7401
+ return entry;
7402
+ };
7403
+ SuspenseCache.prototype.lookup = function (query, variables) {
7404
+ var _a;
7405
+ return (_a = this.queries
7406
+ .get(query)) === null || _a === void 0 ? void 0 : _a.get(this.getVariablesKey(variables));
7407
+ };
7408
+ SuspenseCache.prototype.remove = function (query, variables) {
7409
+ var map = this.queries.get(query);
7410
+ if (!map) {
7411
+ return;
7412
+ }
7413
+ var key = this.getVariablesKey(variables);
7414
+ var entry = map.get(key);
7415
+ if (entry && !entry.observable.hasObservers()) {
7416
+ map.delete(key);
7417
+ }
7418
+ if (map.size === 0) {
7419
+ this.queries.delete(query);
7420
+ }
7421
+ };
7422
+ SuspenseCache.prototype.getVariablesKey = function (variables) {
7423
+ return canonicalStringify(variables || Object.create(null));
7424
+ };
7425
+ return SuspenseCache;
7426
+ }());
7427
+
7189
7428
  exports.setLogVerbosity = tsInvariant.setVerbosity;
7190
7429
  exports.Observable = zenObservableTs.Observable;
7191
7430
  exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
@@ -7203,6 +7442,7 @@ exports.HttpLink = HttpLink;
7203
7442
  exports.InMemoryCache = InMemoryCache;
7204
7443
  exports.MissingFieldError = MissingFieldError;
7205
7444
  exports.ObservableQuery = ObservableQuery;
7445
+ exports.SuspenseCache = SuspenseCache;
7206
7446
  exports.checkFetcher = checkFetcher;
7207
7447
  exports.concat = concat;
7208
7448
  exports.createHttpLink = createHttpLink;
@@ -7240,4 +7480,5 @@ exports.useMutation = useMutation;
7240
7480
  exports.useQuery = useQuery;
7241
7481
  exports.useReactiveVar = useReactiveVar;
7242
7482
  exports.useSubscription = useSubscription;
7483
+ exports.useSuspenseQuery_experimental = useSuspenseQuery_experimental;
7243
7484
  //# sourceMappingURL=apollo-client.cjs.map