@apollo/client 3.8.0-alpha.12 → 3.8.0-alpha.13

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 (90) hide show
  1. package/apollo-client.cjs +145 -119
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/core/ObservableQuery.d.ts.map +1 -1
  5. package/core/ObservableQuery.js.map +1 -1
  6. package/core/core.cjs +1 -1
  7. package/core/core.cjs.map +1 -1
  8. package/core/core.cjs.native.js +1 -1
  9. package/invariantErrorCodes.js +29 -34
  10. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  11. package/link/persisted-queries/index.d.ts.map +1 -1
  12. package/link/persisted-queries/index.js +12 -13
  13. package/link/persisted-queries/index.js.map +1 -1
  14. package/link/persisted-queries/persisted-queries.cjs +12 -13
  15. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  16. package/link/persisted-queries/persisted-queries.cjs.native.js +12 -13
  17. package/link/utils/throwServerError.d.ts +1 -1
  18. package/link/utils/throwServerError.d.ts.map +1 -1
  19. package/link/utils/throwServerError.js.map +1 -1
  20. package/package.json +18 -17
  21. package/react/cache/QuerySubscription.d.ts +11 -4
  22. package/react/cache/QuerySubscription.d.ts.map +1 -1
  23. package/react/cache/QuerySubscription.js +52 -34
  24. package/react/cache/QuerySubscription.js.map +1 -1
  25. package/react/context/ApolloConsumer.js +1 -1
  26. package/react/context/ApolloProvider.js +1 -1
  27. package/react/context/context.cjs +2 -2
  28. package/react/context/context.cjs.map +1 -1
  29. package/react/context/context.cjs.native.js +2 -2
  30. package/react/hoc/hoc-utils.js +1 -1
  31. package/react/hoc/hoc.cjs +2 -2
  32. package/react/hoc/hoc.cjs.map +1 -1
  33. package/react/hoc/hoc.cjs.native.js +2 -2
  34. package/react/hoc/withApollo.js +1 -1
  35. package/react/hooks/hooks.cjs +58 -63
  36. package/react/hooks/hooks.cjs.map +1 -1
  37. package/react/hooks/hooks.cjs.native.js +58 -63
  38. package/react/hooks/useApolloClient.js +1 -1
  39. package/react/hooks/useFragment.d.ts +2 -1
  40. package/react/hooks/useFragment.d.ts.map +1 -1
  41. package/react/hooks/useFragment.js.map +1 -1
  42. package/react/hooks/useSubscription.d.ts.map +1 -1
  43. package/react/hooks/useSubscription.js +25 -13
  44. package/react/hooks/useSubscription.js.map +1 -1
  45. package/react/hooks/useSuspenseCache.js +1 -1
  46. package/react/hooks/useSuspenseQuery.d.ts +15 -3
  47. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  48. package/react/hooks/useSuspenseQuery.js +34 -52
  49. package/react/hooks/useSuspenseQuery.js.map +1 -1
  50. package/react/parser/index.js +5 -5
  51. package/react/parser/parser.cjs +5 -5
  52. package/react/parser/parser.cjs.map +1 -1
  53. package/react/parser/parser.cjs.native.js +5 -5
  54. package/react/react.cjs +52 -33
  55. package/react/react.cjs.map +1 -1
  56. package/react/react.cjs.native.js +52 -33
  57. package/react/types/types.d.ts +1 -3
  58. package/react/types/types.d.ts.map +1 -1
  59. package/react/types/types.js.map +1 -1
  60. package/testing/core/core.cjs +1 -1
  61. package/testing/core/core.cjs.map +1 -1
  62. package/testing/core/core.cjs.native.js +1 -1
  63. package/testing/core/mocking/mockLink.js +1 -1
  64. package/utilities/graphql/directives.js +4 -4
  65. package/utilities/graphql/fragments.js +3 -3
  66. package/utilities/graphql/getFromAST.js +8 -8
  67. package/utilities/graphql/storeUtils.js +1 -1
  68. package/utilities/index.d.ts +2 -1
  69. package/utilities/index.d.ts.map +1 -1
  70. package/utilities/index.js +1 -1
  71. package/utilities/index.js.map +1 -1
  72. package/utilities/promises/decoration.d.ts +2 -0
  73. package/utilities/promises/decoration.d.ts.map +1 -1
  74. package/utilities/promises/decoration.js +12 -0
  75. package/utilities/promises/decoration.js.map +1 -1
  76. package/utilities/types/DeepOmit.d.ts +4 -3
  77. package/utilities/types/DeepOmit.d.ts.map +1 -1
  78. package/utilities/types/DeepOmit.js.map +1 -1
  79. package/utilities/types/DeepPartial.d.ts +12 -0
  80. package/utilities/types/DeepPartial.d.ts.map +1 -0
  81. package/utilities/types/DeepPartial.js +2 -0
  82. package/utilities/types/DeepPartial.js.map +1 -0
  83. package/utilities/types/Primitive.d.ts +2 -0
  84. package/utilities/types/Primitive.d.ts.map +1 -0
  85. package/utilities/types/Primitive.js +2 -0
  86. package/utilities/types/Primitive.js.map +1 -0
  87. package/utilities/utilities.cjs +30 -16
  88. package/utilities/utilities.cjs.map +1 -1
  89. package/utilities/utilities.cjs.native.js +30 -16
  90. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -67,7 +67,7 @@ function shouldInclude(_a, variables) {
67
67
  var evaledValue = false;
68
68
  if (ifArgument.value.kind === 'Variable') {
69
69
  evaledValue = variables && variables[ifArgument.value.name.value];
70
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 42);
70
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 41);
71
71
  }
