@apollo/client 4.2.0-alpha.2 → 4.2.0-alpha.4

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 (147) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  4. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  5. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  6. package/__cjs/cache/inmemory/policies.cjs +4 -4
  7. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  8. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  9. package/__cjs/core/ApolloClient.cjs +52 -20
  10. package/__cjs/core/ApolloClient.cjs.map +1 -1
  11. package/__cjs/core/ApolloClient.d.cts +159 -22
  12. package/__cjs/core/ObservableQuery.cjs +7 -7
  13. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  14. package/__cjs/core/ObservableQuery.d.cts +20 -1
  15. package/__cjs/core/QueryManager.cjs +12 -12
  16. package/__cjs/core/QueryManager.cjs.map +1 -1
  17. package/__cjs/core/RefetchEventManager.cjs +134 -0
  18. package/__cjs/core/RefetchEventManager.cjs.map +1 -0
  19. package/__cjs/core/RefetchEventManager.d.cts +130 -0
  20. package/__cjs/core/index.cjs +7 -1
  21. package/__cjs/core/index.cjs.map +1 -1
  22. package/__cjs/core/index.d.cts +4 -1
  23. package/__cjs/core/refetchSources/onlineSource.cjs +10 -0
  24. package/__cjs/core/refetchSources/onlineSource.cjs.map +1 -0
  25. package/__cjs/core/refetchSources/onlineSource.d.cts +3 -0
  26. package/__cjs/core/refetchSources/windowFocusSource.cjs +13 -0
  27. package/__cjs/core/refetchSources/windowFocusSource.cjs.map +1 -0
  28. package/__cjs/core/refetchSources/windowFocusSource.d.cts +3 -0
  29. package/__cjs/core/types.d.cts +20 -0
  30. package/__cjs/invariantErrorCodes.cjs +69 -44
  31. package/__cjs/link/ws/index.cjs +9 -1
  32. package/__cjs/link/ws/index.cjs.map +1 -1
  33. package/__cjs/link/ws/index.d.cts +1 -1
  34. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  35. package/__cjs/react/hooks/useBackgroundQuery.d.cts +1486 -66
  36. package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
  37. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  38. package/__cjs/react/hooks/useLazyQuery.d.cts +366 -40
  39. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  40. package/__cjs/react/hooks/useLoadableQuery.d.cts +512 -50
  41. package/__cjs/react/hooks/useMutation.cjs +5 -48
  42. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  43. package/__cjs/react/hooks/useMutation.d.cts +239 -130
  44. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  45. package/__cjs/react/hooks/useQuery.d.cts +590 -41
  46. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  47. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  48. package/__cjs/react/hooks/useSubscription.d.cts +2 -2
  49. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  50. package/__cjs/react/hooks/useSuspenseQuery.d.cts +754 -46
  51. package/__cjs/react/internal/cache/QueryReference.cjs +1 -0
  52. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  53. package/__cjs/react/internal/cache/QueryReference.d.cts +1 -1
  54. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  55. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -1
  56. package/__cjs/react/types/types.documentation.d.cts +19 -0
  57. package/__cjs/version.cjs +1 -1
  58. package/cache/core/cache.js +1 -1
  59. package/cache/inmemory/entityStore.js +3 -3
  60. package/cache/inmemory/entityStore.js.map +1 -1
  61. package/cache/inmemory/key-extractor.js +1 -1
  62. package/cache/inmemory/policies.js +4 -4
  63. package/cache/inmemory/readFromStore.js +2 -2
  64. package/cache/inmemory/writeToStore.js +4 -4
  65. package/core/ApolloClient.d.ts +159 -22
  66. package/core/ApolloClient.js +53 -21
  67. package/core/ApolloClient.js.map +1 -1
  68. package/core/ObservableQuery.d.ts +20 -1
  69. package/core/ObservableQuery.js +7 -7
  70. package/core/ObservableQuery.js.map +1 -1
  71. package/core/QueryManager.js +12 -12
  72. package/core/QueryManager.js.map +1 -1
  73. package/core/RefetchEventManager.d.ts +130 -0
  74. package/core/RefetchEventManager.js +126 -0
  75. package/core/RefetchEventManager.js.map +1 -0
  76. package/core/index.d.ts +4 -1
  77. package/core/index.js +3 -0
  78. package/core/index.js.map +1 -1
  79. package/core/refetchSources/onlineSource.d.ts +3 -0
  80. package/core/refetchSources/onlineSource.js +6 -0
  81. package/core/refetchSources/onlineSource.js.map +1 -0
  82. package/core/refetchSources/windowFocusSource.d.ts +3 -0
  83. package/core/refetchSources/windowFocusSource.js +9 -0
  84. package/core/refetchSources/windowFocusSource.js.map +1 -0
  85. package/core/types.d.ts +20 -0
  86. package/core/types.js.map +1 -1
  87. package/invariantErrorCodes.js +69 -44
  88. package/link/ws/index.d.ts +1 -1
  89. package/link/ws/index.js +9 -1
  90. package/link/ws/index.js.map +1 -1
  91. package/package.json +3 -7
  92. package/react/hooks/useBackgroundQuery.d.ts +1486 -66
  93. package/react/hooks/useBackgroundQuery.js.map +1 -1
  94. package/react/hooks/useLazyQuery.d.ts +366 -40
  95. package/react/hooks/useLazyQuery.js +1 -0
  96. package/react/hooks/useLazyQuery.js.map +1 -1
  97. package/react/hooks/useLoadableQuery.d.ts +512 -50
  98. package/react/hooks/useLoadableQuery.js.map +1 -1
  99. package/react/hooks/useMutation.d.ts +239 -130
  100. package/react/hooks/useMutation.js +5 -48
  101. package/react/hooks/useMutation.js.map +1 -1
  102. package/react/hooks/useQuery.d.ts +590 -41
  103. package/react/hooks/useQuery.js.map +1 -1
  104. package/react/hooks/useSubscription.d.ts +2 -2
  105. package/react/hooks/useSubscription.js +1 -1
  106. package/react/hooks/useSubscription.js.map +1 -1
  107. package/react/hooks/useSuspenseQuery.d.ts +754 -46
  108. package/react/hooks/useSuspenseQuery.js.map +1 -1
  109. package/react/hooks-compiled/useBackgroundQuery.d.ts +1486 -66
  110. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  111. package/react/hooks-compiled/useLazyQuery.d.ts +366 -40
  112. package/react/hooks-compiled/useLazyQuery.js +1 -0
  113. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  114. package/react/hooks-compiled/useLoadableQuery.d.ts +512 -50
  115. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  116. package/react/hooks-compiled/useMutation.d.ts +239 -130
  117. package/react/hooks-compiled/useMutation.js +4 -47
  118. package/react/hooks-compiled/useMutation.js.map +1 -1
  119. package/react/hooks-compiled/useQuery.d.ts +590 -41
  120. package/react/hooks-compiled/useQuery.js.map +1 -1
  121. package/react/hooks-compiled/useSubscription.d.ts +2 -2
  122. package/react/hooks-compiled/useSubscription.js +1 -1
  123. package/react/hooks-compiled/useSubscription.js.map +1 -1
  124. package/react/hooks-compiled/useSuspenseQuery.d.ts +754 -46
  125. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  126. package/react/internal/cache/QueryReference.d.ts +1 -1
  127. package/react/internal/cache/QueryReference.js +1 -0
  128. package/react/internal/cache/QueryReference.js.map +1 -1
  129. package/react/query-preloader/createQueryPreloader.d.ts +20 -1
  130. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  131. package/react/types/types.documentation.d.ts +19 -0
  132. package/react/types/types.documentation.js.map +1 -1
  133. package/skills/apollo-client/SKILL.md +168 -0
  134. package/skills/apollo-client/references/caching.md +560 -0
  135. package/skills/apollo-client/references/error-handling.md +350 -0
  136. package/skills/apollo-client/references/fragments.md +804 -0
  137. package/skills/apollo-client/references/integration-client.md +336 -0
  138. package/skills/apollo-client/references/integration-nextjs.md +325 -0
  139. package/skills/apollo-client/references/integration-react-router.md +256 -0
  140. package/skills/apollo-client/references/integration-tanstack-start.md +378 -0
  141. package/skills/apollo-client/references/mutations.md +549 -0
  142. package/skills/apollo-client/references/queries.md +416 -0
  143. package/skills/apollo-client/references/state-management.md +428 -0
  144. package/skills/apollo-client/references/suspense-hooks.md +773 -0
  145. package/skills/apollo-client/references/troubleshooting.md +487 -0
  146. package/skills/apollo-client/references/typescript-codegen.md +133 -0
  147. package/version.js +1 -1
