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

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 (221) hide show
  1. package/apollo-client.cjs +648 -464
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +2 -0
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +2 -0
  7. package/cache/core/cache.d.ts +1 -0
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js +1 -0
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/inmemory/inMemoryCache.d.ts +1 -0
  12. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  13. package/cache/inmemory/inMemoryCache.js +1 -0
  14. package/cache/inmemory/inMemoryCache.js.map +1 -1
  15. package/core/ApolloClient.d.ts.map +1 -1
  16. package/core/ApolloClient.js +6 -6
  17. package/core/ApolloClient.js.map +1 -1
  18. package/core/ObservableQuery.d.ts.map +1 -1
  19. package/core/ObservableQuery.js +27 -20
  20. package/core/ObservableQuery.js.map +1 -1
  21. package/core/QueryInfo.d.ts.map +1 -1
  22. package/core/QueryInfo.js.map +1 -1
  23. package/core/QueryManager.d.ts +2 -0
  24. package/core/QueryManager.d.ts.map +1 -1
  25. package/core/QueryManager.js +62 -50
  26. package/core/QueryManager.js.map +1 -1
  27. package/core/core.cjs +180 -91
  28. package/core/core.cjs.map +1 -1
  29. package/core/core.cjs.native.js +180 -91
  30. package/core/equalByQuery.d.ts +4 -0
  31. package/core/equalByQuery.d.ts.map +1 -0
  32. package/{react/hooks/compareResults.js → core/equalByQuery.js} +14 -10
  33. package/core/equalByQuery.js.map +1 -0
  34. package/core/index.d.ts +1 -1
  35. package/core/index.d.ts.map +1 -1
  36. package/core/index.js +1 -1
  37. package/core/index.js.map +1 -1
  38. package/core/networkStatus.d.ts +1 -0
  39. package/core/networkStatus.d.ts.map +1 -1
  40. package/core/networkStatus.js +3 -0
  41. package/core/networkStatus.js.map +1 -1
  42. package/core/types.d.ts +3 -0
  43. package/core/types.d.ts.map +1 -1
  44. package/core/types.js.map +1 -1
  45. package/core/watchQueryOptions.d.ts +0 -1
  46. package/core/watchQueryOptions.d.ts.map +1 -1
  47. package/core/watchQueryOptions.js.map +1 -1
  48. package/errors/errors.cjs +17 -17
  49. package/errors/errors.cjs.map +1 -1
  50. package/errors/errors.cjs.native.js +17 -17
  51. package/errors/index.d.ts +24 -8
  52. package/errors/index.d.ts.map +1 -1
  53. package/errors/index.js +17 -19
  54. package/errors/index.js.map +1 -1
  55. package/invariantErrorCodes.js +35 -30
  56. package/link/batch-http/batch-http.cjs +23 -2
  57. package/link/batch-http/batch-http.cjs.map +1 -1
  58. package/link/batch-http/batch-http.cjs.native.js +23 -2
  59. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  60. package/link/batch-http/batchHttpLink.js +7 -2
  61. package/link/batch-http/batchHttpLink.js.map +1 -1
  62. package/link/core/types.d.ts +4 -0
  63. package/link/core/types.d.ts.map +1 -1
  64. package/link/core/types.js.map +1 -1
  65. package/link/http/createHttpLink.d.ts.map +1 -1
  66. package/link/http/createHttpLink.js +21 -20
  67. package/link/http/createHttpLink.js.map +1 -1
  68. package/link/http/http.cjs +59 -30
  69. package/link/http/http.cjs.map +1 -1
  70. package/link/http/http.cjs.native.js +59 -30
  71. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  72. package/link/http/parseAndCheckHttpResponse.js +34 -14
  73. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  74. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  75. package/link/http/selectHttpOptionsAndBody.js +2 -1
  76. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  77. package/link/subscriptions/index.d.ts.map +1 -1
  78. package/link/subscriptions/index.js +10 -5
  79. package/link/subscriptions/index.js.map +1 -1
  80. package/link/subscriptions/subscriptions.cjs +9 -4
  81. package/link/subscriptions/subscriptions.cjs.map +1 -1
  82. package/link/subscriptions/subscriptions.cjs.native.js +9 -4
  83. package/link/utils/filterOperationVariables.d.ts +5 -0
  84. package/link/utils/filterOperationVariables.d.ts.map +1 -0
  85. package/link/utils/filterOperationVariables.js +18 -0
  86. package/link/utils/filterOperationVariables.js.map +1 -0
  87. package/link/utils/index.d.ts +1 -0
  88. package/link/utils/index.d.ts.map +1 -1
  89. package/link/utils/index.js +1 -0
  90. package/link/utils/index.js.map +1 -1
  91. package/link/utils/utils.cjs +18 -0
  92. package/link/utils/utils.cjs.map +1 -1
  93. package/link/utils/utils.cjs.native.js +18 -0
  94. package/package.json +18 -18
  95. package/react/cache/QuerySubscription.d.ts +26 -0
  96. package/react/cache/QuerySubscription.d.ts.map +1 -0
  97. package/react/cache/QuerySubscription.js +88 -0
  98. package/react/cache/QuerySubscription.js.map +1 -0
  99. package/react/cache/SuspenseCache.d.ts +10 -13
  100. package/react/cache/SuspenseCache.d.ts.map +1 -1
  101. package/react/cache/SuspenseCache.js +17 -41
  102. package/react/cache/SuspenseCache.js.map +1 -1
  103. package/react/context/ApolloConsumer.js +1 -1
  104. package/react/context/ApolloProvider.js +1 -1
  105. package/react/context/context.cjs +2 -2
  106. package/react/context/context.cjs.map +1 -1
  107. package/react/context/context.cjs.native.js +2 -2
  108. package/react/hoc/hoc-utils.js +1 -1
  109. package/react/hoc/hoc.cjs +2 -2
  110. package/react/hoc/hoc.cjs.map +1 -1
  111. package/react/hoc/hoc.cjs.native.js +2 -2
  112. package/react/hoc/withApollo.js +1 -1
  113. package/react/hooks/hooks.cjs +135 -202
  114. package/react/hooks/hooks.cjs.map +1 -1
  115. package/react/hooks/hooks.cjs.native.js +135 -202
  116. package/react/hooks/internal/__use.d.ts +4 -0
  117. package/react/hooks/internal/__use.d.ts.map +1 -0
  118. package/react/hooks/internal/__use.js +17 -0
  119. package/react/hooks/internal/__use.js.map +1 -0
  120. package/react/hooks/internal/index.d.ts +2 -0
  121. package/react/hooks/internal/index.d.ts.map +1 -1
  122. package/react/hooks/internal/index.js +2 -0
  123. package/react/hooks/internal/index.js.map +1 -1
  124. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -1
  125. package/react/hooks/internal/useIsomorphicLayoutEffect.js +2 -2
  126. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  127. package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts +2 -0
  128. package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts.map +1 -0
  129. package/react/hooks/internal/useStrictModeSafeCleanupEffect.js +11 -0
  130. package/react/hooks/internal/useStrictModeSafeCleanupEffect.js.map +1 -0
  131. package/react/hooks/useApolloClient.js +1 -1
  132. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  133. package/react/hooks/useLazyQuery.js +13 -22
  134. package/react/hooks/useLazyQuery.js.map +1 -1
  135. package/react/hooks/useQuery.d.ts +3 -3
  136. package/react/hooks/useQuery.d.ts.map +1 -1
  137. package/react/hooks/useQuery.js +26 -25
  138. package/react/hooks/useQuery.js.map +1 -1
  139. package/react/hooks/useSuspenseCache.js +1 -1
  140. package/react/hooks/useSuspenseQuery.d.ts +7 -2
  141. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  142. package/react/hooks/useSuspenseQuery.js +70 -153
  143. package/react/hooks/useSuspenseQuery.js.map +1 -1
  144. package/react/index.d.ts +1 -1
  145. package/react/index.d.ts.map +1 -1
  146. package/react/index.js +1 -1
  147. package/react/index.js.map +1 -1
  148. package/react/parser/index.js +5 -5
  149. package/react/parser/parser.cjs +5 -5
  150. package/react/parser/parser.cjs.map +1 -1
  151. package/react/parser/parser.cjs.native.js +5 -5
  152. package/react/react.cjs +98 -39
  153. package/react/react.cjs.map +1 -1
  154. package/react/react.cjs.native.js +98 -39
  155. package/react/types/types.d.ts +1 -2
  156. package/react/types/types.d.ts.map +1 -1
  157. package/react/types/types.js.map +1 -1
  158. package/testing/core/core.cjs +1 -1
  159. package/testing/core/core.cjs.map +1 -1
  160. package/testing/core/core.cjs.native.js +1 -1
  161. package/testing/core/mocking/mockLink.js +1 -1
  162. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  163. package/testing/react/MockedProvider.d.ts +1 -1
  164. package/testing/react/MockedProvider.d.ts.map +1 -1
  165. package/testing/react/MockedProvider.js +7 -6
  166. package/testing/react/MockedProvider.js.map +1 -1
  167. package/testing/testing.cjs +7 -51
  168. package/testing/testing.cjs.map +1 -1
  169. package/testing/testing.cjs.native.js +7 -51
  170. package/utilities/common/incrementalResult.d.ts +2 -1
  171. package/utilities/common/incrementalResult.d.ts.map +1 -1
  172. package/utilities/common/incrementalResult.js +4 -0
  173. package/utilities/common/incrementalResult.js.map +1 -1
  174. package/utilities/common/mergeOptions.d.ts +1 -1
  175. package/utilities/common/mergeOptions.d.ts.map +1 -1
  176. package/utilities/common/mergeOptions.js +1 -1
  177. package/utilities/common/mergeOptions.js.map +1 -1
  178. package/utilities/common/objects.d.ts +1 -0
  179. package/utilities/common/objects.d.ts.map +1 -1
  180. package/utilities/common/objects.js +6 -0
  181. package/utilities/common/objects.js.map +1 -1
  182. package/utilities/common/omitDeep.d.ts +3 -0
  183. package/utilities/common/omitDeep.d.ts.map +1 -0
  184. package/utilities/common/omitDeep.js +42 -0
  185. package/utilities/common/omitDeep.js.map +1 -0
  186. package/utilities/common/stripTypename.d.ts +2 -0
  187. package/utilities/common/stripTypename.d.ts.map +1 -0
  188. package/utilities/common/stripTypename.js +5 -0
  189. package/utilities/common/stripTypename.js.map +1 -0
  190. package/utilities/graphql/directives.js +4 -4
  191. package/utilities/graphql/fragments.js +3 -3
  192. package/utilities/graphql/getFromAST.js +8 -8
  193. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  194. package/utilities/graphql/storeUtils.js +2 -1
  195. package/utilities/graphql/storeUtils.js.map +1 -1
  196. package/utilities/graphql/transform.d.ts.map +1 -1
  197. package/utilities/graphql/transform.js +26 -16
  198. package/utilities/graphql/transform.js.map +1 -1
  199. package/utilities/index.d.ts +4 -0
  200. package/utilities/index.d.ts.map +1 -1
  201. package/utilities/index.js +3 -0
  202. package/utilities/index.js.map +1 -1
  203. package/utilities/promises/decoration.d.ts +15 -0
  204. package/utilities/promises/decoration.d.ts.map +1 -0
  205. package/utilities/promises/decoration.js +25 -0
  206. package/utilities/promises/decoration.js.map +1 -0
  207. package/utilities/types/DeepOmit.d.ts +9 -0
  208. package/utilities/types/DeepOmit.d.ts.map +1 -0
  209. package/utilities/types/DeepOmit.js +2 -0
  210. package/utilities/types/DeepOmit.js.map +1 -0
  211. package/utilities/utilities.cjs +128 -32
  212. package/utilities/utilities.cjs.map +1 -1
  213. package/utilities/utilities.cjs.native.js +128 -32
  214. package/version.js +1 -1
  215. package/cache/inmemory/__mocks__/optimism.d.ts +0 -2
  216. package/cache/inmemory/__mocks__/optimism.d.ts.map +0 -1
  217. package/cache/inmemory/__mocks__/optimism.js +0 -14
  218. package/cache/inmemory/__mocks__/optimism.js.map +0 -1
  219. package/react/hooks/compareResults.d.ts +0 -3
  220. package/react/hooks/compareResults.d.ts.map +0 -1
  221. package/react/hooks/compareResults.js.map +0 -1
