@apollo/client 4.3.0-alpha.3 → 4.3.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +3 -7
  3. package/__cjs/cache/core/cache.cjs +1 -1
  4. package/__cjs/cache/core/cache.cjs.map +1 -1
  5. package/__cjs/cache/core/cache.d.cts +5 -1
  6. package/__cjs/cache/core/types/Cache.d.cts +25 -0
  7. package/__cjs/cache/index.cjs.map +1 -1
  8. package/__cjs/cache/index.d.cts +1 -1
  9. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  10. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  11. package/__cjs/cache/inmemory/inMemoryCache.d.cts +6 -3
  12. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  13. package/__cjs/cache/inmemory/policies.cjs +4 -4
  14. package/__cjs/cache/inmemory/readFromStore.cjs +477 -49
  15. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  16. package/__cjs/cache/inmemory/readFromStore.d.cts +11 -2
  17. package/__cjs/cache/inmemory/types.d.cts +10 -1
  18. package/__cjs/cache/inmemory/writeToStore.cjs +5 -9
  19. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  20. package/__cjs/core/ApolloClient.cjs +21 -22
  21. package/__cjs/core/ApolloClient.cjs.map +1 -1
  22. package/__cjs/core/ApolloClient.d.cts +44 -10
  23. package/__cjs/core/ObservableQuery.cjs +46 -5
  24. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  25. package/__cjs/core/ObservableQuery.d.cts +12 -1
  26. package/__cjs/core/QueryInfo.cjs +206 -269
  27. package/__cjs/core/QueryInfo.cjs.map +1 -1
  28. package/__cjs/core/QueryInfo.d.cts +20 -4
  29. package/__cjs/core/QueryManager.cjs +52 -28
  30. package/__cjs/core/QueryManager.cjs.map +1 -1
  31. package/__cjs/core/RefetchEventManager.cjs +3 -3
  32. package/__cjs/core/dataStateErrorCache.cjs +12 -0
  33. package/__cjs/core/dataStateErrorCache.cjs.map +1 -0
  34. package/__cjs/core/dataStateErrorCache.d.cts +3 -0
  35. package/__cjs/core/types.d.cts +2 -0
  36. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  37. package/__cjs/incremental/handlers/defer20220824.d.cts +2 -4
  38. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +46 -15
  39. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  40. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +29 -6
  41. package/__cjs/incremental/types.d.cts +55 -4
  42. package/__cjs/invariantErrorCodes.cjs +50 -31
  43. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  44. package/__cjs/react/hooks/useBackgroundQuery.d.cts +100 -47
  45. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  46. package/__cjs/react/hooks/useLazyQuery.d.cts +26 -20
  47. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  48. package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
  49. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  50. package/__cjs/react/hooks/useMutation.d.cts +10 -7
  51. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  52. package/__cjs/react/hooks/useQuery.d.cts +74 -32
  53. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  54. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  55. package/__cjs/react/hooks/useSuspenseQuery.d.cts +83 -34
  56. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  57. package/__cjs/react/internal/types.d.cts +14 -3
  58. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  59. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
  60. package/__cjs/testing/core/mocking/mockLink.cjs +21 -1
  61. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  62. package/__cjs/testing/core/mocking/mockLink.d.cts +1 -2
  63. package/__cjs/utilities/caching/sizes.cjs.map +1 -1
  64. package/__cjs/utilities/caching/sizes.d.cts +39 -1
  65. package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
  66. package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
  67. package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
  68. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs +33 -0
  69. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs.map +1 -0
  70. package/__cjs/utilities/internal/addDeferFragmentLabels.d.cts +3 -0
  71. package/__cjs/utilities/internal/constants.cjs +20 -1
  72. package/__cjs/utilities/internal/constants.cjs.map +1 -1
  73. package/__cjs/utilities/internal/constants.d.cts +19 -0
  74. package/__cjs/utilities/internal/getDirectiveArgValue.cjs +19 -0
  75. package/__cjs/utilities/internal/getDirectiveArgValue.cjs.map +1 -0
  76. package/__cjs/utilities/internal/getDirectiveArgValue.d.cts +9 -0
  77. package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
  78. package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
  79. package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
  80. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  81. package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
  82. package/__cjs/utilities/internal/index.cjs +13 -4
  83. package/__cjs/utilities/internal/index.cjs.map +1 -1
  84. package/__cjs/utilities/internal/index.d.cts +7 -3
  85. package/__cjs/utilities/internal/isDeferredFragment.cjs +19 -4
  86. package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -1
  87. package/__cjs/utilities/internal/isDeferredFragment.d.cts +6 -1
  88. package/__cjs/utilities/internal/isStreamField.cjs +37 -0
  89. package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
  90. package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
  91. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
  92. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
  93. package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
  94. package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
  95. package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
  96. package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
  97. package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
  98. package/__cjs/version.cjs +1 -1
  99. package/cache/core/cache.d.ts +5 -1
  100. package/cache/core/cache.js +1 -1
  101. package/cache/core/cache.js.map +1 -1
  102. package/cache/core/types/Cache.d.ts +25 -0
  103. package/cache/core/types/Cache.js.map +1 -1
  104. package/cache/index.d.ts +1 -1
  105. package/cache/index.js.map +1 -1
  106. package/cache/inmemory/entityStore.js +3 -3
  107. package/cache/inmemory/inMemoryCache.d.ts +6 -3
  108. package/cache/inmemory/inMemoryCache.js.map +1 -1
  109. package/cache/inmemory/key-extractor.js +1 -1
  110. package/cache/inmemory/policies.js +4 -4
  111. package/cache/inmemory/readFromStore.d.ts +11 -2
  112. package/cache/inmemory/readFromStore.js +478 -50
  113. package/cache/inmemory/readFromStore.js.map +1 -1
  114. package/cache/inmemory/types.d.ts +11 -2
  115. package/cache/inmemory/types.js.map +1 -1
  116. package/cache/inmemory/writeToStore.js +6 -10
  117. package/cache/inmemory/writeToStore.js.map +1 -1
  118. package/core/ApolloClient.d.ts +44 -10
  119. package/core/ApolloClient.js +21 -22
  120. package/core/ApolloClient.js.map +1 -1
  121. package/core/ObservableQuery.d.ts +12 -1
  122. package/core/ObservableQuery.js +46 -5
  123. package/core/ObservableQuery.js.map +1 -1
  124. package/core/QueryInfo.d.ts +20 -4
  125. package/core/QueryInfo.js +202 -269
  126. package/core/QueryInfo.js.map +1 -1
  127. package/core/QueryManager.js +52 -28
  128. package/core/QueryManager.js.map +1 -1
  129. package/core/RefetchEventManager.js +3 -3
  130. package/core/dataStateErrorCache.d.ts +3 -0
  131. package/core/dataStateErrorCache.js +9 -0
  132. package/core/dataStateErrorCache.js.map +1 -0
  133. package/core/types.d.ts +2 -0
  134. package/core/types.js.map +1 -1
  135. package/incremental/handlers/defer20220824.d.ts +2 -4
  136. package/incremental/handlers/defer20220824.js.map +1 -1
  137. package/incremental/handlers/graphql17Alpha9.d.ts +29 -6
  138. package/incremental/handlers/graphql17Alpha9.js +47 -16
  139. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  140. package/incremental/types.d.ts +55 -4
  141. package/incremental/types.js.map +1 -1
  142. package/invariantErrorCodes.js +50 -31
  143. package/package.json +1 -1
  144. package/react/hooks/useBackgroundQuery.d.ts +100 -47
  145. package/react/hooks/useBackgroundQuery.js.map +1 -1
  146. package/react/hooks/useLazyQuery.d.ts +26 -20
  147. package/react/hooks/useLazyQuery.js.map +1 -1
  148. package/react/hooks/useLoadableQuery.d.ts +23 -15
  149. package/react/hooks/useLoadableQuery.js.map +1 -1
  150. package/react/hooks/useMutation.d.ts +10 -7
  151. package/react/hooks/useMutation.js.map +1 -1
  152. package/react/hooks/useQuery.d.ts +74 -32
  153. package/react/hooks/useQuery.js.map +1 -1
  154. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  155. package/react/hooks/useSuspenseQuery.d.ts +83 -34
  156. package/react/hooks/useSuspenseQuery.js.map +1 -1
  157. package/react/hooks-compiled/useBackgroundQuery.d.ts +100 -47
  158. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  159. package/react/hooks-compiled/useLazyQuery.d.ts +26 -20
  160. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  161. package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
  162. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  163. package/react/hooks-compiled/useMutation.d.ts +10 -7
  164. package/react/hooks-compiled/useMutation.js.map +1 -1
  165. package/react/hooks-compiled/useQuery.d.ts +74 -32
  166. package/react/hooks-compiled/useQuery.js.map +1 -1
  167. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  168. package/react/hooks-compiled/useSuspenseQuery.d.ts +83 -34
  169. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  170. package/react/internal/cache/QueryReference.js.map +1 -1
  171. package/react/internal/types.d.ts +15 -4
  172. package/react/internal/types.js.map +1 -1
  173. package/react/query-preloader/createQueryPreloader.d.ts +20 -5
  174. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  175. package/testing/core/mocking/mockLink.d.ts +1 -2
  176. package/testing/core/mocking/mockLink.js +21 -1
  177. package/testing/core/mocking/mockLink.js.map +1 -1
  178. package/utilities/caching/sizes.d.ts +39 -1
  179. package/utilities/caching/sizes.js.map +1 -1
  180. package/utilities/internal/StreamArrayState.d.ts +12 -0
  181. package/utilities/internal/StreamArrayState.js +23 -0
  182. package/utilities/internal/StreamArrayState.js.map +1 -0
  183. package/utilities/internal/addDeferFragmentLabels.d.ts +3 -0
  184. package/utilities/internal/addDeferFragmentLabels.js +30 -0
  185. package/utilities/internal/addDeferFragmentLabels.js.map +1 -0
  186. package/utilities/internal/constants.d.ts +19 -0
  187. package/utilities/internal/constants.js +19 -0
  188. package/utilities/internal/constants.js.map +1 -1
  189. package/utilities/internal/getDirectiveArgValue.d.ts +9 -0
  190. package/utilities/internal/getDirectiveArgValue.js +16 -0
  191. package/utilities/internal/getDirectiveArgValue.js.map +1 -0
  192. package/utilities/internal/getFragmentFromSelection.js +1 -1
  193. package/utilities/internal/getFragmentFromSelection.js.map +1 -1
  194. package/utilities/internal/getMemoryInternals.d.ts +4 -0
  195. package/utilities/internal/getMemoryInternals.js +6 -0
  196. package/utilities/internal/getMemoryInternals.js.map +1 -1
  197. package/utilities/internal/index.d.ts +7 -3
  198. package/utilities/internal/index.js +6 -2
  199. package/utilities/internal/index.js.map +1 -1
  200. package/utilities/internal/isDeferredFragment.d.ts +7 -2
  201. package/utilities/internal/isDeferredFragment.js +19 -4
  202. package/utilities/internal/isDeferredFragment.js.map +1 -1
  203. package/utilities/internal/isStreamField.d.ts +9 -0
  204. package/utilities/internal/isStreamField.js +34 -0
  205. package/utilities/internal/isStreamField.js.map +1 -0
  206. package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
  207. package/utilities/internal/makeStreamInfoTrie.js +14 -0
  208. package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
  209. package/utilities/internal/types/DeferInfo.d.ts +10 -0
  210. package/utilities/internal/types/DeferInfo.js +2 -0
  211. package/utilities/internal/types/DeferInfo.js.map +1 -0
  212. package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
  213. package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
  214. package/version.js +1 -1
  215. package/__cjs/utilities/internal/collectSiblingFields.cjs +0 -61
  216. package/__cjs/utilities/internal/collectSiblingFields.cjs.map +0 -1
  217. package/__cjs/utilities/internal/collectSiblingFields.d.cts +0 -21
  218. package/utilities/internal/collectSiblingFields.d.ts +0 -21
  219. package/utilities/internal/collectSiblingFields.js +0 -58
  220. package/utilities/internal/collectSiblingFields.js.map +0 -1