72
72
  else {
73
73
  evaledValue = ifArgument.value.value;
@@ -75,7 +75,6 @@ function shouldInclude(_a, variables) {
75
75
  return directive.name.value === 'skip' ? !evaledValue : evaledValue;
76
76
  });
77
77
  }
78
- var hasAnyDirectives = function (names, root) { return hasDirectives(names, root, false); };
79
78
  function hasDirectives(names, root, all) {
80
79
  var nameSet = new Set(names);
81
80
  var uniqueCount = nameSet.size;
@@ -104,13 +103,13 @@ function getInclusionDirectives(directives) {
104
103
  return;
105
104
  var directiveArguments = directive.arguments;
106
105
  var directiveName = directive.name.value;
107
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 43);
106
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 42);
108
107
  var ifArgument = directiveArguments[0];
109
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 44);
108
+ __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);
110
109
  var ifValue = ifArgument.value;
111
110
  __DEV__ ? tsInvariant.invariant(ifValue &&
112
111
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
113
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 45);
112
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 44);
114
113
  result.push({ directive: directive, ifArgument: ifArgument });
115
114
  });
116
115
  }
@@ -123,14 +122,14 @@ function getFragmentQueryDocument(document, fragmentName) {
123
122
  document.definitions.forEach(function (definition) {
124
123
  if (definition.kind === 'OperationDefinition') {
125
124
  throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
126
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(46);
125
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(45);
127
126
  }
128
127
  if (definition.kind === 'FragmentDefinition') {
129
128
  fragments.push(definition);
130
129
  }
131
130
  });
132
131
  if (typeof actualFragmentName === 'undefined') {
133
- __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, 47);
132
+ __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);
134
133
  actualFragmentName = fragments[0].name.value;
135
134
  }
136
135
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -171,7 +170,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
171
170
  return fragmentMap(fragmentName);
172
171
  }
173
172
  var fragment = fragmentMap && fragmentMap[fragmentName];
174
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 48);
173
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 47);
175
174
  return fragment || null;
176
175
  }
177
176
  default:
@@ -261,7 +260,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
261
260
  else {
262
261
  throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
263
262
  'is not supported. Use variables instead of inline arguments to ' +
264
- 'overcome this limitation.') : new tsInvariant.InvariantError(57);
263
+ 'overcome this limitation.') : new tsInvariant.InvariantError(56);
265
264
  }
266
265
  }
