@apollo/client 4.2.8 → 4.2.10

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 (76) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +3 -7
  3. package/__cjs/cache/inmemory/readFromStore.cjs +1 -4
  4. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  5. package/__cjs/core/ApolloClient.cjs.map +1 -1
  6. package/__cjs/core/ApolloClient.d.cts +44 -10
  7. package/__cjs/core/ObservableQuery.cjs +42 -4
  8. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  9. package/__cjs/core/ObservableQuery.d.cts +12 -1
  10. package/__cjs/core/QueryManager.cjs +12 -0
  11. package/__cjs/core/QueryManager.cjs.map +1 -1
  12. package/__cjs/core/types.d.cts +2 -0
  13. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  14. package/__cjs/react/hooks/useBackgroundQuery.d.cts +92 -47
  15. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  16. package/__cjs/react/hooks/useLazyQuery.d.cts +26 -20
  17. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  18. package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
  19. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  20. package/__cjs/react/hooks/useMutation.d.cts +10 -7
  21. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  22. package/__cjs/react/hooks/useQuery.d.cts +66 -32
  23. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  24. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  25. package/__cjs/react/hooks/useSuspenseQuery.d.cts +75 -34
  26. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  27. package/__cjs/react/internal/types.d.cts +14 -3
  28. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  29. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
  30. package/__cjs/version.cjs +1 -1
  31. package/__cjs/version.cjs.map +1 -1
  32. package/cache/inmemory/readFromStore.js +2 -5
  33. package/cache/inmemory/readFromStore.js.map +1 -1
  34. package/core/ApolloClient.d.ts +44 -10
  35. package/core/ApolloClient.js.map +1 -1
  36. package/core/ObservableQuery.d.ts +12 -1
  37. package/core/ObservableQuery.js +42 -4
  38. package/core/ObservableQuery.js.map +1 -1
  39. package/core/QueryManager.js +12 -0
  40. package/core/QueryManager.js.map +1 -1
  41. package/core/types.d.ts +2 -0
  42. package/core/types.js.map +1 -1
  43. package/package.json +1 -1
  44. package/react/hooks/useBackgroundQuery.d.ts +92 -47
  45. package/react/hooks/useBackgroundQuery.js.map +1 -1
  46. package/react/hooks/useLazyQuery.d.ts +26 -20
  47. package/react/hooks/useLazyQuery.js.map +1 -1
  48. package/react/hooks/useLoadableQuery.d.ts +23 -15
  49. package/react/hooks/useLoadableQuery.js.map +1 -1
  50. package/react/hooks/useMutation.d.ts +10 -7
  51. package/react/hooks/useMutation.js.map +1 -1
  52. package/react/hooks/useQuery.d.ts +66 -32
  53. package/react/hooks/useQuery.js.map +1 -1
  54. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  55. package/react/hooks/useSuspenseQuery.d.ts +75 -34
  56. package/react/hooks/useSuspenseQuery.js.map +1 -1
  57. package/react/hooks-compiled/useBackgroundQuery.d.ts +92 -47
  58. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  59. package/react/hooks-compiled/useLazyQuery.d.ts +26 -20
  60. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  61. package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
  62. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  63. package/react/hooks-compiled/useMutation.d.ts +10 -7
  64. package/react/hooks-compiled/useMutation.js.map +1 -1
  65. package/react/hooks-compiled/useQuery.d.ts +66 -32
  66. package/react/hooks-compiled/useQuery.js.map +1 -1
  67. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  68. package/react/hooks-compiled/useSuspenseQuery.d.ts +75 -34
  69. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  70. package/react/internal/cache/QueryReference.js.map +1 -1
  71. package/react/internal/types.d.ts +15 -4
  72. package/react/internal/types.js.map +1 -1
  73. package/react/query-preloader/createQueryPreloader.d.ts +20 -5
  74. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  75. package/version.js +1 -1
  76. package/version.js.map +1 -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
  *
@@ -1254,13 +1254,49 @@ export class ObservableQuery {
1254
1254
  });
1255
1255
  }
1256
1256
  operator = filterMap((notification) => {
1257
- const { query, variables, meta } = notification;
1257
+ const { query, meta } = notification;
1258
1258
  if (notification.source === "setResult") {
1259
- return { query, variables, result: notification.value, meta };
1259
+ return {
1260
+ query,
1261
+ variables: this.variables,
1262
+ result: notification.value,
1263
+ meta,
1264
+ };
1260
1265
  }
1261
- 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) {
1262
1288
  return;
1263
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;
1264
1300
  let result;
1265
1301
  const previous = this.subject.getValue();
1266
1302
  if (notification.source === "cache") {
@@ -1281,7 +1317,9 @@ export class ObservableQuery {
1281
1317
  result =
1282
1318
  notification.kind === "E" ?
1283
1319
  {
1284
- ...(isEqualQuery(previous, notification) ?
1320
+ ...((isEqualQuery(previous, notification) ||
1321
+ (resolvedVariables &&
1322
+ equal(resolvedVariables, previous.variables))) ?
1285
1323
  previous.result
1286
1324
  : { data: undefined, dataState: "empty", partial: true }),
1287
1325
  error: notification.error,