package/apollo-client.cjs CHANGED
@@ -6,7 +6,7 @@ var tslib = require('tslib');
6
6
  var tsInvariant = require('ts-invariant');
7
7
  var process$1 = require('ts-invariant/process');
8
8
  var graphql = require('graphql');
9
- var equality = require('@wry/equality');
9
+ var equal = require('@wry/equality');
10
10
  var zenObservableTs = require('zen-observable-ts');
11
11
  require('symbol-observable');
12
12
  var optimism = require('optimism');
@@ -15,6 +15,8 @@ var trie = require('@wry/trie');
15
15
  var graphqlTag = require('graphql-tag');
16
16
  var React = require('react');
17
17
 
18
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
19
+
18
20
  function _interopNamespace(e) {
19
21
  if (e && e.__esModule) return e;
20
22
  var n = Object.create(null);
@@ -27,7 +29,9 @@ function _interopNamespace(e) {
27
29
  return Object.freeze(n);
28
30
  }
29
31
 
32
+ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
30
33
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
31
35
 
32
36
  function maybe(thunk) {
33
37
  try {
@@ -63,7 +67,7 @@ function shouldInclude(_a, variables) {
63
67
  var evaledValue = false;
64
68
  if (ifArgument.value.kind === 'Variable') {
65
69
  evaledValue = variables && variables[ifArgument.value.name.value];
66
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 41);
70
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 42);
67
71
  }
68
72
  else {
69
73
  evaledValue = ifArgument.value.value;
@@ -71,6 +75,7 @@ function shouldInclude(_a, variables) {
71
75
  return directive.name.value === 'skip' ? !evaledValue : evaledValue;
72
76
  });
73
77
  }
78
+ var hasAnyDirectives = function (names, root) { return hasDirectives(names, root, false); };
74
79
  function hasDirectives(names, root, all) {
75
80
  var nameSet = new Set(names);
76
81
  var uniqueCount = nameSet.size;
@@ -99,13 +104,13 @@ function getInclusionDirectives(directives) {
99
104
  return;
100
105
  var directiveArguments = directive.arguments;
101
106
  var directiveName = directive.name.value;
102
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 42);
107
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 43);
103
108
  var ifArgument = directiveArguments[0];
104
- __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);
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);
105
110
  var ifValue = ifArgument.value;
106
111
  __DEV__ ? tsInvariant.invariant(ifValue &&
107
112
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
108
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 44);
113
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 45);
109
114
  result.push({ directive: directive, ifArgument: ifArgument });
110
115
  });
111
116
  }
@@ -118,14 +123,14 @@ function getFragmentQueryDocument(document, fragmentName) {
118
123
  document.definitions.forEach(function (definition) {
119
124
  if (definition.kind === 'OperationDefinition') {
120
125
  throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
121
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(45);
126
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(46);
122
127
  }
123
128
  if (definition.kind === 'FragmentDefinition') {
124
129
  fragments.push(definition);
125
130
  }
126
131
  });
127
132
  if (typeof actualFragmentName === 'undefined') {
128
- __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);
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);
129
134
  actualFragmentName = fragments[0].name.value;
130
135
  }
131
136
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -166,7 +171,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
166
171
  return fragmentMap(fragmentName);
167
172
  }
168
173
  var fragment = fragmentMap && fragmentMap[fragmentName];
169
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 47);
174
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 48);
170
175
  return fragment || null;
171
176
  }
172
177
  default:
@@ -177,6 +182,12 @@ function getFragmentFromSelection(selection, fragmentMap) {
177
182
  function isNonNullObject(obj) {
178
183
  return obj !== null && typeof obj === 'object';
179
184
  }
185
+ function isPlainObject(obj) {
186
+ return (obj !== null &&
187
+ typeof obj === 'object' &&
188
+ (Object.getPrototypeOf(obj) === Object.prototype ||
189
+ Object.getPrototypeOf(obj) === null));
190
+ }
180
191
 
181
192
  function makeReference(id) {
182
193
  return { __ref: String(id) };
@@ -250,7 +261,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
250
261
  else {
251
262
  throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
252
263
  'is not supported. Use variables instead of inline arguments to ' +
253
- 'overcome this limitation.') : new tsInvariant.InvariantError(56);
264
+ 'overcome this limitation.') : new tsInvariant.InvariantError(57);
254
265
  }
255
266
  }
256
267
  function storeKeyNameFromField(field, variables) {
@@ -284,6 +295,7 @@ var KNOWN_DIRECTIVES = [
284
295
  'client',
285
296
  'rest',
286
297
  'export',
298
+ 'nonreactive',
287
299
  ];
288
300
  var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
289
301
  if (args &&
@@ -384,16 +396,16 @@ function isInlineFragment(selection) {
384
396
  }
385
397
 
386
398
  function checkDocument(doc) {
387
- __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);
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);
388
400
  var operations = doc.definitions
389
401
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
390
402
  .map(function (definition) {
391
403
  if (definition.kind !== 'OperationDefinition') {
392
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(49);
404
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(50);
393
405
  }
394
406
  return definition;
395
407
  });
396
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 50);
408
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 51);
397
409
  return doc;
398
410
  }
399
411
  function getOperationDefinition(doc) {
@@ -416,14 +428,14 @@ function getFragmentDefinitions(doc) {
416
428
  }
417
429
  function getQueryDefinition(doc) {
418
430
  var queryDef = getOperationDefinition(doc);
419
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 51);
431
+ __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 52);
420
432
  return queryDef;
421
433
  }
422
434
  function getFragmentDefinition(doc) {
423
- __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);
424
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 53);
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);
425
437
  var fragmentDef = doc.definitions[0];
426
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 54);
438
+ __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 55);
427
439
  return fragmentDef;
428
440
  }