267
266
  function storeKeyNameFromField(field, variables) {
@@ -396,16 +395,16 @@ function isInlineFragment(selection) {
396
395
  }
397
396
 
398
397
  function checkDocument(doc) {
399
- __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', 49);
398
+ __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);
400
399
  var operations = doc.definitions
401
400
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
402
401
  .map(function (definition) {
403
402
  if (definition.kind !== 'OperationDefinition') {
404
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(50);
403
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(49);
405
404
  }
406
405
  return definition;
407
406
  });
408
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 51);
407
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 50);
409
408
  return doc;
410
409
  }
411
410
  function getOperationDefinition(doc) {
@@ -428,14 +427,14 @@ function getFragmentDefinitions(doc) {
428
427
  }
429
428
  function getQueryDefinition(doc) {
430
429
  var queryDef = getOperationDefinition(doc);
431
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 52);
430
+ __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 51);
432
431
  return queryDef;
433
432
  }
434
433
  function getFragmentDefinition(doc) {
435
- __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', 53);
436
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 54);
434
+ __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);
435
+ __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 53);
437
436
  var fragmentDef = doc.definitions[0];
438
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 55);
437
+ __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 54);
439
438
  return fragmentDef;
440
439
  }
441
440
  function getMainDefinition(queryDoc) {
@@ -458,7 +457,7 @@ function getMainDefinition(queryDoc) {
458
457
  if (fragmentDefinition) {
459
458
  return fragmentDefinition;
460
459
  }
461
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(56);
460
+ throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(55);
462
461
  }
463
462
  function getDefaultValues(definition) {
464
463
  var defaultValues = Object.create(null);
@@ -817,6 +816,18 @@ var DeepMerger = (function () {
817
816
  return DeepMerger;
818
817
  }());
819
818
 
819
+ function createFulfilledPromise(value) {
820
+ var promise = Promise.resolve(value);
821
+ promise.status = 'fulfilled';
822
+ promise.value = value;
823
+ return promise;
824
+ }
825
+ function createRejectedPromise(reason) {
826
+ var promise = Promise.reject(reason);
827
+ promise.status = 'rejected';
828
+ promise.reason = reason;
829
+ return promise;
830
+ }
820
831
  function isStatefulPromise(promise) {
821
832
  return 'status' in promise;
822
833
  }
@@ -1490,7 +1501,7 @@ var concat = ApolloLink.concat;
1490
1501
 
1491
1502
  var execute = ApolloLink.execute;
1492
1503
 
1493
- var version = '3.8.0-alpha.12';
1504
+ var version = '3.8.0-alpha.13';
1494
1505
 
1495
1506
  function asyncIterator(source) {
1496
1507
  var _a;
@@ -6741,7 +6752,7 @@ var ApolloConsumer = function (props) {
6741
6752
  var ApolloContext = getApolloContext();
6742
6753
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6743
6754
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
6744
- 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 29);
6755
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 28);
6745
6756
  return props.children(context.client);
6746
6757
  }));
6747
6758
  };
@@ -6758,7 +6769,7 @@ var ApolloProvider = function (_a) {
6758
6769
  context = Object.assign({}, context, { suspenseCache: suspenseCache });
6759
6770
  }
6760
6771
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
6761
- 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 30);
6772
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 29);
6762
6773
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6763
6774
  }));
6764
6775
  };
@@ -6768,7 +6779,7 @@ function useApolloClient(override) {
6768
6779
  var client = override || context.client;
6769
6780
  __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
6770
6781
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
6771
- 'instance in via options.') : tsInvariant.invariant(!!client, 33);
6782
+ 'instance in via options.') : tsInvariant.invariant(!!client, 32);
6772
6783
  return client;
6773
6784
  }
6774
6785
 
@@ -6846,7 +6857,7 @@ function parser(document) {
6846
6857
  var variables, type, name;
6847
6858
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6848
6859
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6849
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 36);
6860
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 35);
6850
6861
  var fragments = [];
6851
6862
  var queries = [];
6852
6863
  var mutations = [];
