@apollo/client 3.7.1 → 3.8.0-alpha.0

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 (128) hide show
  1. package/README.md +5 -5
  2. package/apollo-client.cjs +252 -32
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/core/types/common.d.ts +3 -2
  6. package/cache/core/types/common.d.ts.map +1 -1
  7. package/cache/core/types/common.js.map +1 -1
  8. package/cache/index.d.ts +1 -1
  9. package/cache/index.d.ts.map +1 -1
  10. package/cache/index.js.map +1 -1
  11. package/config/jest/setup.d.ts +1 -1
  12. package/config/jest/setup.d.ts.map +1 -1
  13. package/config/jest/setup.js +1 -0
  14. package/config/jest/setup.js.map +1 -1
  15. package/core/ApolloClient.js +1 -1
  16. package/core/ApolloClient.js.map +1 -1
  17. package/core/ObservableQuery.d.ts.map +1 -1
  18. package/core/ObservableQuery.js +3 -2
  19. package/core/ObservableQuery.js.map +1 -1
  20. package/core/QueryInfo.d.ts.map +1 -1
  21. package/core/QueryInfo.js +6 -2
  22. package/core/QueryInfo.js.map +1 -1
  23. package/core/QueryManager.d.ts.map +1 -1
  24. package/core/QueryManager.js +1 -2
  25. package/core/QueryManager.js.map +1 -1
  26. package/core/core.cjs +11 -7
  27. package/core/core.cjs.map +1 -1
  28. package/core/core.cjs.native.js +11 -7
  29. package/core/watchQueryOptions.d.ts +1 -0
  30. package/core/watchQueryOptions.d.ts.map +1 -1
  31. package/core/watchQueryOptions.js.map +1 -1
  32. package/errors/errors.cjs +1 -0
  33. package/errors/errors.cjs.map +1 -1
  34. package/errors/errors.cjs.native.js +1 -0
  35. package/errors/index.d.ts +1 -0
  36. package/errors/index.d.ts.map +1 -1
  37. package/errors/index.js +1 -0
  38. package/errors/index.js.map +1 -1
  39. package/invariantErrorCodes.js +35 -23
  40. package/package.json +28 -14
  41. package/react/cache/SuspenseCache.d.ts +18 -0
  42. package/react/cache/SuspenseCache.d.ts.map +1 -0
  43. package/react/cache/SuspenseCache.js +49 -0
  44. package/react/cache/SuspenseCache.js.map +1 -0
  45. package/react/cache/index.d.ts +2 -0
  46. package/react/cache/index.d.ts.map +1 -0
  47. package/react/cache/index.js +2 -0
  48. package/react/cache/index.js.map +1 -0
  49. package/react/context/ApolloContext.d.ts +2 -0
  50. package/react/context/ApolloContext.d.ts.map +1 -1
  51. package/react/context/ApolloContext.js.map +1 -1
  52. package/react/context/ApolloProvider.d.ts +2 -0
  53. package/react/context/ApolloProvider.d.ts.map +1 -1
  54. package/react/context/ApolloProvider.js +4 -1
  55. package/react/context/ApolloProvider.js.map +1 -1
  56. package/react/context/context.cjs +4 -1
  57. package/react/context/context.cjs.map +1 -1
  58. package/react/context/context.cjs.native.js +4 -1
  59. package/react/hooks/compareResults.d.ts +3 -0
  60. package/react/hooks/compareResults.d.ts.map +1 -0
  61. package/react/hooks/compareResults.js +63 -0
  62. package/react/hooks/compareResults.js.map +1 -0
  63. package/react/hooks/hooks.cjs +167 -3
  64. package/react/hooks/hooks.cjs.map +1 -1
  65. package/react/hooks/hooks.cjs.native.js +167 -3
  66. package/react/hooks/index.d.ts +1 -0
  67. package/react/hooks/index.d.ts.map +1 -1
  68. package/react/hooks/index.js +1 -0
  69. package/react/hooks/index.js.map +1 -1
  70. package/react/hooks/internal/index.d.ts +2 -0
  71. package/react/hooks/internal/index.d.ts.map +1 -0
  72. package/react/hooks/internal/index.js +2 -0
  73. package/react/hooks/internal/index.js.map +1 -0
  74. package/react/hooks/internal/useDeepMemo.d.ts +3 -0
  75. package/react/hooks/internal/useDeepMemo.d.ts.map +1 -0
  76. package/react/hooks/internal/useDeepMemo.js +10 -0
  77. package/react/hooks/internal/useDeepMemo.js.map +1 -0
  78. package/react/hooks/useMutation.d.ts +1 -1
  79. package/react/hooks/useMutation.d.ts.map +1 -1
  80. package/react/hooks/useMutation.js.map +1 -1
  81. package/react/hooks/useQuery.d.ts.map +1 -1
  82. package/react/hooks/useQuery.js +5 -3
  83. package/react/hooks/useQuery.js.map +1 -1
  84. package/react/hooks/useSuspenseCache.d.ts +2 -0
  85. package/react/hooks/useSuspenseCache.d.ts.map +1 -0
  86. package/react/hooks/useSuspenseCache.js +10 -0
  87. package/react/hooks/useSuspenseCache.js.map +1 -0
  88. package/react/hooks/useSuspenseQuery.d.ts +10 -0
  89. package/react/hooks/useSuspenseQuery.d.ts.map +1 -0
  90. package/react/hooks/useSuspenseQuery.js +157 -0
  91. package/react/hooks/useSuspenseQuery.js.map +1 -0
  92. package/react/index.d.ts +1 -0
  93. package/react/index.d.ts.map +1 -1
  94. package/react/index.js +1 -0
  95. package/react/index.js.map +1 -1
  96. package/react/parser/index.js +5 -5
  97. package/react/parser/parser.cjs +5 -5
  98. package/react/parser/parser.cjs.map +1 -1
  99. package/react/parser/parser.cjs.native.js +5 -5
  100. package/react/react.cjs +49 -2
  101. package/react/react.cjs.map +1 -1
  102. package/react/react.cjs.native.js +49 -2
  103. package/react/types/types.d.ts +9 -1
  104. package/react/types/types.d.ts.map +1 -1
  105. package/react/types/types.js.map +1 -1
  106. package/testing/core/core.cjs +1 -1
  107. package/testing/core/core.cjs.map +1 -1
  108. package/testing/core/core.cjs.native.js +1 -1
  109. package/testing/core/mocking/mockLink.js +1 -1
  110. package/testing/react/MockedProvider.d.ts +3 -0
  111. package/testing/react/MockedProvider.d.ts.map +1 -1
  112. package/testing/react/MockedProvider.js +8 -3
  113. package/testing/react/MockedProvider.js.map +1 -1
  114. package/testing/testing.cjs +54 -3
  115. package/testing/testing.cjs.map +1 -1
  116. package/testing/testing.cjs.native.js +54 -3
  117. package/utilities/globals/globals.cjs +1 -1
  118. package/utilities/globals/globals.cjs.map +1 -1
  119. package/utilities/globals/globals.cjs.native.js +1 -1
  120. package/utilities/globals/index.js +1 -1
  121. package/utilities/graphql/directives.js +4 -4
  122. package/utilities/graphql/fragments.js +3 -3
  123. package/utilities/graphql/getFromAST.js +8 -8
  124. package/utilities/graphql/storeUtils.js +1 -1
  125. package/utilities/utilities.cjs +16 -16
  126. package/utilities/utilities.cjs.map +1 -1
  127. package/utilities/utilities.cjs.native.js +16 -16
  128. package/version.js +1 -1