429
441
  function getMainDefinition(queryDoc) {
@@ -446,7 +458,7 @@ function getMainDefinition(queryDoc) {
446
458
  if (fragmentDefinition) {
447
459
  return fragmentDefinition;
448
460
  }
449
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(55);
461
+ throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(56);
450
462
  }
451
463
  function getDefaultValues(definition) {
452
464
  var defaultValues = Object.create(null);
@@ -482,19 +494,30 @@ function nullIfDocIsEmpty(doc) {
482
494
  ? null
483
495
  : doc;
484
496
  }
485
- function getDirectiveMatcher(directives) {
486
- var nameSet = new Set();
487
- var tests = [];
488
- directives.forEach(function (directive) {
489
- if (directive.name) {
490
- nameSet.add(directive.name);
491
- }
492
- else if (directive.test) {
493
- tests.push(directive.test);
497
+ function getDirectiveMatcher(configs) {
498
+ var names = new Map();
499
+ var tests = new Map();
500
+ configs.forEach(function (directive) {
501
+ if (directive) {
502
+ if (directive.name) {
503
+ names.set(directive.name, directive);
504
+ }
505
+ else if (directive.test) {
506
+ tests.set(directive.test, directive);
507
+ }
494
508
  }
495
509
  });
496
- return function (directive) { return (nameSet.has(directive.name.value) ||
497
- tests.some(function (test) { return test(directive); })); };
510
+ return function (directive) {
511
+ var config = names.get(directive.name.value);
512
+ if (!config && tests.size) {
513
+ tests.forEach(function (testConfig, test) {
514
+ if (test(directive)) {
515
+ config = testConfig;
516
+ }
517
+ });
518
+ }
519
+ return config;
520
+ };
498
521
  }
499
522
  function makeInUseGetterFunction(defaultKey) {
500
523
  var map = new Map();
@@ -511,6 +534,7 @@ function makeInUseGetterFunction(defaultKey) {
511
534
  };
512
535
  }
513
536
  function removeDirectivesFromDocument(directives, doc) {
537
+ checkDocument(doc);
514
538
  var getInUseByOperationName = makeInUseGetterFunction("");
515
539
  var getInUseByFragmentName = makeInUseGetterFunction("");
516
540
  var getInUse = function (ancestors) {
@@ -534,10 +558,8 @@ function removeDirectivesFromDocument(directives, doc) {
534
558
  }
535
559
  }
536
560
  var directiveMatcher = getDirectiveMatcher(directives);
537
- var hasRemoveDirective = directives.some(function (directive) { return directive.remove; });
538
- var shouldRemoveField = function (nodeDirectives) { return (hasRemoveDirective &&
539
- nodeDirectives &&
540
- nodeDirectives.some(directiveMatcher)); };
561
+ var shouldRemoveField = function (nodeDirectives) { return (isNonEmptyArray(nodeDirectives) &&
562
+ nodeDirectives.map(directiveMatcher).some(function (config) { return config && config.remove; })); };
541
563
  var originalFragmentDefsByPath = new Map();
542
564
  var firstVisitMadeChanges = false;
543
565
  var fieldOrInlineFragmentVisitor = {
@@ -696,22 +718,6 @@ var addTypenameToDocument = Object.assign(function (doc) {
696
718
  return field === TYPENAME_FIELD;
697
719
  },
698
720
  });
699
- var connectionRemoveConfig = {
700
- test: function (directive) {
701
- var willRemove = directive.name.value === 'connection';
702
- if (willRemove) {
703
- if (!directive.arguments ||
704
- !directive.arguments.some(function (arg) { return arg.name.value === 'key'; })) {
705
- __DEV__ && tsInvariant.invariant.warn('Removing an @connection directive even though it does not have a key. ' +
706
- 'You may want to use the key parameter to specify a store key.');
707
- }
708
- }
709
- return willRemove;
710
- },
711
- };
712
- function removeConnectionDirectiveFromDocument(doc) {
713
- return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
714
- }
715
721
  function buildQueryFromSelectionSet(document) {
716
722
  var definition = getMainDefinition(document);
717
723
  var definitionOperation = definition.operation;
@@ -811,6 +817,31 @@ var DeepMerger = (function () {
811
817
  return DeepMerger;
812
818
  }());
813
819
 
820
+ function isStatefulPromise(promise) {
821
+ return 'status' in promise;
822
+ }
823
+ function wrapPromiseWithState(promise) {
824
+ if (isStatefulPromise(promise)) {
825
+ return promise;
826
+ }
827
+ var pendingPromise = promise;
828
+ pendingPromise.status = 'pending';
829
+ pendingPromise.then(function (value) {
830
+ if (pendingPromise.status === 'pending') {
831
+ var fulfilledPromise = pendingPromise;
832
+ fulfilledPromise.status = 'fulfilled';
833
+ fulfilledPromise.value = value;
834
+ }
835
+ }, function (reason) {
836
+ if (pendingPromise.status === 'pending') {
837
+ var rejectedPromise = pendingPromise;
838
+ rejectedPromise.status = 'rejected';
839
+ rejectedPromise.reason = reason;
840
+ }
841
+ });
842
+ return promise;
843
+ }
844
+
814
845
  var toString = Object.prototype.toString;
815
846
  function cloneDeep(value) {
816
847
  return cloneDeepHelper(value);
@@ -1093,6 +1124,9 @@ function isExecutionPatchResult(value) {
1093
1124
  return (isExecutionPatchIncrementalResult(value) ||
1094
1125
  isExecutionPatchInitialResult(value));
1095
1126
  }
1127
+ function isApolloPayloadResult(value) {
1128
+ return isNonNullObject(value) && "payload" in value;
1129
+ }
1096
1130
  function mergeIncrementalData(prevResult, result) {
1097
1131
  var mergedData = prevResult;
1098
1132
  var merger = new DeepMerger();
@@ -1167,7 +1201,7 @@ function stringifyForDisplay(value) {
1167
1201
 
1168
1202
  function mergeOptions(defaults, options) {
1169
1203
  return compact(defaults, options, options.variables && {
1170
- variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
1204
+ variables: compact(tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables)),
1171
1205
  });
1172
1206
  }
1173
1207
 
@@ -1191,6 +1225,51 @@ function isNodeReadableStream(value) {
1191
1225
  return !!value.pipe;
1192
1226
  }
1193
1227
 
1228
+ function omitDeep(value, key) {
1229
+ return __omitDeep(value, key);
1230
+ }
1231
+ function __omitDeep(value, key, known) {
1232
+ if (known === void 0) { known = new Map(); }
1233
+ if (known.has(value)) {
1234
+ return known.get(value);
1235
+ }
1236
+ var modified = false;
1237
+ if (Array.isArray(value)) {
1238
+ var array_1 = [];
1239
+ known.set(value, array_1);
1240
+ value.forEach(function (value, index) {
1241
+ var result = __omitDeep(value, key, known);
1242
+ modified || (modified = result !== value);
1243
+ array_1[index] = result;
1244
+ });
1245
+ if (modified) {
1246
+ return array_1;
1247
+ }
1248
+ }
1249
+ else if (isPlainObject(value)) {
1250
+ var obj_1 = Object.create(Object.getPrototypeOf(value));
1251
+ known.set(value, obj_1);
1252
+ Object.keys(value).forEach(function (k) {
1253
+ if (k === key) {
1254
+ modified = true;
1255
+ }
1256
+ else {
1257
+ var result = __omitDeep(value[k], key, known);
1258
+ modified || (modified = result !== value[k]);
1259
+ obj_1[k] = result;
1260
+ }
1261
+ });
1262
+ if (modified) {
1263
+ return obj_1;
1264
+ }
1265
+ }
1266
+ return value;
1267
+ }
1268
+
1269
+ function stripTypename(value) {
1270
+ return omitDeep(value, '__typename');
1271
+ }
1272
+
1194
1273
  function fromError(errorValue) {
1195
1274
  return new zenObservableTs.Observable(function (observer) {
1196
1275
  observer.error(errorValue);
@@ -1290,6 +1369,22 @@ function transformOperation(operation) {
1290
1369
  return transformedOperation;
1291
1370
  }
1292
1371
 
1372
+ function filterOperationVariables(variables, operation) {
1373
+ var result = tslib.__assign({}, variables);
1374
+ var unusedNames = new Set(Object.keys(variables));
1375
+ graphql.visit(operation.query, {
1376
+ Variable: function (node, _key, parent) {
1377
+ if (parent && parent.kind !== 'VariableDefinition') {
1378
+ unusedNames.delete(node.name.value);
1379
+ }
1380
+ },
1381
+ });
1382
+ unusedNames.forEach(function (name) {
1383
+ delete result[name];
1384
+ });
1385
+ return result;
1386
+ }
1387
+
1293
1388
  function passthrough(op, forward) {
1294
1389
  return (forward ? forward(op) : zenObservableTs.Observable.of());
1295
1390
  }
@@ -1395,7 +1490,7 @@ var concat = ApolloLink.concat;
1395
1490
 
1396
1491
  var execute = ApolloLink.execute;
1397
1492
 
1398
- var version = '3.8.0-alpha.10';
1493
+ var version = '3.8.0-alpha.12';
1399
1494
 
1400
1495
  function asyncIterator(source) {
1401
1496
  var _a;
@@ -1540,20 +1635,56 @@ function responseIterator(response) {
1540
1635
  throw new Error("Unknown body type for responseIterator. Please pass a streamable response.");
1541
1636
  }
1542
1637
 
1638
+ var PROTOCOL_ERRORS_SYMBOL = Symbol();
1639
+ function graphQLResultHasProtocolErrors(result) {
1640
+ if (result.extensions) {
1641
+ return Array.isArray(result.extensions[PROTOCOL_ERRORS_SYMBOL]);
1642
+ }
1643
+ return false;
1644
+ }
1645
+ function isApolloError(err) {
1646
+ return err.hasOwnProperty('graphQLErrors');
1647
+ }
1648
+ var generateErrorMessage = function (err) {
1649
+ var errors = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], err.graphQLErrors, true), err.clientErrors, true), err.protocolErrors, true);
1650
+ if (err.networkError)
1651
+ errors.push(err.networkError);
1652
+ return errors
1653
+ .map(function (err) { return isNonNullObject(err) && err.message || 'Error message not found.'; })
1654
+ .join('\n');
1655
+ };
1656
+ var ApolloError = (function (_super) {
1657
+ tslib.__extends(ApolloError, _super);
1658
+ function ApolloError(_a) {
1659
+ var graphQLErrors = _a.graphQLErrors, protocolErrors = _a.protocolErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
1660
+ var _this = _super.call(this, errorMessage) || this;
1661
+ _this.name = 'ApolloError';
1662
+ _this.graphQLErrors = graphQLErrors || [];
1663
+ _this.protocolErrors = protocolErrors || [];
1664
+ _this.clientErrors = clientErrors || [];
1665
+ _this.networkError = networkError || null;
1666
+ _this.message = errorMessage || generateErrorMessage(_this);
1667
+ _this.extraInfo = extraInfo;
1668
+ _this.__proto__ = ApolloError.prototype;
1669
+ return _this;
1670
+ }
1671
+ return ApolloError;
1672
+ }(Error));
1673
+
1543
1674
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1544
1675
  function readMultipartBody(response, observer) {
1545
- var _a, _b, _c;
1676
+ var _a, _b, _c, _d, _e;
1546
1677
  return tslib.__awaiter(this, void 0, void 0, function () {
1547
- var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _d, value, done, chunk, bi, message, i, headers, contentType_1, body, result;
1548
- var _e;
1549
- return tslib.__generator(this, function (_f) {
1550
- switch (_f.label) {
1678
+ var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _f, value, done, chunk, bi, message, i, headers, contentType_1, body, result, next;
1679
+ var _g, _h;
1680
+ return tslib.__generator(this, function (_j) {
1681
+ switch (_j.label) {
1551
1682
  case 0:
1552
1683
  if (TextDecoder === undefined) {
1553
1684
  throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
1554
1685
  }
1555
1686
  decoder = new TextDecoder("utf-8");
1556
- contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get('content-type');
1687
+ contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
1557
1688
  delimiter = "boundary=";
1558
1689
  boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter))
1559
1690
  ? contentType === null || contentType === void 0 ? void 0 : contentType.substring((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(delimiter)) + delimiter.length).replace(/['"]/g, "").replace(/\;(.*)/gm, "").trim()
@@ -1562,22 +1693,22 @@ function readMultipartBody(response, observer) {
1562
1693
  buffer = "";
1563
1694
  iterator = responseIterator(response);
1564
1695
  running = true;
1565
- _f.label = 1;
1696
+ _j.label = 1;
1566
1697
  case 1:
1567
1698
  if (!running) return [3, 3];
1568
1699
  return [4, iterator.next()];
1569
1700
  case 2:
1570
- _d = _f.sent(), value = _d.value, done = _d.done;
1701
+ _f = _j.sent(), value = _f.value, done = _f.done;
1571
1702
  chunk = typeof value === "string" ? value : decoder.decode(value);
1572
1703
  running = !done;
1573
1704
  buffer += chunk;
1574
1705
  bi = buffer.indexOf(boundary);
1575
1706
  while (bi > -1) {
1576
1707
  message = void 0;
1577
- _e = [
1708
+ _g = [
1578
1709
  buffer.slice(0, bi),
1579
1710
  buffer.slice(bi + boundary.length),
1580
- ], message = _e[0], buffer = _e[1];
1711
+ ], message = _g[0], buffer = _g[1];
1581
1712
  if (message.trim()) {
1582
1713
  i = message.indexOf("\r\n\r\n");
1583
1714
  headers = parseHeaders(message.slice(0, i));
@@ -1592,8 +1723,26 @@ function readMultipartBody(response, observer) {
1592
1723
  if (Object.keys(result).length > 1 ||
1593
1724
  "data" in result ||
1594
1725
  "incremental" in result ||
1595
- "errors" in result) {
1596
- (_b = observer.next) === null || _b === void 0 ? void 0 : _b.call(observer, result);
1726
+ "errors" in result ||
1727
+ "payload" in result) {
1728
+ if (isApolloPayloadResult(result)) {
1729
+ next = {};
1730
+ if ("payload" in result) {
1731
+ next = tslib.__assign({}, result.payload);
1732
+ }
1733
+ if ("errors" in result) {
1734
+ next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_h = {}, _h[PROTOCOL_ERRORS_SYMBOL] = result.errors, _h)) });
1735
+ }
1736
+ (_b = observer.next) === null || _b === void 0 ? void 0 : _b.call(observer, next);
1737
+ }
1738
+ else {
1739
+ (_c = observer.next) === null || _c === void 0 ? void 0 : _c.call(observer, result);
1740
+ }
1741
+ }
1742
+ else if (Object.keys(result).length === 1 &&
1743
+ "hasNext" in result &&
1744
+ !result.hasNext) {
1745
+ (_d = observer.complete) === null || _d === void 0 ? void 0 : _d.call(observer);
1597
1746
  }
1598
1747
  }
1599
1748
  catch (err) {
@@ -1604,7 +1753,7 @@ function readMultipartBody(response, observer) {
1604
1753
  }
1605
1754
  return [3, 1];
1606
1755
  case 3:
1607
- (_c = observer.complete) === null || _c === void 0 ? void 0 : _c.call(observer);
1756
+ (_e = observer.complete) === null || _e === void 0 ? void 0 : _e.call(observer);
1608
1757
  return [2];
1609
1758
  }
1610
1759
  });
@@ -1743,7 +1892,7 @@ function selectHttpOptionsAndBodyInternal(operation, printer) {
1743
1892
  options.headers = removeDuplicateHeaders(options.headers, http.preserveHeaderCase);
1744
1893
  }
1745
1894
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
1746
- var body = { operationName: operationName, variables: variables };
1895
+ var body = { operationName: operationName, variables: stripTypename(variables) };
1747
1896
  if (http.includeExtensions)
1748
1897
  body.extensions = extensions;
1749
1898
  if (http.includeQuery)
@@ -1884,20 +2033,7 @@ var createHttpLink = function (linkOptions) {
1884
2033
  }
1885
2034
  var _b = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1886
2035
  if (body.variables && !includeUnusedVariables) {
1887
- var unusedNames_1 = new Set(Object.keys(body.variables));
1888
- graphql.visit(operation.query, {
1889
- Variable: function (node, _key, parent) {
1890
- if (parent && parent.kind !== 'VariableDefinition') {
1891
- unusedNames_1.delete(node.name.value);
1892
- }
1893
- },
1894
- });
1895
- if (unusedNames_1.size) {
1896
- body.variables = tslib.__assign({}, body.variables);
1897
- unusedNames_1.forEach(function (name) {
1898
- delete body.variables[name];
1899
- });
1900
- }
2036
+ body.variables = filterOperationVariables(body.variables, operation);
1901
2037
  }
1902
2038
  var controller;
1903
2039
  if (!options.signal) {
@@ -1909,13 +2045,28 @@ var createHttpLink = function (linkOptions) {
1909
2045
  var definitionIsMutation = function (d) {
1910
2046
  return d.kind === 'OperationDefinition' && d.operation === 'mutation';
1911
2047
  };
2048
+ var definitionIsSubscription = function (d) {
2049
+ return d.kind === 'OperationDefinition' && d.operation === 'subscription';
2050
+ };
2051
+ var isSubscription = definitionIsSubscription(getMainDefinition(operation.query));
2052
+ var hasDefer = hasDirectives(['defer'], operation.query);
1912
2053
  if (useGETForQueries &&
1913
2054
  !operation.query.definitions.some(definitionIsMutation)) {
1914
2055
  options.method = 'GET';
1915
2056
  }
1916
- if (hasDirectives(['defer'], operation.query)) {
2057
+ if (hasDefer || isSubscription) {
1917
2058
  options.headers = options.headers || {};
1918
- options.headers.accept = "multipart/mixed; deferSpec=20220824, application/json";
2059
+ var acceptHeader = "multipart/mixed;";
2060
+ if (isSubscription && hasDefer) {
2061
+ __DEV__ && tsInvariant.invariant.warn("Multipart-subscriptions do not support @defer");
2062
+ }
2063
+ if (isSubscription) {
2064
+ acceptHeader += 'boundary=graphql;subscriptionSpec=1.0,application/json';
2065
+ }
2066
+ else if (hasDefer) {
2067
+ acceptHeader += 'deferSpec=20220824,application/json';
2068
+ }
2069
+ options.headers.accept = acceptHeader;
1919
2070
  }
1920
2071
  if (options.method === 'GET') {
1921
2072
  var _d = rewriteURIForGET(chosenURI, body), newURI = _d.newURI, parseError = _d.parseError;
@@ -1968,6 +2119,7 @@ var HttpLink = (function (_super) {
1968
2119
 
1969
2120
  var ApolloCache = (function () {
1970
2121
  function ApolloCache() {
2122
+ this.assumeImmutableResults = false;
1971
2123
  this.getFragmentDoc = optimism.wrap(getFragmentQueryDocument);
1972
2124
  }
1973
2125
  ApolloCache.prototype.batch = function (options) {
@@ -2566,7 +2718,7 @@ var Layer = (function (_super) {
2566
2718
  }
2567
2719
  else if (ownStoreObject !== parentStoreObject) {
2568
2720
  Object.keys(ownStoreObject).forEach(function (storeFieldName) {
2569
- if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2721
+ if (!equal.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2570
2722
  _this.group.dirty(dataId, storeFieldName);
2571
2723
  }
2572
2724
  });
@@ -2610,7 +2762,7 @@ var Stump = (function (_super) {
2610
2762
  function storeObjectReconciler(existingObject, incomingObject, property) {
2611
2763
  var existingValue = existingObject[property];
2612
2764
  var incomingValue = incomingObject[property];
2613
- return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2765
+ return equal.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2614
2766
  }
2615
2767
  function supportsResultCaching(store) {
2616
2768
  return !!(store instanceof EntityStore && store.group.caching);
@@ -3937,7 +4089,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3937
4089
  return;
3938
4090
  if (isReference(existing))
3939
4091
  return;
3940
- if (equality.equal(existing, incoming))
4092
+ if (equal.equal(existing, incoming))
3941
4093
  return;
3942
4094
  if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
3943
4095
  return;
@@ -3973,6 +4125,7 @@ var InMemoryCache = (function (_super) {
3973
4125
  var _this = _super.call(this) || this;
3974
4126
  _this.watches = new Set();
3975
4127
  _this.typenameDocumentCache = new Map();
4128
+ _this.assumeImmutableResults = true;
3976
4129
  _this.makeVar = makeVar;
3977
4130
  _this.txCount = 0;
3978
4131
  _this.config = normalizeConfig(config);
@@ -4259,51 +4412,13 @@ var InMemoryCache = (function (_super) {
4259
4412
  return;
4260
4413
  }
4261
4414
  }
4262
- if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
4415
+ if (!lastDiff || !equal.equal(lastDiff.result, diff.result)) {
4263
4416
  c.callback(c.lastDiff = diff, lastDiff);
4264
4417
  }
4265
4418
  };
4266
4419
  return InMemoryCache;
4267
4420
  }(ApolloCache));
4268
4421
 
4269
- function isApolloError(err) {
4270
- return err.hasOwnProperty('graphQLErrors');
4271
- }
4272
- var generateErrorMessage = function (err) {
4273
- var message = '';
4274
- if (isNonEmptyArray(err.graphQLErrors) || isNonEmptyArray(err.clientErrors)) {
4275
- var errors = (err.graphQLErrors || [])
4276
- .concat(err.clientErrors || []);
4277
- errors.forEach(function (error) {
4278
- var errorMessage = error
4279
- ? error.message
4280
- : 'Error message not found.';
4281
- message += "".concat(errorMessage, "\n");
4282
- });
4283
- }
4284
- if (err.networkError) {
4285
- message += "".concat(err.networkError.message, "\n");
4286
- }
4287
- message = message.replace(/\n$/, '');
4288
- return message;
4289
- };
4290
- var ApolloError = (function (_super) {
4291
- tslib.__extends(ApolloError, _super);
4292
- function ApolloError(_a) {
4293
- var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
4294
- var _this = _super.call(this, errorMessage) || this;
4295
- _this.name = 'ApolloError';
4296
- _this.graphQLErrors = graphQLErrors || [];
4297
- _this.clientErrors = clientErrors || [];
4298
- _this.networkError = networkError || null;
4299
- _this.message = errorMessage || generateErrorMessage(_this);
4300
- _this.extraInfo = extraInfo;
4301
- _this.__proto__ = ApolloError.prototype;
4302
- return _this;
4303
- }
4304
- return ApolloError;
4305
- }(Error));
4306
-
4307
4422
  exports.NetworkStatus = void 0;
4308
4423
  (function (NetworkStatus) {
4309
4424
  NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
@@ -4317,6 +4432,73 @@ exports.NetworkStatus = void 0;
4317
4432
  function isNetworkRequestInFlight(networkStatus) {
4318
4433
  return networkStatus ? networkStatus < 7 : false;
4319
4434
  }
4435
+ function isNetworkRequestSettled(networkStatus) {
4436
+ return networkStatus === 7 || networkStatus === 8;
4437
+ }
4438
+
4439
+ function equalByQuery(query, _a, _b, variables) {
4440
+ var aData = _a.data, aRest = tslib.__rest(_a, ["data"]);
4441
+ var bData = _b.data, bRest = tslib.__rest(_b, ["data"]);
4442
+ return equal__default(aRest, bRest) && equalBySelectionSet(getMainDefinition(query).selectionSet, aData, bData, {
4443
+ fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
4444
+ variables: variables,
4445
+ });
4446
+ }
4447
+ function equalBySelectionSet(selectionSet, aResult, bResult, context) {
4448
+ if (aResult === bResult) {
4449
+ return true;
4450
+ }
4451
+ var seenSelections = new Set();
4452
+ return selectionSet.selections.every(function (selection) {
4453
+ if (seenSelections.has(selection))
4454
+ return true;
4455
+ seenSelections.add(selection);
4456
+ if (!shouldInclude(selection, context.variables))
4457
+ return true;
4458
+ if (selectionHasNonreactiveDirective(selection))
4459
+ return true;
4460
+ if (isField(selection)) {
4461
+ var resultKey = resultKeyNameFromField(selection);
4462
+ var aResultChild = aResult && aResult[resultKey];
4463
+ var bResultChild = bResult && bResult[resultKey];
4464
+ var childSelectionSet = selection.selectionSet;
4465
+ if (!childSelectionSet) {
4466
+ return equal__default(aResultChild, bResultChild);
4467
+ }
4468
+ var aChildIsArray = Array.isArray(aResultChild);
4469
+ var bChildIsArray = Array.isArray(bResultChild);
4470
+ if (aChildIsArray !== bChildIsArray)
4471
+ return false;
4472
+ if (aChildIsArray && bChildIsArray) {
4473
+ var length_1 = aResultChild.length;
4474
+ if (bResultChild.length !== length_1) {
4475
+ return false;
4476
+ }
4477
+ for (var i = 0; i < length_1; ++i) {
4478
+ if (!equalBySelectionSet(childSelectionSet, aResultChild[i], bResultChild[i], context)) {
4479
+ return false;
4480
+ }
4481
+ }
4482
+ return true;
4483
+ }
4484
+ return equalBySelectionSet(childSelectionSet, aResultChild, bResultChild, context);
4485
+ }
4486
+ else {
4487
+ var fragment = getFragmentFromSelection(selection, context.fragmentMap);
4488
+ if (fragment) {
4489
+ if (selectionHasNonreactiveDirective(fragment))
4490
+ return true;
4491
+ return equalBySelectionSet(fragment.selectionSet, aResult, bResult, context);
4492
+ }
4493
+ }
4494
+ });
4495
+ }
4496
+ function selectionHasNonreactiveDirective(selection) {
4497
+ return !!selection.directives && selection.directives.some(directiveIsNonreactive);
4498
+ }
4499
+ function directiveIsNonreactive(dir) {
4500
+ return dir.name.value === "nonreactive";
4501
+ }
4320
4502
 
4321
4503
  var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
4322
4504
  var ObservableQuery = (function (_super) {
@@ -4324,14 +4506,13 @@ var ObservableQuery = (function (_super) {
4324
4506
  function ObservableQuery(_a) {
4325
4507
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
4326
4508
  var _this = _super.call(this, function (observer) {
4327
- var _a = options.fetchOnFirstSubscribe, fetchOnFirstSubscribe = _a === void 0 ? true : _a;
4328
4509
  try {
4329
4510
  var subObserver = observer._subscription._observer;
4330
4511
  if (subObserver && !subObserver.error) {
4331
4512
  subObserver.error = defaultSubscriptionObserverErrorCallback;
4332
4513
  }
4333
4514
  }
4334
- catch (_b) { }
4515
+ catch (_a) { }
4335
4516
  var first = !_this.observers.size;
4336
4517
  _this.observers.add(observer);
4337
4518
  var last = _this.last;
@@ -4341,7 +4522,7 @@ var ObservableQuery = (function (_super) {
4341
4522
  else if (last && last.result) {
4342
4523
  observer.next && observer.next(last.result);
4343
4524
  }
4344
- if (first && fetchOnFirstSubscribe) {
4525
+ if (first) {
4345
4526
  _this.reobserve().catch(function () { });
4346
4527
  }
4347
4528
  return function () {
@@ -4413,7 +4594,7 @@ var ObservableQuery = (function (_super) {
4413
4594
  if (diff.complete || this.options.returnPartialData) {
4414
4595
  result.data = diff.result;
4415
4596
  }
4416
- if (equality.equal(result.data, {})) {
4597
+ if (equal.equal(result.data, {})) {
4417
4598
  result.data = void 0;
4418
4599
  }
4419
4600
  if (diff.complete) {
@@ -4444,15 +4625,21 @@ var ObservableQuery = (function (_super) {
4444
4625
  return result;
4445
4626
  };
4446
4627
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
4447
- return (!this.last ||
4448
- !equality.equal(this.last.result, newResult) ||
4449
- (variables && !equality.equal(this.last.variables, variables)));
4628
+ if (!this.last) {
4629
+ return true;
4630
+ }
4631
+ var query = this.options.query;
4632
+ var resultIsDifferent = this.queryManager.transform(query).hasNonreactiveDirective
4633
+ ? !equalByQuery(query, this.last.result, newResult, this.variables)
4634
+ : !equal.equal(this.last.result, newResult);
4635
+ return (resultIsDifferent ||
4636
+ (variables && !equal.equal(this.last.variables, variables)));
4450
4637
  };
4451
4638
  ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
4452
4639
  var last = this.last;
4453
4640
  if (last &&
4454
4641
  last[key] &&
4455
- (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
4642
+ (!variablesMustMatch || equal.equal(last.variables, this.variables))) {
4456
4643
  return last[key];
4457
4644
  }
4458
4645
  };
@@ -4491,7 +4678,7 @@ var ObservableQuery = (function (_super) {
4491
4678
  __DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
4492
4679
  }
4493
4680
  }
4494
- if (variables && !equality.equal(this.options.variables, variables)) {
4681
+ if (variables && !equal.equal(this.options.variables, variables)) {
4495
4682
  reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
4496
4683
  }
4497
4684
  this.queryInfo.resetLastWrite();
@@ -4586,7 +4773,7 @@ var ObservableQuery = (function (_super) {
4586
4773
  return this.reobserve(newOptions);
4587
4774
  };
4588
4775
  ObservableQuery.prototype.setVariables = function (variables) {
4589
- if (equality.equal(this.variables, variables)) {
4776
+ if (equal.equal(this.variables, variables)) {
4590
4777
  return this.observers.size
4591
4778
  ? this.result()
4592
4779
  : Promise.resolve();
@@ -4651,7 +4838,7 @@ var ObservableQuery = (function (_super) {
4651
4838
  };
4652
4839
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4653
4840
  this.queryManager.setObservableQuery(this);
4654
- return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
4841
+ return this.queryManager['fetchConcastWithInfo'](this.queryId, options, newNetworkStatus);
4655
4842
  };
4656
4843
  ObservableQuery.prototype.updatePolling = function () {
4657
4844
  var _this = this;
@@ -4696,13 +4883,13 @@ var ObservableQuery = (function (_super) {
4696
4883
  };
4697
4884
  ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
4698
4885
  if (variables === void 0) { variables = this.variables; }
4699
- this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
4700
- ? newResult
4701
- : cloneDeep(newResult), variables: variables });
4702
- if (!isNonEmptyArray(newResult.errors)) {
4703
- delete this.last.error;
4886
+ var error = this.getLastError();
4887
+ if (error && this.last && !equal.equal(variables, this.last.variables)) {
4888
+ error = void 0;
4704
4889
  }
4705
- return this.last;
4890
+ return this.last = tslib.__assign({ result: this.queryManager.assumeImmutableResults
4891
+ ? newResult
4892
+ : cloneDeep(newResult), variables: variables }, (error ? { error: error } : null));
4706
4893
  };
4707
4894
  ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
4708
4895
  var _this = this;
@@ -4720,7 +4907,7 @@ var ObservableQuery = (function (_super) {
4720
4907
  this.updatePolling();
4721
4908
  if (newOptions &&
4722
4909
  newOptions.variables &&
4723
- !equality.equal(newOptions.variables, oldVariables) &&
4910
+ !equal.equal(newOptions.variables, oldVariables) &&
4724
4911
  options.fetchPolicy !== "standby" &&
4725
4912
  options.fetchPolicy === oldFetchPolicy) {
4726
4913
  this.applyNextFetchPolicy("variables-changed", options);
@@ -4730,7 +4917,7 @@ var ObservableQuery = (function (_super) {
4730
4917
  }
4731
4918
  }
4732
4919
  var variables = options.variables && tslib.__assign({}, options.variables);
4733
- var concast = this.fetch(options, newNetworkStatus);
4920
+ var _a = this.fetch(options, newNetworkStatus), concast = _a.concast, fromLink = _a.fromLink;
4734
4921
  var observer = {
4735
4922
  next: function (result) {
4736
4923
  _this.reportResult(result, variables);
@@ -4739,7 +4926,7 @@ var ObservableQuery = (function (_super) {
4739
4926
  _this.reportError(error, variables);
4740
4927
  },
4741
4928
  };
4742
- if (!useDisposableConcast) {
4929
+ if (!useDisposableConcast && (fromLink || !this.concast)) {
4743
4930
  if (this.concast && this.observer) {
4744
4931
  this.concast.removeObserver(this.observer);
4745
4932
  }
@@ -4757,11 +4944,12 @@ var ObservableQuery = (function (_super) {
4757
4944
  };
4758
4945
  ObservableQuery.prototype.reportResult = function (result, variables) {
4759
4946
  var lastError = this.getLastError();
4760
- if (lastError || this.isDifferentFromLastResult(result, variables)) {
4761
- if (lastError || !result.partial || this.options.returnPartialData) {
4762
- this.updateLastResult(result, variables);
4763
- }
4764
- iterateObserversSafely(this.observers, 'next', result);
4947
+ var isDifferent = this.isDifferentFromLastResult(result, variables);
4948
+ if (lastError || !result.partial || this.options.returnPartialData) {
4949
+ this.updateLastResult(result, variables);
4950
+ }
4951
+ if (lastError || isDifferent) {
4952
+ iterateObserversSafely(this.observers, "next", result);
4765
4953
  }
4766
4954
  };
4767
4955
  ObservableQuery.prototype.reportError = function (error, variables) {
@@ -5170,10 +5358,10 @@ var QueryInfo = (function () {
5170
5358
  var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
5171
5359
  if (this.variables &&
5172
5360
  this.networkStatus !== exports.NetworkStatus.loading &&
5173
- !equality.equal(this.variables, query.variables)) {
5361
+ !equal.equal(this.variables, query.variables)) {
5174
5362
  networkStatus = exports.NetworkStatus.setVariables;
5175
5363
  }
5176
- if (!equality.equal(query.variables, this.variables)) {
5364
+ if (!equal.equal(query.variables, this.variables)) {
5177
5365
  this.lastDiff = void 0;
5178
5366
  }
5179
5367
  Object.assign(this, {
@@ -5198,7 +5386,7 @@ var QueryInfo = (function () {
5198
5386
  QueryInfo.prototype.getDiff = function (variables) {
5199
5387
  if (variables === void 0) { variables = this.variables; }
5200
5388
  var options = this.getDiffOptions(variables);
5201
- if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
5389
+ if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
5202
5390
  return this.lastDiff.diff;
5203
5391
  }
5204
5392
  this.updateWatch(this.variables = variables);
@@ -5232,7 +5420,7 @@ var QueryInfo = (function () {
5232
5420
  var oldDiff = this.lastDiff && this.lastDiff.diff;
5233
5421
  this.updateLastDiff(diff);
5234
5422
  if (!this.dirty &&
5235
- !equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
5423
+ !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
5236
5424
  this.dirty = true;
5237
5425
  if (!this.notifyTimeout) {
5238
5426
  this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
@@ -5307,7 +5495,7 @@ var QueryInfo = (function () {
5307
5495
  }
5308
5496
  var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
5309
5497
  if (!this.lastWatch ||
5310
- !equality.equal(watchOptions, this.lastWatch)) {
5498
+ !equal.equal(watchOptions, this.lastWatch)) {
5311
5499
  this.cancel();
5312
5500
  this.cancel = this.cache.watch(this.lastWatch = watchOptions);
5313
5501
  }
@@ -5319,8 +5507,8 @@ var QueryInfo = (function () {
5319
5507
  var lastWrite = this.lastWrite;
5320
5508
  return !(lastWrite &&
5321
5509
  lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
5322
- equality.equal(variables, lastWrite.variables) &&
5323
- equality.equal(result.data, lastWrite.result.data));
5510
+ equal.equal(variables, lastWrite.variables) &&
5511
+ equal.equal(result.data, lastWrite.result.data));
5324
5512
  };
5325
5513
  QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
5326
5514
  var _this = this;
@@ -5412,7 +5600,7 @@ function shouldWriteResult(result, errorPolicy) {
5412
5600
  var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
5413
5601
  var QueryManager = (function () {
5414
5602
  function QueryManager(_a) {
5415
- var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
5603
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e;
5416
5604
  this.clientAwareness = {};
5417
5605
  this.queries = new Map();
5418
5606
  this.fetchCancelFns = new Map();
@@ -5428,7 +5616,7 @@ var QueryManager = (function () {
5428
5616
  this.clientAwareness = clientAwareness;
5429
5617
  this.localState = localState || new LocalState({ cache: cache });
5430
5618
  this.ssrMode = ssrMode;
5431
- this.assumeImmutableResults = !!assumeImmutableResults;
5619
+ this.assumeImmutableResults = assumeImmutableResults;
5432
5620
  if ((this.onBroadcast = onBroadcast)) {
5433
5621
  this.mutationStore = Object.create(null);
5434
5622
  }
@@ -5722,14 +5910,17 @@ var QueryManager = (function () {
5722
5910
  var _a = (this.defaultOptions.transformQuery || Object.create(null)).removeClientFields, removeClientFields = _a === void 0 ? true : _a;
5723
5911
  if (!transformCache.has(document)) {
5724
5912
  var transformed = this.cache.transformDocument(document);
5725
- var noConnection = removeConnectionDirectiveFromDocument(transformed);
5913
+ var serverQuery = removeDirectivesFromDocument([
5914
+ removeClientFields ? { name: 'client', remove: true } : {},
5915
+ { name: 'connection' },
5916
+ { name: 'nonreactive' },
5917
+ ], transformed);
5726
5918
  var clientQuery = this.localState.clientQuery(transformed);
5727
- var serverQuery = noConnection &&
5728
- this.localState.serverQuery(noConnection, { removeClientFields: removeClientFields });
5729
5919
  var cacheEntry_1 = {
5730
5920
  document: transformed,
5731
5921
  hasClientExports: hasClientExports(transformed),
5732
5922
  hasForcedResolvers: this.localState.shouldForceResolvers(transformed),
5923
+ hasNonreactiveDirective: hasDirectives(['nonreactive'], transformed),
5733
5924
  clientQuery: clientQuery,
5734
5925
  serverQuery: serverQuery,
5735
5926
  defaultVars: getDefaultValues(getOperationDefinition(transformed)),
@@ -5927,10 +6118,17 @@ var QueryManager = (function () {
5927
6118
  }
5928
6119
  _this.broadcastQueries();
5929
6120
  }
5930
- if (graphQLResultHasError(result)) {
5931
- throw new ApolloError({
5932
- graphQLErrors: result.errors,
5933
- });
6121
+ var hasErrors = graphQLResultHasError(result);
6122
+ var hasProtocolErrors = graphQLResultHasProtocolErrors(result);
6123
+ if (hasErrors || hasProtocolErrors) {
6124
+ var errors = {};
6125
+ if (hasErrors) {
6126
+ errors.graphQLErrors = result.errors;
6127
+ }
6128
+ if (hasProtocolErrors) {
6129
+ errors.protocolErrors = result.extensions[PROTOCOL_ERRORS_SYMBOL];
6130
+ }
6131
+ throw new ApolloError(errors);
5934
6132
  }
5935
6133
  return result;
5936
6134
  });
@@ -6062,6 +6260,9 @@ var QueryManager = (function () {
6062
6260
  });
6063
6261
  };
6064
6262
  QueryManager.prototype.fetchQueryObservable = function (queryId, options, networkStatus) {
6263
+ return this.fetchConcastWithInfo(queryId, options, networkStatus).concast;
6264
+ };
6265
+ QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus) {
6065
6266
  var _this = this;
6066
6267
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
6067
6268
  var query = this.transform(options.query).document;
@@ -6080,24 +6281,36 @@ var QueryManager = (function () {
6080
6281
  });
6081
6282
  var fromVariables = function (variables) {
6082
6283
  normalized.variables = variables;
6083
- var concastSources = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
6284
+ var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
6084
6285
  if (normalized.fetchPolicy !== "standby" &&
6085
- concastSources.length > 0 &&
6286
+ sourcesWithInfo.sources.length > 0 &&
6086
6287
  queryInfo.observableQuery) {
6087
6288
  queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
6088
6289
  }
6089
- return concastSources;
6290
+ return sourcesWithInfo;
6090
6291
  };
6091
6292
  var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
6092
6293
  this.fetchCancelFns.set(queryId, function (reason) {
6093
6294
  cleanupCancelFn();
6094
6295
  setTimeout(function () { return concast.cancel(reason); });
6095
6296
  });
6096
- var concast = new Concast(this.transform(normalized.query).hasClientExports
6097
- ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
6098
- : fromVariables(normalized.variables));
6297
+ var concast, containsDataFromLink;
6298
+ if (this.transform(normalized.query).hasClientExports) {
6299
+ concast = new Concast(this.localState
6300
+ .addExportedVariables(normalized.query, normalized.variables, normalized.context)
6301
+ .then(fromVariables).then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
6302
+ containsDataFromLink = true;
6303
+ }
6304
+ else {
6305
+ var sourcesWithInfo = fromVariables(normalized.variables);
6306
+ containsDataFromLink = sourcesWithInfo.fromLink;
6307
+ concast = new Concast(sourcesWithInfo.sources);
6308
+ }
6099
6309
  concast.promise.then(cleanupCancelFn, cleanupCancelFn);
6100
- return concast;
6310
+ return {
6311
+ concast: concast,
6312
+ fromLink: containsDataFromLink,
6313
+ };
6101
6314
  };
6102
6315
  QueryManager.prototype.refetchQueries = function (_a) {
6103
6316
  var _this = this;
@@ -6182,7 +6395,7 @@ var QueryManager = (function () {
6182
6395
  var data = diff.result;
6183
6396
  if (__DEV__ &&
6184
6397
  !returnPartialData &&
6185
- !equality.equal(data, {})) {
6398
+ !equal.equal(data, {})) {
6186
6399
  logMissingFieldErrors(diff.missing);
6187
6400
  }
6188
6401
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
@@ -6221,54 +6434,40 @@ var QueryManager = (function () {
6221
6434
  case "cache-first": {
6222
6435
  var diff = readCache();
6223
6436
  if (diff.complete) {
6224
- return [
6225
- resultsFromCache(diff, queryInfo.markReady()),
6226
- ];
6437
+ return { fromLink: false, sources: [resultsFromCache(diff, queryInfo.markReady())] };
6227
6438
  }
6228
6439
  if (returnPartialData || shouldNotify) {
6229
- return [
6230
- resultsFromCache(diff),
6231
- resultsFromLink(),
6232
- ];
6440
+ return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
6233
6441
  }
6234
- return [
6235
- resultsFromLink(),
6236
- ];
6442
+ return { fromLink: true, sources: [resultsFromLink()] };
6237
6443
  }
6238
6444
  case "cache-and-network": {
6239
6445
  var diff = readCache();
6240
6446
  if (diff.complete || returnPartialData || shouldNotify) {
6241
- return [
6242
- resultsFromCache(diff),
6243
- resultsFromLink(),
6244
- ];
6447
+ return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
6245
6448
  }
6246
- return [
6247
- resultsFromLink(),
6248
- ];
6449
+ return { fromLink: true, sources: [resultsFromLink()] };
6249
6450
  }
6250
6451
  case "cache-only":
6251
- return [
6252
- resultsFromCache(readCache(), queryInfo.markReady()),
6253
- ];
6452
+ return { fromLink: false, sources: [resultsFromCache(readCache(), queryInfo.markReady())] };
6254
6453
  case "network-only":
6255
6454
  if (shouldNotify) {
6256
- return [
6257
- resultsFromCache(readCache()),
6258
- resultsFromLink(),
6259
- ];
6455
+ return { fromLink: true, sources: [resultsFromCache(readCache()), resultsFromLink()] };
6260
6456
  }
6261
- return [resultsFromLink()];
6457
+ return { fromLink: true, sources: [resultsFromLink()] };
6262
6458
  case "no-cache":
6263
6459
  if (shouldNotify) {
6264
- return [
6265
- resultsFromCache(queryInfo.getDiff()),
6266
- resultsFromLink(),
6267
- ];
6460
+ return {
6461
+ fromLink: true,
6462
+ sources: [
6463
+ resultsFromCache(queryInfo.getDiff()),
6464
+ resultsFromLink(),
6465
+ ],
6466
+ };
6268
6467
  }
6269
- return [resultsFromLink()];
6468
+ return { fromLink: true, sources: [resultsFromLink()] };
6270
6469
  case "standby":
6271
- return [];
6470
+ return { fromLink: false, sources: [] };
6272
6471
  }
6273
6472
  };
6274
6473
  QueryManager.prototype.getQuery = function (queryId) {
@@ -6291,20 +6490,20 @@ var ApolloClient = (function () {
6291
6490
  var _this = this;
6292
6491
  this.resetStoreCallbacks = [];
6293
6492
  this.clearStoreCallbacks = [];
6493
+ if (!options.cache) {
6494
+ throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
6495
+ "in the options object. \n" +
6496
+ "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
6497
+ }
6294
6498
  var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
6295
6499
  !window.__APOLLO_CLIENT__ &&
6296
- __DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? false : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
6500
+ __DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
6297
6501
  var link = options.link;
6298
6502
  if (!link) {
6299
6503
  link = uri
6300
6504
  ? new HttpLink({ uri: uri, credentials: credentials, headers: headers })
6301
6505
  : ApolloLink.empty();
6302
6506
  }
6303
- if (!cache) {
6304
- throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
6305
- "in the options object. \n" +
6306
- "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
6307
- }
6308
6507
  this.link = link;
6309
6508
  this.cache = cache;
6310
6509
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
@@ -6542,7 +6741,7 @@ var ApolloConsumer = function (props) {
6542
6741
  var ApolloContext = getApolloContext();
6543
6742
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6544
6743
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
6545
- 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 28);
6744
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 29);
6546
6745
  return props.children(context.client);
6547
6746
  }));
6548
6747
  };
@@ -6559,7 +6758,7 @@ var ApolloProvider = function (_a) {
6559
6758
  context = Object.assign({}, context, { suspenseCache: suspenseCache });
6560
6759
  }
6561
6760
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
6562
- 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 29);
6761
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 30);
6563
6762
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6564
6763
  }));
6565
6764
  };
@@ -6569,14 +6768,14 @@ function useApolloClient(override) {
6569
6768
  var client = override || context.client;
6570
6769
  __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
6571
6770
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
6572
- 'instance in via options.') : tsInvariant.invariant(!!client, 32);
6771
+ 'instance in via options.') : tsInvariant.invariant(!!client, 33);
6573
6772
  return client;
6574
6773
  }
6575
6774
 
6576
6775
  var didWarnUncachedGetSnapshot = false;
6577
6776
  var uSESKey = "useSyncExternalStore";
6578
- var realHook = React__namespace[uSESKey];
6579
- var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
6777
+ var realHook$1 = React__namespace[uSESKey];
6778
+ var useSyncExternalStore = realHook$1 || (function (subscribe, getSnapshot, getServerSnapshot) {
6580
6779
  var value = getSnapshot();
6581
6780
  if (__DEV__ &&
6582
6781
  !didWarnUncachedGetSnapshot &&
@@ -6647,7 +6846,7 @@ function parser(document) {
6647
6846
  var variables, type, name;
6648
6847
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6649
6848
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6650
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 35);
6849
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 36);
6651
6850
  var fragments = [];
6652
6851
  var queries = [];
6653
6852
  var mutations = [];
@@ -6675,11 +6874,11 @@ function parser(document) {
6675
6874
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6676
6875
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6677
6876
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6678
- (queries.length || mutations.length || subscriptions.length), 36);
6877
+ (queries.length || mutations.length || subscriptions.length), 37);
6679
6878
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6680
6879
  "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6681
6880
  "subscriptions and ".concat(mutations.length, " mutations. ") +
6682
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 37);
6881
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 38);
6683
6882
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6684
6883
  if (!queries.length && !mutations.length)
6685
6884
  type = exports.DocumentType.Subscription;
@@ -6690,7 +6889,7 @@ function parser(document) {
6690
6889
  : subscriptions;
6691
6890
  __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6692
6891
  "".concat(definitions.length, " definitions. ") +
6693
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 38);
6892
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 39);
6694
6893
  var definition = definitions[0];
6695
6894
  variables = definition.variableDefinitions || [];
6696
6895
  if (definition.name && definition.name.kind === 'Name') {
@@ -6708,7 +6907,7 @@ function verifyDocumentType(document, type) {
6708
6907
  var requiredOperationName = operationName(type);
6709
6908
  var usedOperationName = operationName(operation.type);
6710
6909
  __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6711
- "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 39);
6910
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 40);
6712
6911
  }
6713
6912
 
6714
6913
  var hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -6734,8 +6933,6 @@ var InternalState = (function () {
6734
6933
  function InternalState(client, query, previous) {
6735
6934
  this.client = client;
6736
6935
  this.query = query;
6737
- this.asyncResolveFns = new Set();
6738
- this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
6739
6936
  this.ssrDisabledResult = maybeDeepFreeze({
6740
6937
  loading: true,
6741
6938
  data: void 0,
@@ -6759,20 +6956,30 @@ var InternalState = (function () {
6759
6956
  InternalState.prototype.forceUpdate = function () {
6760
6957
  __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
6761
6958
  };
6762
- InternalState.prototype.asyncUpdate = function (signal) {
6959
+ InternalState.prototype.executeQuery = function (options) {
6763
6960
  var _this = this;
6764
- return new Promise(function (resolve, reject) {
6765
- var watchQueryOptions = _this.watchQueryOptions;
6766
- var handleAborted = function () {
6767
- _this.asyncResolveFns.delete(resolve);
6768
- _this.optionsToIgnoreOnce.delete(watchQueryOptions);
6769
- signal.removeEventListener('abort', handleAborted);
6770
- reject(signal.reason);
6771
- };
6772
- _this.asyncResolveFns.add(resolve);
6773
- _this.optionsToIgnoreOnce.add(watchQueryOptions);
6774
- signal.addEventListener('abort', handleAborted);
6775
- _this.forceUpdate();
6961
+ var _a;
6962
+ if (options.query) {
6963
+ Object.assign(this, { query: options.query });
6964
+ }
6965
+ this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6966
+ var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
6967
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6968
+ this.result = void 0;
6969
+ this.forceUpdate();
6970
+ return new Promise(function (resolve) {
6971
+ var result;
6972
+ concast.subscribe({
6973
+ next: function (value) {
6974
+ result = value;
6975
+ },
6976
+ error: function () {
6977
+ resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
6978
+ },
6979
+ complete: function () {
6980
+ resolve(_this.toQueryResult(result));
6981
+ }
6982
+ });
6776
6983
  });
6777
6984
  };
6778
6985
  InternalState.prototype.useQuery = function (options) {
@@ -6790,7 +6997,7 @@ var InternalState = (function () {
6790
6997
  if (previousResult &&
6791
6998
  previousResult.loading === result.loading &&
6792
6999
  previousResult.networkStatus === result.networkStatus &&
6793
- equality.equal(previousResult.data, result.data)) {
7000
+ equal.equal(previousResult.data, result.data)) {
6794
7001
  return;
6795
7002
  }
6796
7003
  _this.setResult(result);
@@ -6811,7 +7018,7 @@ var InternalState = (function () {
6811
7018
  var previousResult = _this.result;
6812
7019
  if (!previousResult ||
6813
7020
  (previousResult && previousResult.loading) ||
6814
- !equality.equal(error, previousResult.error)) {
7021
+ !equal.equal(error, previousResult.error)) {
6815
7022
  _this.setResult({
6816
7023
  data: (previousResult && previousResult.data),
6817
7024
  error: error,
@@ -6828,22 +7035,15 @@ var InternalState = (function () {
6828
7035
  this.client.disableNetworkFetches,
6829
7036
  ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
6830
7037
  this.unsafeHandlePartialRefetch(result);
6831
- var queryResult = this.toQueryResult(result);
6832
- if (!queryResult.loading && this.asyncResolveFns.size) {
6833
- this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
6834
- this.asyncResolveFns.clear();
6835
- }
6836
- return queryResult;
7038
+ return this.toQueryResult(result);
6837
7039
  };
6838
7040
  InternalState.prototype.useOptions = function (options) {
6839
7041
  var _a;
6840
7042
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6841
7043
  var currentWatchQueryOptions = this.watchQueryOptions;
6842
- if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
6843
- !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
7044
+ if (!equal.equal(watchQueryOptions, currentWatchQueryOptions)) {
6844
7045
  this.watchQueryOptions = watchQueryOptions;
6845
7046
  if (currentWatchQueryOptions && this.observable) {
6846
- this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
6847
7047
  this.observable.reobserve(this.getObsQueryOptions());
6848
7048
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6849
7049
  this.result = void 0;
@@ -7010,11 +7210,15 @@ var EAGER_METHODS = [
7010
7210
  'subscribeToMore',
7011
7211
  ];
7012
7212
  function useLazyQuery(query, options) {
7013
- var _a, _b;
7014
- var abortControllersRef = React.useRef(new Set());
7213
+ var _a;
7015
7214
  var execOptionsRef = React.useRef();
7016
- var merged = execOptionsRef.current ? mergeOptions(options, execOptionsRef.current) : options;
7017
- var internalState = useInternalState(useApolloClient(options && options.client), (_b = (_a = execOptionsRef.current) === null || _a === void 0 ? void 0 : _a.query) !== null && _b !== void 0 ? _b : query);
7215
+ var optionsRef = React.useRef();
7216
+ var queryRef = React.useRef();
7217
+ var merged = mergeOptions(options, execOptionsRef.current || {});
7218
+ var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
7219
+ optionsRef.current = merged;
7220
+ queryRef.current = document;
7221
+ var internalState = useInternalState(useApolloClient(options && options.client), document);
7018
7222
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
7019
7223
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
7020
7224
  internalState.getDefaultFetchPolicy();
@@ -7040,28 +7244,15 @@ function useLazyQuery(query, options) {
7040
7244
  return eagerMethods;
7041
7245
  }, []);
7042
7246
  Object.assign(result, eagerMethods);
7043
- React.useEffect(function () {
7044
- return function () {
7045
- abortControllersRef.current.forEach(function (controller) {
7046
- controller.abort();
7047
- });
7048
- };
7049
- }, []);
7050
7247
  var execute = React.useCallback(function (executeOptions) {
7051
- var controller = new AbortController();
7052
- abortControllersRef.current.add(controller);
7053
7248
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
7054
7249
  fetchPolicy: initialFetchPolicy,
7055
7250
  };
7251
+ var options = mergeOptions(optionsRef.current, tslib.__assign({ query: queryRef.current }, execOptionsRef.current));
7056
7252
  var promise = internalState
7057
- .asyncUpdate(controller.signal)
7058
- .then(function (queryResult) {
7059
- abortControllersRef.current.delete(controller);
7060
- return Object.assign(queryResult, eagerMethods);
7061
- });
7062
- promise.catch(function () {
7063
- abortControllersRef.current.delete(controller);
7064
- });
7253
+ .executeQuery(tslib.__assign(tslib.__assign({}, options), { skip: false }))
7254
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
7255
+ promise.catch(function () { });
7065
7256
  return promise;
7066
7257
  }, []);
7067
7258
  return [execute, result];
@@ -7117,7 +7308,7 @@ function useMutation(mutation, options) {
7117
7308
  error: error,
7118
7309
  client: client,
7119
7310
  };
7120
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
7311
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
7121
7312
  setResult(ref.current.result = result_1);
7122
7313
  }
7123
7314
  }
@@ -7135,7 +7326,7 @@ function useMutation(mutation, options) {
7135
7326
  called: true,
7136
7327
  client: client,
7137
7328
  };
7138
- if (!equality.equal(ref.current.result, result_2)) {
7329
+ if (!equal.equal(ref.current.result, result_2)) {
7139
7330
  setResult(ref.current.result = result_2);
7140
7331
  }
7141
7332
  }
@@ -7225,7 +7416,7 @@ function useSubscription(subscription, options) {
7225
7416
  subscription !== ref.current.subscription ||
7226
7417
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
7227
7418
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
7228
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
7419
+ !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
7229
7420
  canResetObservableRef.current) {
7230
7421
  setResult({
7231
7422
  loading: true,
@@ -7321,13 +7512,13 @@ function useFragment_experimental(options) {
7321
7512
  var getSnapshot = function () {
7322
7513
  var latestDiffToResult = diffToResult(latestDiff);
7323
7514
  return resultRef.current &&
7324
- equality.equal(resultRef.current.data, latestDiffToResult.data)
7515
+ equal.equal(resultRef.current.data, latestDiffToResult.data)
7325
7516
  ? resultRef.current
7326
7517
  : (resultRef.current = latestDiffToResult);
7327
7518
  };
7328
7519
  return useSyncExternalStore(function (forceUpdate) {
7329
7520
  return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
7330
- if (!equality.equal(diff, latestDiff)) {
7521
+ if (!equal.equal(diff, latestDiff)) {
7331
7522
  resultRef.current = diffToResult((latestDiff = diff));
7332
7523
  forceUpdate();
7333
7524
  }
@@ -7347,130 +7538,110 @@ function diffToResult(diff) {
7347
7538
 
7348
7539
  function useDeepMemo(memoFn, deps) {
7349
7540
  var ref = React.useRef();
7350
- if (!ref.current || !equality.equal(ref.current.deps, deps)) {
7541
+ if (!ref.current || !equal.equal(ref.current.deps, deps)) {
7351
7542
  ref.current = { value: memoFn(), deps: deps };
7352
7543
  }
7353
7544
  return ref.current.value;
7354
7545
  }
7355
7546
 
7356
- var useIsomorphicLayoutEffect = canUseLayoutEffect
7357
- ? React.useLayoutEffect
7358
- : React.useEffect;
7547
+ function useStrictModeSafeCleanupEffect(cleanup) {
7548
+ var timeout;
7549
+ React.useEffect(function () {
7550
+ clearTimeout(timeout);
7551
+ return function () {
7552
+ timeout = setTimeout(cleanup);
7553
+ };
7554
+ }, []);
7555
+ }
7556
+
7557
+ var useKey = 'use';
7558
+ var realHook = React__default[useKey];
7559
+ var __use = realHook ||
7560
+ function __use(promise) {
7561
+ var statefulPromise = wrapPromiseWithState(promise);
7562
+ switch (statefulPromise.status) {
7563
+ case 'pending':
7564
+ throw statefulPromise;
7565
+ case 'rejected':
7566
+ throw statefulPromise.reason;
7567
+ case 'fulfilled':
7568
+ return statefulPromise.value;
7569
+ }
7570
+ };
7359
7571
 
7360
7572
  function useSuspenseCache(override) {
7361
7573
  var context = React.useContext(getApolloContext());
7362
7574
  var suspenseCache = override || context.suspenseCache;
7363
7575
  __DEV__ ? tsInvariant.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context or passed in as an option. ' +
7364
7576
  'Wrap the root component in an <ApolloProvider> and provide a suspenseCache, ' +
7365
- 'or pass a SuspenseCache instance in via options.') : tsInvariant.invariant(suspenseCache, 33);
7577
+ 'or pass a SuspenseCache instance in via options.') : tsInvariant.invariant(suspenseCache, 34);
7366
7578
  return suspenseCache;
7367
7579
  }
7368
7580
 
7369
- var SUPPORTED_FETCH_POLICIES = [
7370
- 'cache-first',
7371
- 'network-only',
7372
- 'no-cache',
7373
- 'cache-and-network',
7374
- ];
7375
- var DEFAULT_FETCH_POLICY = 'cache-first';
7376
- var DEFAULT_SUSPENSE_POLICY = 'always';
7377
- var DEFAULT_ERROR_POLICY = 'none';
7378
7581
  function useSuspenseQuery_experimental(query, options) {
7379
7582
  if (options === void 0) { options = Object.create(null); }
7380
- var suspenseCache = useSuspenseCache(options.suspenseCache);
7583
+ var didPreviouslySuspend = React.useRef(false);
7381
7584
  var client = useApolloClient(options.client);
7382
- var watchQueryOptions = useWatchQueryOptions({ query: query, options: options, client: client });
7383
- var previousWatchQueryOptionsRef = React.useRef(watchQueryOptions);
7384
- var deferred = useIsDeferred(query);
7385
- var fetchPolicy = watchQueryOptions.fetchPolicy, errorPolicy = watchQueryOptions.errorPolicy, returnPartialData = watchQueryOptions.returnPartialData, variables = watchQueryOptions.variables;
7386
- var cacheEntry = suspenseCache.lookup(query, variables);
7387
- var observable = React.useState(function () {
7388
- return (cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.observable) || client.watchQuery(watchQueryOptions);
7389
- })[0];
7390
- var result = useObservableQueryResult(observable);
7391
- var hasFullResult = result.data && !result.partial;
7392
- var hasPartialResult = result.data && result.partial;
7393
- var usePartialResult = returnPartialData && hasPartialResult;
7394
- var allowsThrownErrors = errorPolicy === 'none' && (!deferred || !hasPartialResult);
7395
- if (result.error &&
7396
- (result.error.networkError || allowsThrownErrors)) {
7397
- throw result.error;
7398
- }
7399
- if (result.loading) {
7400
- if (!cacheEntry) {
7401
- cacheEntry = suspenseCache.add(query, variables, {
7402
- promise: maybeWrapConcastWithCustomPromise(observable.reobserveAsConcast(watchQueryOptions), { deferred: deferred }),
7403
- observable: observable,
7404
- });
7405
- }
7406
- var hasUsableResult = usePartialResult ||
7407
- (fetchPolicy === 'cache-and-network' && hasFullResult);
7408
- if (!hasUsableResult && !cacheEntry.fulfilled) {
7409
- throw cacheEntry.promise;
7410
- }
7411
- }
7412
- React.useEffect(function () {
7413
- var variables = watchQueryOptions.variables, query = watchQueryOptions.query;
7414
- var previousOpts = previousWatchQueryOptionsRef.current;
7415
- if (variables !== previousOpts.variables || query !== previousOpts.query) {
7416
- suspenseCache.remove(previousOpts.query, previousOpts.variables);
7417
- suspenseCache.add(query, variables, {
7418
- promise: observable.reobserve({ query: query, variables: variables }),
7419
- observable: observable,
7420
- });
7421
- previousWatchQueryOptionsRef.current = watchQueryOptions;
7422
- }
7423
- }, [watchQueryOptions]);
7424
- React.useEffect(function () {
7425
- return function () {
7426
- suspenseCache.remove(query, variables);
7427
- };
7428
- }, []);
7429
- var fetchMore = React.useCallback(function (options) {
7430
- var promise = observable.fetchMore(options);
7431
- suspenseCache.add(query, watchQueryOptions.variables, {
7432
- promise: promise,
7433
- observable: observable,
7434
- });
7435
- return promise;
7436
- }, [observable]);
7437
- var refetch = React.useCallback(function (variables) {
7438
- var promise = observable.refetch(variables);
7439
- suspenseCache.add(query, watchQueryOptions.variables, {
7440
- promise: promise,
7441
- observable: observable,
7442
- });
7443
- return promise;
7444
- }, [observable]);
7445
- var subscribeToMore = React.useCallback(function (options) { return observable.subscribeToMore(options); }, [observable]);
7585
+ var suspenseCache = useSuspenseCache(options.suspenseCache);
7586
+ 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;
7590
+ var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
7591
+ var subscription = suspenseCache.getSubscription(cacheKey, function () {
7592
+ return client.watchQuery(watchQueryOptions);
7593
+ });
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]);
7617
+ var subscribeToMore = React.useCallback(function (options) { return subscription.observable.subscribeToMore(options); }, [subscription]);
7446
7618
  return React.useMemo(function () {
7447
7619
  return {
7448
7620
  client: client,
7449
7621
  data: result.data,
7450
- error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
7622
+ error: toApolloError(result),
7451
7623
  networkStatus: result.networkStatus,
7452
7624
  fetchMore: fetchMore,
7453
7625
  refetch: refetch,
7454
7626
  subscribeToMore: subscribeToMore,
7455
7627
  };
7456
- }, [
7457
- client,
7458
- fetchMore,
7459
- refetch,
7460
- result,
7461
- observable,
7462
- errorPolicy,
7463
- subscribeToMore,
7464
- ]);
7628
+ }, [client, fetchMore, refetch, result, subscribeToMore]);
7465
7629
  }
7466
7630
  function validateOptions(options) {
7467
- var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
7631
+ var query = options.query, fetchPolicy = options.fetchPolicy, returnPartialData = options.returnPartialData;
7468
7632
  verifyDocumentType(query, exports.DocumentType.Query);
7469
7633
  validateFetchPolicy(fetchPolicy);
7470
7634
  validatePartialDataReturn(fetchPolicy, returnPartialData);
7471
7635
  }
7472
7636
  function validateFetchPolicy(fetchPolicy) {
7473
- __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), 34);
7637
+ if (fetchPolicy === void 0) { fetchPolicy = 'cache-first'; }
7638
+ var supportedFetchPolicies = [
7639
+ 'cache-first',
7640
+ 'network-only',
7641
+ 'no-cache',
7642
+ 'cache-and-network',
7643
+ ];
7644
+ __DEV__ ? tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), 35);
7474
7645
  }
7475
7646
  function validatePartialDataReturn(fetchPolicy, returnPartialData) {
7476
7647
  if (fetchPolicy === 'no-cache' && returnPartialData) {
@@ -7482,125 +7653,137 @@ function toApolloError(result) {
7482
7653
  ? new ApolloError({ graphQLErrors: result.errors })
7483
7654
  : result.error;
7484
7655
  }
7485
- function maybeWrapConcastWithCustomPromise(concast, _a) {
7486
- var deferred = _a.deferred;
7487
- if (deferred) {
7488
- return new Promise(function (resolve, reject) {
7489
- var subscription = concast.subscribe({
7490
- next: function (value) {
7491
- resolve(value);
7492
- subscription.unsubscribe();
7493
- },
7494
- error: reject,
7495
- });
7496
- });
7497
- }
7498
- return concast.promise;
7656
+ function useTrackedSubscriptions(subscription) {
7657
+ var trackedSubscriptions = React.useRef(new Set());
7658
+ trackedSubscriptions.current.add(subscription);
7659
+ return function dispose() {
7660
+ trackedSubscriptions.current.forEach(function (sub) { return sub.dispose(); });
7661
+ };
7499
7662
  }
7500
7663
  function useWatchQueryOptions(_a) {
7501
- var query = _a.query, options = _a.options, client = _a.client;
7502
- var defaultOptions = client.defaultOptions.watchQuery;
7503
- var watchQueryOptions = useDeepMemo(function () {
7504
- 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"]);
7505
- 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)) });
7506
- }, [options, query, defaultOptions]);
7664
+ 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]);
7507
7666
  if (__DEV__) {
7508
7667
  validateOptions(watchQueryOptions);
7509
7668
  }
7510
7669
  return watchQueryOptions;
7511
7670
  }
7512
- function useIsDeferred(query) {
7513
- return React.useMemo(function () { return hasDirectives(['defer'], query); }, [query]);
7514
- }
7515
- function useObservableQueryResult(observable) {
7516
- var resultRef = React.useRef();
7517
- var isMountedRef = React.useRef(false);
7518
- var subscribeTimeoutRef = React.useRef();
7519
- if (!resultRef.current) {
7520
- resultRef.current = observable.getCurrentResult();
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;
7521
7677
  }
7522
- useIsomorphicLayoutEffect(function () {
7523
- isMountedRef.current = true;
7524
- return function () {
7525
- isMountedRef.current = false;
7526
- };
7527
- }, []);
7528
- return useSyncExternalStore(React.useCallback(function (forceUpdate) {
7529
- clearTimeout(subscribeTimeoutRef.current);
7530
- function handleUpdate() {
7531
- var previousResult = resultRef.current;
7532
- var result = observable.getCurrentResult();
7533
- if (previousResult.loading === result.loading &&
7534
- previousResult.networkStatus === result.networkStatus &&
7535
- equality.equal(previousResult.data, result.data)) {
7536
- return;
7537
- }
7538
- resultRef.current = result;
7539
- if (isMountedRef.current) {
7540
- forceUpdate();
7541
- }
7678
+ switch (fetchPolicy) {
7679
+ case void 0:
7680
+ case 'cache-first':
7681
+ case 'cache-and-network': {
7682
+ return Boolean(result.data && (!result.partial || returnPartialData));
7542
7683
  }
7543
- var subscription;
7544
- subscribeTimeoutRef.current = setTimeout(function () {
7545
- subscription = observable.subscribe({
7546
- next: handleUpdate,
7547
- error: handleUpdate,
7548
- });
7549
- var result = resultRef.current;
7550
- if (result.networkStatus !== observable['queryInfo'].networkStatus &&
7551
- result.networkStatus === exports.NetworkStatus.ready) {
7552
- observable['queryInfo'].markReady();
7553
- }
7554
- });
7555
- return function () {
7556
- subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
7557
- };
7558
- }, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
7684
+ default:
7685
+ return false;
7686
+ }
7559
7687
  }
7560
7688
 
7561
- var SuspenseCache = (function () {
7562
- function SuspenseCache() {
7563
- this.queries = new Map();
7564
- }
7565
- SuspenseCache.prototype.add = function (query, variables, _a) {
7566
- var promise = _a.promise, observable = _a.observable;
7567
- var variablesKey = this.getVariablesKey(variables);
7568
- var map = this.queries.get(query) || new Map();
7569
- var entry = {
7570
- observable: observable,
7571
- fulfilled: false,
7572
- promise: promise
7573
- .catch(function () {
7574
- })
7575
- .finally(function () {
7576
- entry.fulfilled = true;
7577
- }),
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
+ var QuerySubscription = (function () {
7704
+ function QuerySubscription(observable, options) {
7705
+ if (options === void 0) { options = Object.create(null); }
7706
+ var _a;
7707
+ this.listeners = new Set();
7708
+ this.listen = this.listen.bind(this);
7709
+ this.handleNext = this.handleNext.bind(this);
7710
+ this.handleError = this.handleError.bind(this);
7711
+ this.dispose = this.dispose.bind(this);
7712
+ this.observable = observable;
7713
+ this.result = observable.getCurrentResult();
7714
+ if (options.onDispose) {
7715
+ this.onDispose = options.onDispose;
7716
+ }
7717
+ this.subscription = observable.subscribe({
7718
+ next: this.handleNext,
7719
+ error: this.handleError,
7720
+ });
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;
7726
+ this.autoDisposeTimeoutId = setTimeout(this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
7727
+ }
7728
+ QuerySubscription.prototype.listen = function (listener) {
7729
+ var _this = this;
7730
+ clearTimeout(this.autoDisposeTimeoutId);
7731
+ this.listeners.add(listener);
7732
+ return function () {
7733
+ _this.listeners.delete(listener);
7578
7734
  };
7579
- map.set(variablesKey, entry);
7580
- this.queries.set(query, map);
7581
- return entry;
7582
7735
  };
7583
- SuspenseCache.prototype.lookup = function (query, variables) {
7584
- var _a;
7585
- return (_a = this.queries
7586
- .get(query)) === null || _a === void 0 ? void 0 : _a.get(this.getVariablesKey(variables));
7736
+ QuerySubscription.prototype.refetch = function (variables) {
7737
+ this.promise = this.observable.refetch(variables);
7738
+ return this.promise;
7587
7739
  };
7588
- SuspenseCache.prototype.remove = function (query, variables) {
7589
- var map = this.queries.get(query);
7590
- if (!map) {
7591
- return;
7592
- }
7593
- var key = this.getVariablesKey(variables);
7594
- var entry = map.get(key);
7595
- if (entry && !entry.observable.hasObservers()) {
7596
- map.delete(key);
7597
- }
7598
- if (map.size === 0) {
7599
- this.queries.delete(query);
7740
+ QuerySubscription.prototype.fetchMore = function (options) {
7741
+ this.promise = this.observable.fetchMore(options);
7742
+ return this.promise;
7743
+ };
7744
+ QuerySubscription.prototype.dispose = function () {
7745
+ this.subscription.unsubscribe();
7746
+ this.onDispose();
7747
+ };
7748
+ QuerySubscription.prototype.onDispose = function () {
7749
+ };
7750
+ QuerySubscription.prototype.handleNext = function (result) {
7751
+ if (isNetworkRequestSettled(result.networkStatus) &&
7752
+ this.result.data &&
7753
+ result.data === void 0) {
7754
+ result.data = this.result.data;
7600
7755
  }
7756
+ this.result = result;
7757
+ this.deliver(result);
7758
+ };
7759
+ QuerySubscription.prototype.handleError = function (error) {
7760
+ var result = tslib.__assign(tslib.__assign({}, this.result), { error: error, networkStatus: exports.NetworkStatus.error });
7761
+ this.result = result;
7762
+ this.deliver(result);
7763
+ };
7764
+ QuerySubscription.prototype.deliver = function (result) {
7765
+ this.listeners.forEach(function (listener) { return listener(result); });
7601
7766
  };
7602
- SuspenseCache.prototype.getVariablesKey = function (variables) {
7603
- return canonicalStringify(variables || Object.create(null));
7767
+ return QuerySubscription;
7768
+ }());
7769
+
7770
+ var SuspenseCache = (function () {
7771
+ function SuspenseCache(options) {
7772
+ if (options === void 0) { options = Object.create(null); }
7773
+ this.cacheKeys = new trie.Trie(canUseWeakMap, function (cacheKey) { return cacheKey; });
7774
+ this.subscriptions = new Map();
7775
+ this.options = options;
7776
+ }
7777
+ SuspenseCache.prototype.getSubscription = function (cacheKey, createObservable) {
7778
+ var _this = this;
7779
+ var stableCacheKey = this.cacheKeys.lookupArray(cacheKey);
7780
+ if (!this.subscriptions.has(stableCacheKey)) {
7781
+ this.subscriptions.set(stableCacheKey, new QuerySubscription(createObservable(), {
7782
+ autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,
7783
+ onDispose: function () { return _this.subscriptions.delete(stableCacheKey); },
7784
+ }));
7785
+ }
7786
+ return this.subscriptions.get(stableCacheKey);
7604
7787
  };
7605
7788
  return SuspenseCache;
7606
7789
  }());
@@ -7637,6 +7820,7 @@ exports.fromError = fromError;
7637
7820
  exports.fromPromise = fromPromise;
7638
7821
  exports.getApolloContext = getApolloContext;
7639
7822
  exports.isApolloError = isApolloError;
7823
+ exports.isNetworkRequestSettled = isNetworkRequestSettled;
7640
7824
  exports.isReference = isReference;
7641
7825
  exports.makeReference = makeReference;
7642
7826
  exports.makeVar = makeVar;