@@ -6874,11 +6885,11 @@ function parser(document) {
6874
6885
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6875
6886
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6876
6887
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6877
- (queries.length || mutations.length || subscriptions.length), 37);
6888
+ (queries.length || mutations.length || subscriptions.length), 36);
6878
6889
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6879
6890
  "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6880
6891
  "subscriptions and ".concat(mutations.length, " mutations. ") +
6881
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 38);
6892
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 37);
6882
6893
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6883
6894
  if (!queries.length && !mutations.length)
6884
6895
  type = exports.DocumentType.Subscription;
@@ -6889,7 +6900,7 @@ function parser(document) {
6889
6900
  : subscriptions;
6890
6901
  __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6891
6902
  "".concat(definitions.length, " definitions. ") +
6892
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 39);
6903
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 38);
6893
6904
  var definition = definitions[0];
6894
6905
  variables = definition.variableDefinitions || [];
6895
6906
  if (definition.name && definition.name.kind === 'Name') {
@@ -6907,7 +6918,7 @@ function verifyDocumentType(document, type) {
6907
6918
  var requiredOperationName = operationName(type);
6908
6919
  var usedOperationName = operationName(operation.type);
6909
6920
  __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6910
- "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 40);
6921
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 39);
6911
6922
  }
6912
6923
 
6913
6924
  var hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -7438,9 +7449,13 @@ function useSubscription(subscription, options) {
7438
7449
  if (!observable) {
7439
7450
  return;
7440
7451
  }
7452
+ var subscriptionStopped = false;
7441
7453
  var subscription = observable.subscribe({
7442
7454
  next: function (fetchResult) {
7443
7455
  var _a, _b;
7456
+ if (subscriptionStopped) {
7457
+ return;
7458
+ }
7444
7459
  var result = {
7445
7460
  loading: false,
7446
7461
  data: fetchResult.data,
@@ -7463,26 +7478,33 @@ function useSubscription(subscription, options) {
7463
7478
  },
7464
7479
  error: function (error) {
7465
7480
  var _a, _b;
7466
- setResult({
7467
- loading: false,
7468
- data: void 0,
7469
- error: error,
7470
- variables: options === null || options === void 0 ? void 0 : options.variables,
7471
- });
7472
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
7481
+ if (!subscriptionStopped) {
7482
+ setResult({
7483
+ loading: false,
7484
+ data: void 0,
7485
+ error: error,
7486
+ variables: options === null || options === void 0 ? void 0 : options.variables,
7487
+ });
7488
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
7489
+ }
7473
7490
  },
7474
7491
  complete: function () {
7475
7492
  var _a, _b;
7476
- if ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onComplete) {
7477
- ref.current.options.onComplete();
7478
- }
7479
- else if ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onSubscriptionComplete) {
7480
- ref.current.options.onSubscriptionComplete();
7493
+ if (!subscriptionStopped) {
7494
+ if ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onComplete) {
7495
+ ref.current.options.onComplete();
7496
+ }
7497
+ else if ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onSubscriptionComplete) {
7498
+ ref.current.options.onSubscriptionComplete();
7499
+ }
7481
7500
  }
7482
7501
  },
7483
7502
  });
7484
7503
  return function () {
7485
- subscription.unsubscribe();
7504
+ subscriptionStopped = true;
7505
+ setTimeout(function () {
7506
+ subscription.unsubscribe();
7507
+ });
7486
7508
  };
7487
7509
  }, [observable]);
7488
7510
  return result;
@@ -7574,46 +7596,40 @@ function useSuspenseCache(override) {
7574
7596
  var suspenseCache = override || context.suspenseCache;
7575
7597
  __DEV__ ? tsInvariant.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context or passed in as an option. ' +
7576
7598
  'Wrap the root component in an <ApolloProvider> and provide a suspenseCache, ' +
7577
- 'or pass a SuspenseCache instance in via options.') : tsInvariant.invariant(suspenseCache, 34);
7599
+ 'or pass a SuspenseCache instance in via options.') : tsInvariant.invariant(suspenseCache, 33);
7578
7600
  return suspenseCache;