package/README.md CHANGED
@@ -19,7 +19,7 @@ The Apollo Client API reference can be found at: <br/>
19
19
  Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apollo's official learning platform: <br/>
20
20
  [https://odyssey.apollographql.com/](https://odyssey.apollographql.com/)
21
21
 
22
- ## Apollo Maintainers
22
+ ## Maintainers
23
23
 
24
24
  - [@benjamn](https://github.com/benjamn)
25
25
  - [@alessbell](https://github.com/alessbell)
@@ -33,10 +33,10 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
33
33
 
34
34
  [Apollo](https://apollographql.com/) builds open-source software and a graph platform to unify GraphQL across your apps and services. We help you ship faster with:
35
35
 
36
- * [Apollo Studio](https://www.apollographql.com/studio/develop/) – A free, end-to-end platform for managing your GraphQL lifecycle. Track your GraphQL schemas in a hosted registry to create a source of truth for everything in your graph. Studio provides an IDE (Apollo Explorer) so you can explore data, collaborate on queries, observe usage, and safely make schema changes.
37
- * [Apollo Federation](https://www.apollographql.com/apollo-federation) – The industry-standard open architecture for building a distributed graph. Use Apollo’s gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
38
- * [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Android](https://github.com/apollographql/apollo-android).
39
- * [Apollo Server](https://www.apollographql.com/docs/apollo-server/) – A production-ready JavaScript GraphQL server that connects to any microservice, API, or database. Compatible with all popular JavaScript frameworks and deployable in serverless environments.
36
+ - [Apollo Studio](https://www.apollographql.com/studio/develop/) – A free, end-to-end platform for managing your GraphQL lifecycle. Track your GraphQL schemas in a hosted registry to create a source of truth for everything in your graph. Studio provides an IDE (Apollo Explorer) so you can explore data, collaborate on queries, observe usage, and safely make schema changes.
37
+ - [Apollo Federation](https://www.apollographql.com/apollo-federation) – The industry-standard open architecture for building a distributed graph. Use Apollo’s gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
38
+ - [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Android](https://github.com/apollographql/apollo-android).
39
+ - [Apollo Server](https://www.apollographql.com/docs/apollo-server/) – A production-ready JavaScript GraphQL server that connects to any microservice, API, or database. Compatible with all popular JavaScript frameworks and deployable in serverless environments.
40
40
 
41
41
  ## Learn how to build with Apollo
42
42
 
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);
@@ -1300,7 +1300,7 @@ var concat = ApolloLink.concat;
1300
1300
 
1301
1301
  var execute = ApolloLink.execute;
1302
1302
 
1303
- var version = '3.7.1';
1303
+ var version = '3.8.0-alpha.0';
1304
1304
 
1305
1305
  function isNodeResponse(value) {
1306
1306
  return !!value.body;
@@ -4201,6 +4201,7 @@ var ApolloError = (function (_super) {
4201
4201
  function ApolloError(_a) {
4202
4202
  var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
4203
4203
  var _this = _super.call(this, errorMessage) || this;
4204
+ _this.name = 'ApolloError';
4204
4205
  _this.graphQLErrors = graphQLErrors || [];
4205
4206
  _this.clientErrors = clientErrors || [];
4206
4207
  _this.networkError = networkError || null;
@@ -4232,13 +4233,14 @@ var ObservableQuery = (function (_super) {
4232
4233
  function ObservableQuery(_a) {
4233
4234
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
4234
4235
  var _this = _super.call(this, function (observer) {
4236
+ var _a = options.fetchOnFirstSubscribe, fetchOnFirstSubscribe = _a === void 0 ? true : _a;
4235
4237
  try {
4236
4238
  var subObserver = observer._subscription._observer;
4237
4239
  if (subObserver && !subObserver.error) {
4238
4240
  subObserver.error = defaultSubscriptionObserverErrorCallback;
4239
4241
  }
4240
4242
  }
4241
- catch (_a) { }
4243
+ catch (_b) { }
4242
4244
  var first = !_this.observers.size;
4243
4245
  _this.observers.add(observer);
4244
4246
  var last = _this.last;
@@ -4248,7 +4250,7 @@ var ObservableQuery = (function (_super) {
4248
4250
  else if (last && last.result) {
4249
4251
  observer.next && observer.next(last.result);
4250
4252
  }
4251
- if (first) {
4253
+ if (first && fetchOnFirstSubscribe) {
4252
4254
  _this.reobserve().catch(function () { });
4253
4255
  }
4254
4256
  return function () {
@@ -5174,13 +5176,13 @@ var QueryInfo = (function () {
5174
5176
  };
5175
5177
  QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
5176
5178
  var _this = this;
5179
+ var merger = new DeepMerger();
5177
5180
  var graphQLErrors = isNonEmptyArray(result.errors)
5178
5181
  ? result.errors.slice(0)
5179
5182
  : [];
5180
5183
  this.reset();
5181
5184
  if ('incremental' in result && isNonEmptyArray(result.incremental)) {
5182
5185
  var mergedData_1 = this.getDiff().result;
5183
- var merger_1 = new DeepMerger();
5184
5186
  result.incremental.forEach(function (_a) {
5185
5187
  var data = _a.data, path = _a.path, errors = _a.errors;
5186
5188
  for (var i = path.length - 1; i >= 0; --i) {
@@ -5193,10 +5195,14 @@ var QueryInfo = (function () {
5193
5195
  if (errors) {
5194
5196
  graphQLErrors.push.apply(graphQLErrors, errors);
5195
5197
  }
5196
- mergedData_1 = merger_1.merge(mergedData_1, data);
5198
+ mergedData_1 = merger.merge(mergedData_1, data);
5197
5199
  });
5198
5200
  result.data = mergedData_1;
5199
5201
  }
5202
+ else if ('hasNext' in result && result.hasNext) {
5203
+ var diff = this.getDiff();
5204
+ result.data = merger.merge(diff.result, result.data);
5205
+ }
5200
5206
  this.graphQLErrors = graphQLErrors;
5201
5207
  if (options.fetchPolicy === 'no-cache') {
5202
5208
  this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
@@ -5850,7 +5856,6 @@ var QueryManager = (function () {
5850
5856
  };
5851
5857
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
5852
5858
  var requestId = queryInfo.lastRequestId = this.generateRequestId();
5853
- options = cloneDeep(options);
5854
5859
  var linkDocument = this.cache.transformForLink(this.transform(queryInfo.document).document);
5855
5860
  return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
5856
5861
  var graphQLErrors = isNonEmptyArray(result.errors)
@@ -6149,7 +6154,7 @@ var ApolloClient = (function () {
6149
6154
  if (connectToDevTools && typeof window === 'object') {
6150
6155
  window.__APOLLO_CLIENT__ = this;
6151
6156
  }
6152
- if (!hasSuggestedDevtools && __DEV__) {
6157
+ if (!hasSuggestedDevtools && connectToDevTools && __DEV__) {
6153
6158
  hasSuggestedDevtools = true;
6154
6159
  if (typeof window !== 'undefined' &&
6155
6160
  window.document &&
@@ -6369,13 +6374,16 @@ var ApolloConsumer = function (props) {
6369
6374
  };
6370
6375
 
6371
6376
  var ApolloProvider = function (_a) {
6372
- var client = _a.client, children = _a.children;
6377
+ var client = _a.client, suspenseCache = _a.suspenseCache, children = _a.children;
6373
6378
  var ApolloContext = getApolloContext();
6374
6379
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6375
6380
  if (context === void 0) { context = {}; }
6376
6381
  if (client && context.client !== client) {
6377
6382
  context = Object.assign({}, context, { client: client });
6378
6383
  }
6384
+ if (suspenseCache) {
6385
+ context = Object.assign({}, context, { suspenseCache: suspenseCache });
6386
+ }
6379
6387
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
6380
6388
  'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 28);
6381
6389
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
@@ -6465,7 +6473,7 @@ function parser(document) {
6465
6473
  var variables, type, name;
6466
6474
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6467
6475
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6468
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 32);
6476
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 34);
6469
6477
  var fragments = [];
6470
6478
  var queries = [];
6471
6479
  var mutations = [];
@@ -6493,11 +6501,11 @@ function parser(document) {
6493
6501
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6494
6502
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6495
6503
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6496
- (queries.length || mutations.length || subscriptions.length), 33);
6504
+ (queries.length || mutations.length || subscriptions.length), 35);
6497
6505
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6498
6506
  "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6499
6507
  "subscriptions and ".concat(mutations.length, " mutations. ") +
6500
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 34);
6508
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 36);
6501
6509
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6502
6510
  if (!queries.length && !mutations.length)
6503
6511
  type = exports.DocumentType.Subscription;
@@ -6508,7 +6516,7 @@ function parser(document) {
6508
6516
  : subscriptions;
6509
6517
  __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6510
6518
  "".concat(definitions.length, " definitions. ") +
6511
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 35);
6519
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 37);
6512
6520
  var definition = definitions[0];
6513
6521
  variables = definition.variableDefinitions || [];
6514
6522
  if (definition.name && definition.name.kind === 'Name') {
@@ -6526,7 +6534,7 @@ function verifyDocumentType(document, type) {
6526
6534
  var requiredOperationName = operationName(type);
6527
6535
  var usedOperationName = operationName(operation.type);
6528
6536
  __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6529
- "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 36);
6537
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 38);
6530
6538
  }
6531
6539
 
6532
6540
  var hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -6753,16 +6761,18 @@ var InternalState = (function () {
6753
6761
  }
6754
6762
  this.result = nextResult;
6755
6763
  this.forceUpdate();
6756
- this.handleErrorOrCompleted(nextResult);
6764
+ this.handleErrorOrCompleted(nextResult, previousResult);
6757
6765
  };
6758
- InternalState.prototype.handleErrorOrCompleted = function (result) {
6766
+ InternalState.prototype.handleErrorOrCompleted = function (result, previousResult) {
6759
6767
  var _this = this;
6760
6768
  if (!result.loading) {
6761
6769
  Promise.resolve().then(function () {
6762
6770
  if (result.error) {
6763
6771
  _this.onError(result.error);
6764
6772
  }
6765
- else if (result.data) {
6773
+ else if (result.data &&
6774
+ (previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus) !== result.networkStatus &&
6775
+ result.networkStatus === exports.NetworkStatus.ready) {
6766
6776
  _this.onCompleted(result.data);
6767
6777
  }
6768
6778
  }).catch(function (error) {
@@ -7131,6 +7141,214 @@ function diffToResult(diff) {
7131
7141
  return result;
7132
7142
  }
7133
7143
 
7144
+ function useDeepMemo(memoFn, deps) {
7145
+ var ref = React.useRef();
7146
+ if (!ref.current || !equality.equal(ref.current.deps, deps)) {
7147
+ ref.current = { value: memoFn(), deps: deps };
7148
+ }
7149
+ return ref.current.value;
7150
+ }
7151
+
7152
+ function useSuspenseCache() {
7153
+ var suspenseCache = React.useContext(getApolloContext()).suspenseCache;
7154
+ __DEV__ ? tsInvariant.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context. Wrap the root component ' +
7155
+ 'in an <ApolloProvider> and provide a suspenseCache.') : tsInvariant.invariant(suspenseCache, 32);
7156
+ return suspenseCache;
7157
+ }
7158
+
7159
+ var SUPPORTED_FETCH_POLICIES = [
7160
+ 'cache-first',
7161
+ 'network-only',
7162
+ 'no-cache',
7163
+ 'cache-and-network',
7164
+ ];
7165
+ var DEFAULT_FETCH_POLICY = 'cache-first';
7166
+ var DEFAULT_SUSPENSE_POLICY = 'always';
7167
+ var DEFAULT_ERROR_POLICY = 'none';
7168
+ function useSuspenseQuery_experimental(query, options) {
7169
+ if (options === void 0) { options = Object.create(null); }
7170
+ var suspenseCache = useSuspenseCache();
7171
+ var client = useApolloClient(options.client);
7172
+ var watchQueryOptions = useWatchQueryOptions({ query: query, options: options, client: client });
7173
+ var previousWatchQueryOptionsRef = React.useRef(watchQueryOptions);
7174
+ var fetchPolicy = watchQueryOptions.fetchPolicy, errorPolicy = watchQueryOptions.errorPolicy, returnPartialData = watchQueryOptions.returnPartialData, variables = watchQueryOptions.variables;
7175
+ var cacheEntry = suspenseCache.lookup(query, variables);
7176
+ var observable = React.useState(function () {
7177
+ return (cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.observable) || client.watchQuery(watchQueryOptions);
7178
+ })[0];
7179
+ var result = useObservableQueryResult(observable);
7180
+ if (result.error && errorPolicy === 'none') {
7181
+ throw result.error;
7182
+ }
7183
+ if (result.loading) {
7184
+ if (!cacheEntry) {
7185
+ cacheEntry = suspenseCache.add(query, variables, {
7186
+ promise: observable.reobserve(watchQueryOptions),
7187
+ observable: observable,
7188
+ });
7189
+ }
7190
+ var hasFullResult = result.data && !result.partial;
7191
+ var usePartialResult = returnPartialData && result.partial && result.data;
7192
+ var hasUsableResult = usePartialResult ||
7193
+ (fetchPolicy === 'cache-and-network' && hasFullResult);
7194
+ if (!hasUsableResult && !cacheEntry.fulfilled) {
7195
+ throw cacheEntry.promise;
7196
+ }
7197
+ }
7198
+ React.useEffect(function () {
7199
+ var variables = watchQueryOptions.variables, query = watchQueryOptions.query;
7200
+ var previousOpts = previousWatchQueryOptionsRef.current;
7201
+ if (variables !== previousOpts.variables || query !== previousOpts.query) {
7202
+ suspenseCache.remove(previousOpts.query, previousOpts.variables);
7203
+ suspenseCache.add(query, variables, {
7204
+ promise: observable.reobserve({ query: query, variables: variables }),
7205
+ observable: observable,
7206
+ });
7207
+ previousWatchQueryOptionsRef.current = watchQueryOptions;
7208
+ }
7209
+ }, [watchQueryOptions]);
7210
+ React.useEffect(function () {
7211
+ return function () {
7212
+ suspenseCache.remove(query, variables);
7213
+ };
7214
+ }, []);
7215
+ return React.useMemo(function () {
7216
+ return {
7217
+ data: result.data,
7218
+ error: errorPolicy === 'all' ? toApolloError(result) : void 0,
7219
+ fetchMore: function (options) {
7220
+ var promise = observable.fetchMore(options);
7221
+ suspenseCache.add(query, watchQueryOptions.variables, {
7222
+ promise: promise,
7223
+ observable: observable,
7224
+ });
7225
+ return promise;
7226
+ },
7227
+ refetch: function (variables) {
7228
+ var promise = observable.refetch(variables);
7229
+ suspenseCache.add(query, watchQueryOptions.variables, {
7230
+ promise: promise,
7231
+ observable: observable,
7232
+ });
7233
+ return promise;
7234
+ },
7235
+ };
7236
+ }, [result, observable, errorPolicy]);
7237
+ }
7238
+ function validateOptions(options) {
7239
+ var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
7240
+ verifyDocumentType(query, exports.DocumentType.Query);
7241
+ validateFetchPolicy(fetchPolicy);
7242
+ validatePartialDataReturn(fetchPolicy, returnPartialData);
7243
+ }
7244
+ function validateFetchPolicy(fetchPolicy) {
7245
+ __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);
7246
+ }
7247
+ function validatePartialDataReturn(fetchPolicy, returnPartialData) {
7248
+ if (fetchPolicy === 'no-cache' && returnPartialData) {
7249
+ __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.');
7250
+ }
7251
+ }
7252
+ function toApolloError(result) {
7253
+ return isNonEmptyArray(result.errors)
7254
+ ? new ApolloError({ graphQLErrors: result.errors })
7255
+ : result.error;
7256
+ }
7257
+ function useWatchQueryOptions(_a) {
7258
+ var query = _a.query, options = _a.options, client = _a.client;
7259
+ var defaultOptions = client.defaultOptions.watchQuery;
7260
+ var watchQueryOptions = useDeepMemo(function () {
7261
+ 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"]);
7262
+ 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)) });
7263
+ }, [options, query, defaultOptions]);
7264
+ if (__DEV__) {
7265
+ validateOptions(watchQueryOptions);
7266
+ }
7267
+ return watchQueryOptions;
7268
+ }
7269
+ function useObservableQueryResult(observable) {
7270
+ var resultRef = React.useRef();
7271
+ var isMountedRef = React.useRef(false);
7272
+ if (!resultRef.current) {
7273
+ resultRef.current = observable.getCurrentResult();
7274
+ }
7275
+ React.useLayoutEffect(function () {
7276
+ isMountedRef.current = true;
7277
+ return function () {
7278
+ isMountedRef.current = false;
7279
+ };
7280
+ }, []);
7281
+ return useSyncExternalStore(React.useCallback(function (forceUpdate) {
7282
+ function handleUpdate() {
7283
+ var previousResult = resultRef.current;
7284
+ var result = observable.getCurrentResult();
7285
+ if (previousResult.loading === result.loading &&
7286
+ previousResult.networkStatus === result.networkStatus &&
7287
+ equality.equal(previousResult.data, result.data)) {
7288
+ return;
7289
+ }
7290
+ resultRef.current = result;
7291
+ if (isMountedRef.current) {
7292
+ forceUpdate();
7293
+ }
7294
+ }
7295
+ var subscription = observable.subscribe({
7296
+ next: handleUpdate,
7297
+ error: handleUpdate,
7298
+ });
7299
+ return function () {
7300
+ subscription.unsubscribe();
7301
+ };
7302
+ }, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
7303
+ }
7304
+
7305
+ var SuspenseCache = (function () {
7306
+ function SuspenseCache() {
7307
+ this.queries = new Map();
7308
+ }
7309
+ SuspenseCache.prototype.add = function (query, variables, _a) {
7310
+ var promise = _a.promise, observable = _a.observable;
7311
+ var variablesKey = this.getVariablesKey(variables);
7312
+ var map = this.queries.get(query) || new Map();
7313
+ var entry = {
7314
+ observable: observable,
7315
+ fulfilled: false,
7316
+ promise: promise
7317
+ .catch(function () {
7318
+ })
7319
+ .finally(function () {
7320
+ entry.fulfilled = true;
7321
+ }),
7322
+ };
7323
+ map.set(variablesKey, entry);
7324
+ this.queries.set(query, map);
7325
+ return entry;
7326
+ };
7327
+ SuspenseCache.prototype.lookup = function (query, variables) {
7328
+ var _a;
7329
+ return (_a = this.queries
7330
+ .get(query)) === null || _a === void 0 ? void 0 : _a.get(this.getVariablesKey(variables));
7331
+ };
7332
+ SuspenseCache.prototype.remove = function (query, variables) {
7333
+ var map = this.queries.get(query);
7334
+ if (!map) {
7335
+ return;
7336
+ }
7337
+ var key = this.getVariablesKey(variables);
7338
+ var entry = map.get(key);
7339
+ if (entry && !entry.observable.hasObservers()) {
7340
+ map.delete(key);
7341
+ }
7342
+ if (map.size === 0) {
7343
+ this.queries.delete(query);
7344
+ }
7345
+ };
7346
+ SuspenseCache.prototype.getVariablesKey = function (variables) {
7347
+ return canonicalStringify(variables || Object.create(null));
7348
+ };
7349
+ return SuspenseCache;
7350
+ }());
7351
+
7134
7352
  exports.setLogVerbosity = tsInvariant.setVerbosity;
7135
7353
  exports.Observable = zenObservableTs.Observable;
7136
7354
  exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
@@ -7148,6 +7366,7 @@ exports.HttpLink = HttpLink;
7148
7366
  exports.InMemoryCache = InMemoryCache;
7149
7367
  exports.MissingFieldError = MissingFieldError;
7150
7368
  exports.ObservableQuery = ObservableQuery;
7369
+ exports.SuspenseCache = SuspenseCache;
7151
7370
  exports.checkFetcher = checkFetcher;
7152
7371
  exports.concat = concat;
7153
7372
  exports.createHttpLink = createHttpLink;
@@ -7185,4 +7404,5 @@ exports.useMutation = useMutation;
7185
7404
  exports.useQuery = useQuery;
7186
7405
  exports.useReactiveVar = useReactiveVar;
7187
7406
  exports.useSubscription = useSubscription;
7407
+ exports.useSuspenseQuery_experimental = useSuspenseQuery_experimental;
7188
7408
  //# sourceMappingURL=apollo-client.cjs.map