@@ -7,7 +7,7 @@ import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
7
7
  import type { ApolloClient } from "./ApolloClient.cjs";
8
8
  import { NetworkStatus } from "./networkStatus.cjs";
9
9
  import type { QueryManager } from "./QueryManager.cjs";
10
- import type { DataState, DefaultContext, ErrorLike, GetDataState, OperationVariables, TypedDocumentNode } from "./types.cjs";
10
+ import type { DataState, DefaultContext, ErrorLike, GetDataState, OperationVariables, RefetchOn, TypedDocumentNode } from "./types.cjs";
11
11
  import type { ErrorPolicy, NextFetchPolicyContext, RefetchWritePolicy, SubscribeToMoreUpdateQueryFn, UpdateQueryMapFn, WatchQueryFetchPolicy } from "./watchQueryOptions.cjs";
12
12
  export declare namespace ObservableQuery {
13
13
  type Options<TData = unknown, TVariables extends OperationVariables = OperationVariables> = {
@@ -106,6 +106,25 @@ export declare namespace ObservableQuery {
106
106
  * @docGroup 1. Operation options
107
107
  */
108
108
  variables: TVariables;
109
+ /**
110
+ * Determines whether events trigger refetches for the query. Provide an
111
+ * object mapping each refetch event to `true` (enable), `false` (disable)
112
+ * or a callback function that returns `true`/`false` to control individual
113
+ * events. Provide `false` to disable all automatic refetch events for this
114
+ * query. Provide `true` to enable all automatic refetch events for this query.
115
+ * Provide a callback function to perform additional logic to determine
116
+ * whether to enable or disable a refetch for a query.
117
+ *
118
+ * `@remarks`
119
+ * `refetchOn` inherits from `defaultOptions.watchQuery.refetchOn`. If
120
+ * `defaultOptions.watchQuery.refetchOn` is not set, all refetch events are
121
+ * enabled by default.
122
+ *
123
+ * This option only has an effect when the client is configured with a
124
+ * `refetchEventManager`.
125
+ * @docGroup 1. Operation options
126
+ */
127
+ refetchOn?: RefetchOn.Option;
109
128
  };
110
129
  type FetchMoreOptions<TData, TVariables extends OperationVariables, TFetchData = TData, TFetchVars extends OperationVariables = TVariables> = {
111
130
  /**
@@ -99,7 +99,7 @@ class QueryManager {
99
99
  */
100
100
  stop() {
101
101
  this.obsQueries.forEach((oq) => oq.stop());
102
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(87));
102
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(89));
103
103
  }
104
104
  cancelPendingFetches(error) {
105
105
  this.fetchCancelFns.forEach((cancel) => cancel(error));
@@ -114,7 +114,7 @@ class QueryManager {
114
114
  if (environment_1.__DEV__) {
115
115
  (0, invariant_1.invariant)(
116
116
  this.localState,
117
- 88,
117
+ 90,
118
118
  (0, internal_1.getOperationName)(mutation, "(anonymous)")
119
119
  );
120
120
  }
@@ -353,7 +353,7 @@ class QueryManager {
353
353
  // depend on values that previously existed in the data portion of the
354
354
  // store. So, we cancel the promises and observers that we have issued
355
355
  // so far and not yet resolved (in the case of queries).
356
- this.cancelPendingFetches((0, invariant_1.newInvariantError)(89));
356
+ this.cancelPendingFetches((0, invariant_1.newInvariantError)(91));
357
357
  this.obsQueries.forEach((observableQuery) => {
358
358
  // Set loading to true so listeners don't trigger unless they want
359
359
  // results with partial data.
@@ -423,10 +423,10 @@ class QueryManager {
423
423
  if (!included) {
424
424
  const queryName = queryNames.get(nameOrQueryString);
425
425
  if (queryName) {
426
- __DEV__ && invariant_1.invariant.warn(90, queryName);
426
+ __DEV__ && invariant_1.invariant.warn(92, queryName);
427
427
  }
428
428
  else {
429
- __DEV__ && invariant_1.invariant.warn(91);
429
+ __DEV__ && invariant_1.invariant.warn(93);
430
430
  }
431
431
  }
432
432
  });
@@ -455,7 +455,7 @@ class QueryManager {
455
455
  if (environment_1.__DEV__) {
456
456
  (0, invariant_1.invariant)(
457
457
  !this.getDocumentInfo(query).hasClientExports || this.localState,
458
- 92,
458
+ 94,
459
459
  (0, internal_1.getOperationName)(query, "(anonymous)")
460
460
  );
461
461
  }
@@ -599,14 +599,14 @@ class QueryManager {
599
599
  if (environment_1.__DEV__) {
600
600
  (0, invariant_1.invariant)(
601
601
  this.localState,
602
- 93,
602
+ 95,
603
603
  operation[0].toUpperCase() + operation.slice(1),
604
604
  operationName ?? "(anonymous)"
605
605
  );
606
606
  }
607
607
  (0, invariant_1.invariant)(
608
608
  !hasIncrementalDirective,
609
- 94,
609
+ 96,
610
610
  operation[0].toUpperCase() + operation.slice(1),
611
611
  operationName ?? "(anonymous)"
612
612
  );
@@ -784,7 +784,7 @@ class QueryManager {
784
784
  if (environment_1.__DEV__) {
785
785
  (0, invariant_1.invariant)(
786
786
  this.localState,
787
- 95,
787
+ 97,
788
788
  (0, internal_1.getOperationName)(normalized.query, "(anonymous)")
789
789
  );
790
790
  }
@@ -960,7 +960,7 @@ class QueryManager {
960
960
  !this.noCacheWarningsByCause.has(cause)) {
961
961
  this.noCacheWarningsByCause.add(cause);
962
962
  __DEV__ && invariant_1.invariant.warn(
963
- 96,
963
+ 98,
964
964
  (0, internal_1.getOperationName)(document, `Unnamed ${operationType ?? "operation"}`)
965
965
  );
966
966
  }
@@ -1022,7 +1022,7 @@ class QueryManager {
1022
1022
  if (environment_1.__DEV__) {
1023
1023
  (0, invariant_1.invariant)(
1024
1024
  this.localState,
1025
- 97,
1025
+ 99,
1026
1026
  (0, internal_1.getOperationName)(query, "(anonymous)")
1027
1027
  );
1028
1028
  }
@@ -1118,7 +1118,7 @@ function validateDidEmitValue() {
1118
1118
  didEmitValue = true;
1119
1119
  },
1120
1120
  complete() {
1121
- (0, invariant_1.invariant)(didEmitValue, 98);
1121
+ (0, invariant_1.invariant)(didEmitValue, 100);
1122
1122
  },
1123
1123
  });
1124
1124
  }