7579
7601
  }
7580
7602
 
7581
7603
  function useSuspenseQuery_experimental(query, options) {
7582
7604
  if (options === void 0) { options = Object.create(null); }
7583
- var didPreviouslySuspend = React.useRef(false);
7584
7605
  var client = useApolloClient(options.client);
7585
7606
  var suspenseCache = useSuspenseCache(options.suspenseCache);
7586
7607
  var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
7587
- var _a = watchQueryOptions.returnPartialData, returnPartialData = _a === void 0 ? false : _a, variables = watchQueryOptions.variables;
7588
- var _b = options.suspensePolicy, suspensePolicy = _b === void 0 ? 'always' : _b, _c = options.queryKey, queryKey = _c === void 0 ? [] : _c;
7589
- var shouldSuspend = suspensePolicy === 'always' || !didPreviouslySuspend.current;
7608
+ var variables = watchQueryOptions.variables;
7609
+ var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
7610
+ var _b = usePromiseVersion(), version = _b[0], setVersion = _b[1];
7590
7611
  var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
7591
7612
  var subscription = suspenseCache.getSubscription(cacheKey, function () {
7592
7613
  return client.watchQuery(watchQueryOptions);
7593
7614
  });
7594
- var dispose = useTrackedSubscriptions(subscription);
7595
- useStrictModeSafeCleanupEffect(dispose);
7596
- var result = useSyncExternalStore(subscription.listen, function () { return subscription.result; }, function () { return subscription.result; });
7597
- var previousVariables = React.useRef(variables);
7598
- var previousData = React.useRef(result.data);
7599
- if (!equal.equal(variables, previousVariables.current)) {
7600
- if (result.networkStatus !== exports.NetworkStatus.ready) {
7601
- result = tslib.__assign(tslib.__assign({}, result), { data: previousData.current, networkStatus: exports.NetworkStatus.setVariables });
7602
- }
7603
- previousVariables.current = variables;
7604
- previousData.current = result.data;
7605
- }
7606
- if (result.networkStatus === exports.NetworkStatus.error ||
7607
- (shouldSuspend &&
7608
- !shouldUseCachedResult(subscription.result, {
7609
- returnPartialData: returnPartialData,
7610
- fetchPolicy: options.fetchPolicy,
7611
- }))) {
7612
- __use(subscription.promise);
7613
- }
7614
- didPreviouslySuspend.current = true;
7615
- var fetchMore = React.useCallback(function (options) { return subscription.fetchMore(options); }, [subscription]);
7616
- var refetch = React.useCallback(function (variables) { return subscription.refetch(variables); }, [subscription]);
7615
+ useTrackedSubscriptions(subscription);
7616
+ React.useEffect(function () {
7617
+ return subscription.listen(function () {
7618
+ setVersion('main');
7619
+ });
7620
+ }, [subscription]);
7621
+ var promise = subscription.promises[version] || subscription.promises.main;
7622
+ var result = __use(promise);
7623
+ var fetchMore = React.useCallback(function (options) {
7624
+ var promise = subscription.fetchMore(options);
7625
+ setVersion('network');
7626
+ return promise;
7627
+ }, [subscription]);
7628
+ var refetch = React.useCallback(function (variables) {
7629
+ var promise = subscription.refetch(variables);
7630
+ setVersion('network');
7631
+ return promise;
7632
+ }, [subscription]);
7617
7633
  var subscribeToMore = React.useCallback(function (options) { return subscription.observable.subscribeToMore(options); }, [subscription]);
7618
7634
  return React.useMemo(function () {
7619
7635
  return {
@@ -7641,7 +7657,7 @@ function validateFetchPolicy(fetchPolicy) {
7641
7657
  'no-cache',
7642
7658
  'cache-and-network',
7643
7659
  ];
7644
- __DEV__ ? tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), 35);
7660
+ __DEV__ ? tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), 34);
7645
7661
  }