@@ -372,7 +372,18 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
372
372
  /**
373
373
  * A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
374
374
  */
375
- fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>): Promise<ApolloClient.QueryResult<TFetchData>>;
375
+ fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables, TErrorPolicy extends ErrorPolicy = "none">(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars> & {
376
+ /**
377
+ * Specifies how the query handles a response that returns both GraphQL errors and partial results.
378
+ *
379
+ * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
380
+ *
381
+ * The default value is `none`, meaning that the query result includes error details but not partial results.
382
+ *
383
+ * @docGroup 1. Operation options
384
+ */
385
+ errorPolicy?: TErrorPolicy;
386
+ }): Promise<ApolloClient.QueryResult<TFetchData, TErrorPolicy>>;
376
387
  /**
377
388
  * A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
378
389
  *
@@ -4,6 +4,7 @@ import { isNetworkRequestInFlight, isNetworkRequestSettled, } from "@apollo/clie
4
4
  import { __DEV__ } from "@apollo/client/utilities/environment";
5
5
  import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
6
6
  import { invariant } from "@apollo/client/utilities/invariant";
7
+ import { dataStateErrorCache } from "./dataStateErrorCache.js";
7
8
  import { NetworkStatus } from "./networkStatus.js";
8
9
  const { assign, hasOwnProperty } = Object;
9
10
  const uninitialized = {
@@ -878,6 +879,7 @@ export class ObservableQuery {
878
879
  if (this.pollingInfo) {
879
880
  if (!isNetworkRequestInFlight(this.networkStatus) &&
880
881
  !this.options.skipPollAttempt?.()) {
882
+ this._lastWrite = undefined;
881
883
  this._reobserve({
882
884
  // Most fetchPolicy options don't make sense to use in a polling context, as
883
885
  // users wouldn't want to be polling the cache directly. However, network-only and
@@ -1252,13 +1254,49 @@ export class ObservableQuery {
1252
1254
  });
1253
1255
  }
1254
1256
  operator = filterMap((notification) => {
1255
- const { query, variables, meta } = notification;
1257
+ const { query, meta } = notification;
1256
1258
  if (notification.source === "setResult") {
1257
- return { query, variables, result: notification.value, meta };
1259
+ return {
1260
+ query,
1261
+ variables: this.variables,
1262
+ result: notification.value,
1263
+ meta,
1264
+ };
1258
1265
  }
1259
- if (notification.kind === "C" || !isEqualQuery(notification, this)) {
1266
+ if (notification.kind === "C") {
1267
+ return;
1268
+ }
1269
+ const resolvedVariables = "resolvedVariables" in notification ?
1270
+ notification.resolvedVariables
1271
+ : undefined;
1272
+ // Usually we prefer to drop notifications that don't match this query
1273
+ // but this breaks when used with `@export` queries that resolve variables
1274
+ // after the request is initiated. `notification.resolvedVariables` gives us
1275
+ // the variables the query actually resolved with during evaluation in
1276
+ // QueryManager (which is the variables value after `@export` variables have
1277
+ // been applied), but we need to update this query with those resolved
1278
+ // variables maybe in the middle of a request (updating is handled below).
1279
+ // When we update this.variables to the resolved variables, this causes
1280
+ // isEqualQuery(notification, this) to fail for future notifications since
1281
+ // the notification.variables holds the stale variables value. In this case,
1282
+ // we want to allow the notification through only if the current variables
1283
+ // value matches the resolved variables.
1284
+ //
1285
+ // Note: the check for matching resolved variables typically kicks in for
1286
+ // multi-emission fetches (such as defer, or cache-and-network, etc).
1287
+ if (notification.query !== this.query) {
1260
1288
  return;
1261
1289
  }
1290
+ if (!equal(resolvedVariables, this.variables)) {
1291
+ if (!equal(notification.variables, this.variables)) {
1292
+ return;
1293
+ }
1294
+ if (resolvedVariables) {
1295
+ this.options.variables = resolvedVariables;
1296
+ this.resubscribeCache();
1297
+ }
1298
+ }
1299
+ const variables = this.variables;
1262
1300
  let result;
1263
1301
  const previous = this.subject.getValue();
1264
1302
  if (notification.source === "cache") {
@@ -1279,7 +1317,9 @@ export class ObservableQuery {
1279
1317
  result =
1280
1318
  notification.kind === "E" ?
1281
1319
  {
1282
- ...(isEqualQuery(previous, notification) ?
1320
+ ...((isEqualQuery(previous, notification) ||
1321
+ (resolvedVariables &&
1322
+ equal(resolvedVariables, previous.variables))) ?
1283
1323
  previous.result
1284
1324
  : { data: undefined, dataState: "empty", partial: true }),
1285
1325
  error: notification.error,
@@ -1288,7 +1328,8 @@ export class ObservableQuery {
1288
1328
  }
1289
1329
  : notification.value;
1290
1330
  if (notification.kind === "E" && result.dataState === "streaming") {
1291
- result.dataState = "complete";
1331
+ result.dataState =
1332
+ dataStateErrorCache.get(notification.error) ?? "complete";
1292
1333
  }
1293
1334
  if (result.error) {
1294
1335
  meta.shouldEmit = 1 /* EmitBehavior.force */;