7646
7662
  function validatePartialDataReturn(fetchPolicy, returnPartialData) {
7647
7663
  if (fetchPolicy === 'no-cache' && returnPartialData) {
@@ -7656,73 +7672,62 @@ function toApolloError(result) {
7656
7672
  function useTrackedSubscriptions(subscription) {
7657
7673
  var trackedSubscriptions = React.useRef(new Set());
7658
7674
  trackedSubscriptions.current.add(subscription);
7659
- return function dispose() {
7675
+ useStrictModeSafeCleanupEffect(function () {
7660
7676
  trackedSubscriptions.current.forEach(function (sub) { return sub.dispose(); });
7661
- };
7677
+ });
7678
+ }
7679
+ function usePromiseVersion() {
7680
+ var _a = React.useState({
7681
+ version: 'main',
7682
+ }), version = _a[0].version, setState = _a[1];
7683
+ var setVersion = React.useCallback(function (version) { return setState({ version: version }); }, []);
7684
+ return [version, setVersion];
7662
7685
  }
7663
7686
  function useWatchQueryOptions(_a) {
7664
7687
  var query = _a.query, options = _a.options;
7665
- var watchQueryOptions = useDeepMemo(function () { return (tslib.__assign(tslib.__assign({}, options), { query: query, notifyOnNetworkStatusChange: true, nextFetchPolicy: void 0 })); }, [options, query]);
7688
+ var watchQueryOptions = useDeepMemo(function () { return (tslib.__assign(tslib.__assign({}, options), { query: query, notifyOnNetworkStatusChange: false, nextFetchPolicy: void 0 })); }, [options, query]);
7666
7689
  if (__DEV__) {
7667
7690
  validateOptions(watchQueryOptions);
7668
7691
  }
7669
7692
  return watchQueryOptions;
7670
7693
  }
7671
- function shouldUseCachedResult(result, _a) {
7672
- var returnPartialData = _a.returnPartialData, fetchPolicy = _a.fetchPolicy;
7673
- if (result.networkStatus === exports.NetworkStatus.refetch ||
7674
- result.networkStatus === exports.NetworkStatus.fetchMore ||
7675
- result.networkStatus === exports.NetworkStatus.error) {
7676
- return false;
7677
- }
7678
- switch (fetchPolicy) {
7679
- case void 0:
7680
- case 'cache-first':
7681
- case 'cache-and-network': {
7682
- return Boolean(result.data && (!result.partial || returnPartialData));
7683
- }
7684
- default:
7685
- return false;
7686
- }
7687
- }
7688
7694
 
7689
- function wrapWithCustomPromise(concast) {
7690
- return new Promise(function (resolve, reject) {
7691
- var subscription = concast.subscribe({
7692
- next: function (value) {
7693
- resolve(value);
7694
- subscription.unsubscribe();
7695
- },
7696
- error: reject,
7697
- });
7698
- });
7699
- }
7700
- var isMultipartQuery = optimism.wrap(function (query) {
7701
- return hasAnyDirectives(['defer', 'stream'], query);
7702
- });
7703
7695
  var QuerySubscription = (function () {
7704
7696
  function QuerySubscription(observable, options) {
7705
7697
  if (options === void 0) { options = Object.create(null); }
7698
+ var _this = this;
7706
7699
  var _a;
7707
7700
  this.listeners = new Set();
7701
+ this.initialized = false;
7702
+ this.refetching = false;
7708
7703
  this.listen = this.listen.bind(this);
7709
7704
  this.handleNext = this.handleNext.bind(this);
7710
7705
  this.handleError = this.handleError.bind(this);
7711
7706
  this.dispose = this.dispose.bind(this);
7712
7707
  this.observable = observable;
7713
- this.result = observable.getCurrentResult();
7708
+ this.result = observable.getCurrentResult(false);
7714
7709
  if (options.onDispose) {
7715
7710
  this.onDispose = options.onDispose;
7716
7711
  }
7712
+ if (isNetworkRequestSettled(this.result.networkStatus) ||
7713
+ (this.result.data &&
7714
+ (!this.result.partial || this.observable.options.returnPartialData))) {
7715
+ this.promises = { main: createFulfilledPromise(this.result) };
7716
+ this.initialized = true;
7717
+ this.refetching = false;
7718
+ }
7717
7719
  this.subscription = observable.subscribe({
7718
7720
  next: this.handleNext,
7719
7721
  error: this.handleError,
7720
7722
  });
7721
- __DEV__ ? tsInvariant.invariant(observable['concast'], 'Unexpected error: A concast was not found on the observable.') : tsInvariant.invariant(observable['concast'], 28);
7722
- var concast = observable['concast'];
7723
- this.promise = isMultipartQuery(observable.query)
7724
- ? wrapWithCustomPromise(concast)
7725
- : concast.promise;
7723
+ if (!this.promises) {
7724
+ this.promises = {
7725
+ main: new Promise(function (resolve, reject) {
7726
+ _this.resolve = resolve;
7727
+ _this.reject = reject;
7728
+ }),
7729
+ };
7730
+ }
7726
7731
  this.autoDisposeTimeoutId = setTimeout(this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
7727
7732
  }
7728
7733
  QuerySubscription.prototype.listen = function (listener) {
@@ -7734,12 +7739,15 @@ var QuerySubscription = (function () {
7734
7739
  };
7735
7740
  };
7736
7741
  QuerySubscription.prototype.refetch = function (variables) {
7737
- this.promise = this.observable.refetch(variables);
7738
- return this.promise;
7742
+ this.refetching = true;
7743
+ var promise = this.observable.refetch(variables);
7744
+ this.promises.network = promise;
7745
+ return promise;
7739
7746
  };
7740
7747
  QuerySubscription.prototype.fetchMore = function (options) {
7741
- this.promise = this.observable.fetchMore(options);
7742
- return this.promise;
7748
+ var promise = this.observable.fetchMore(options);
7749
+ this.promises.network = promise;
7750
+ return promise;
7743
7751
  };
7744
7752
  QuerySubscription.prototype.dispose = function () {
7745
7753
  this.subscription.unsubscribe();
@@ -7748,21 +7756,39 @@ var QuerySubscription = (function () {
7748
7756
  QuerySubscription.prototype.onDispose = function () {
7749
7757
  };
7750
7758
  QuerySubscription.prototype.handleNext = function (result) {
7751
- if (isNetworkRequestSettled(result.networkStatus) &&
7752
- this.result.data &&
7753
- result.data === void 0) {
7759
+ if (!this.initialized) {
7760
+ this.initialized = true;
7761
+ this.result = result;
7762
+ this.resolve(result);
7763
+ return;
7764
+ }
7765
+ if (result.data === this.result.data) {
7766
+ return;
7767
+ }
7768
+ if (this.result.data && result.data === void 0) {
7754
7769
  result.data = this.result.data;
7755
7770
  }
7756
7771
  this.result = result;
7757
- this.deliver(result);
7772
+ this.promises.main = createFulfilledPromise(result);
7773
+ this.deliver();
7758
7774
  };
7759
7775
  QuerySubscription.prototype.handleError = function (error) {
7760
7776
  var result = tslib.__assign(tslib.__assign({}, this.result), { error: error, networkStatus: exports.NetworkStatus.error });
7761
7777
  this.result = result;
7762
- this.deliver(result);
7778
+ if (!this.initialized || this.refetching) {
7779
+ this.initialized = true;
7780
+ this.refetching = false;
7781
+ this.reject(error);
7782
+ return;
7783
+ }
7784
+ this.result = result;
7785
+ this.promises.main = result.data
7786
+ ? createFulfilledPromise(result)
7787
+ : createRejectedPromise(result);
7788
+ this.deliver();
7763
7789
  };
7764
- QuerySubscription.prototype.deliver = function (result) {
7765
- this.listeners.forEach(function (listener) { return listener(result); });
7790
+ QuerySubscription.prototype.deliver = function () {
7791
+ this.listeners.forEach(function (listener) { return listener(); });
7766
7792
  };
7767
7793
  return QuerySubscription;
7768
7794
  }());