@apollo/client 4.1.0-alpha.2 → 4.1.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 (250) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/__cjs/cache/core/cache.cjs +148 -50
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +72 -23
  5. package/__cjs/cache/core/types/common.cjs.map +1 -1
  6. package/__cjs/cache/core/types/common.d.cts +1 -1
  7. package/__cjs/cache/inmemory/fragmentRegistry.cjs +1 -1
  8. package/__cjs/cache/inmemory/fragmentRegistry.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/inMemoryCache.cjs +12 -1
  10. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  11. package/__cjs/core/ApolloClient.cjs +24 -27
  12. package/__cjs/core/ApolloClient.cjs.map +1 -1
  13. package/__cjs/core/ApolloClient.d.cts +94 -5
  14. package/__cjs/core/ObservableQuery.cjs +8 -4
  15. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  16. package/__cjs/core/ObservableQuery.d.cts +2 -2
  17. package/__cjs/core/QueryManager.cjs +1 -1
  18. package/__cjs/core/QueryManager.cjs.map +1 -1
  19. package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
  20. package/__cjs/dev/setErrorMessageHandler.d.cts +1 -1
  21. package/__cjs/incremental/handlers/defer20220824.cjs +6 -2
  22. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  23. package/__cjs/incremental/handlers/defer20220824.d.cts +0 -2
  24. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +9 -3
  25. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  26. package/__cjs/link/schema/index.cjs +1 -1
  27. package/__cjs/link/schema/index.cjs.map +1 -1
  28. package/__cjs/link/schema/index.d.cts +1 -1
  29. package/__cjs/link/subscriptions/index.cjs +2 -1
  30. package/__cjs/link/subscriptions/index.cjs.map +1 -1
  31. package/__cjs/masking/maskDefinition.cjs +1 -1
  32. package/__cjs/masking/maskDefinition.cjs.map +1 -1
  33. package/__cjs/masking/types.d.cts +2 -1
  34. package/__cjs/react/hooks/internal/index.cjs +3 -1
  35. package/__cjs/react/hooks/internal/index.cjs.map +1 -1
  36. package/__cjs/react/hooks/internal/index.d.cts +1 -0
  37. package/__cjs/react/hooks/internal/useDeepMemo.cjs +2 -0
  38. package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
  39. package/__cjs/react/hooks/internal/useRenderGuard.cjs +1 -1
  40. package/__cjs/react/hooks/internal/useRenderGuard.cjs.map +1 -1
  41. package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs +28 -0
  42. package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs.map +1 -0
  43. package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.d.cts +11 -0
  44. package/__cjs/react/hooks/useBackgroundQuery.cjs +3 -11
  45. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  46. package/__cjs/react/hooks/useFragment.cjs +38 -87
  47. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  48. package/__cjs/react/hooks/useFragment.d.cts +65 -6
  49. package/__cjs/react/hooks/useLazyQuery.cjs +2 -0
  50. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  51. package/__cjs/react/hooks/useLazyQuery.d.cts +1 -1
  52. package/__cjs/react/hooks/useMutation.d.cts +3 -1
  53. package/__cjs/react/hooks/useQuery.cjs +1 -4
  54. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  55. package/__cjs/react/hooks/useQuery.d.cts +2 -2
  56. package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -3
  57. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  58. package/__cjs/react/hooks/useReactiveVar.cjs +2 -1
  59. package/__cjs/react/hooks/useReactiveVar.cjs.map +1 -1
  60. package/__cjs/react/hooks/useReactiveVar.d.cts +2 -1
  61. package/__cjs/react/hooks/useReadQuery.cjs +1 -3
  62. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  63. package/__cjs/react/hooks/useReadQuery.d.cts +1 -1
  64. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  65. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  66. package/__cjs/react/hooks/useSuspenseFragment.cjs +16 -16
  67. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  68. package/__cjs/react/hooks/useSuspenseFragment.d.cts +33 -7
  69. package/__cjs/react/hooks/useSuspenseQuery.cjs +6 -12
  70. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  71. package/__cjs/react/hooks/useSuspenseQuery.d.cts +1 -1
  72. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  73. package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
  74. package/__cjs/react/internal/cache/FragmentReference.cjs +3 -22
  75. package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
  76. package/__cjs/react/internal/cache/FragmentReference.d.cts +2 -4
  77. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  78. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  79. package/__cjs/react/internal/cache/QueryReference.d.cts +4 -0
  80. package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
  81. package/__cjs/react/internal/cache/SuspenseCache.d.cts +1 -1
  82. package/__cjs/react/internal/cache/types.d.cts +2 -2
  83. package/__cjs/react/ssr/useSSRQuery.cjs +1 -0
  84. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
  85. package/__cjs/react/types/types.documentation.d.cts +4 -16
  86. package/__cjs/testing/core/mocking/mockLink.cjs +2 -2
  87. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  88. package/__cjs/testing/core/mocking/mockLink.d.cts +3 -1
  89. package/__cjs/utilities/DeepPartial.cjs.map +1 -1
  90. package/__cjs/utilities/DeepPartial.d.cts +1 -1
  91. package/__cjs/utilities/internal/combineLatestBatched.cjs +71 -0
  92. package/__cjs/utilities/internal/combineLatestBatched.cjs.map +1 -0
  93. package/__cjs/utilities/internal/combineLatestBatched.d.cts +14 -0
  94. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  95. package/__cjs/utilities/internal/index.cjs +4 -2
  96. package/__cjs/utilities/internal/index.cjs.map +1 -1
  97. package/__cjs/utilities/internal/index.d.cts +1 -0
  98. package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +1 -1
  99. package/__cjs/version.cjs +1 -1
  100. package/cache/core/cache.d.ts +72 -23
  101. package/cache/core/cache.js +151 -53
  102. package/cache/core/cache.js.map +1 -1
  103. package/cache/core/types/common.d.ts +1 -1
  104. package/cache/core/types/common.js.map +1 -1
  105. package/cache/inmemory/fragmentRegistry.js +1 -1
  106. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  107. package/cache/inmemory/inMemoryCache.js +12 -1
  108. package/cache/inmemory/inMemoryCache.js.map +1 -1
  109. package/core/ApolloClient.d.ts +94 -5
  110. package/core/ApolloClient.js +24 -27
  111. package/core/ApolloClient.js.map +1 -1
  112. package/core/ObservableQuery.d.ts +2 -2
  113. package/core/ObservableQuery.js +8 -4
  114. package/core/ObservableQuery.js.map +1 -1
  115. package/core/QueryManager.js +1 -1
  116. package/core/QueryManager.js.map +1 -1
  117. package/dev/setErrorMessageHandler.d.ts +1 -1
  118. package/dev/setErrorMessageHandler.js.map +1 -1
  119. package/incremental/handlers/defer20220824.d.ts +0 -2
  120. package/incremental/handlers/defer20220824.js +6 -2
  121. package/incremental/handlers/defer20220824.js.map +1 -1
  122. package/incremental/handlers/graphql17Alpha9.js +9 -3
  123. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  124. package/link/schema/index.d.ts +1 -1
  125. package/link/schema/index.js +1 -1
  126. package/link/schema/index.js.map +1 -1
  127. package/link/subscriptions/index.js +2 -1
  128. package/link/subscriptions/index.js.map +1 -1
  129. package/masking/internal/types.js.map +1 -1
  130. package/masking/maskDefinition.js +1 -1
  131. package/masking/maskDefinition.js.map +1 -1
  132. package/masking/types.d.ts +2 -1
  133. package/masking/types.js.map +1 -1
  134. package/package.json +1 -1
  135. package/react/hooks/internal/index.d.ts +1 -0
  136. package/react/hooks/internal/index.js +1 -0
  137. package/react/hooks/internal/index.js.map +1 -1
  138. package/react/hooks/internal/useDeepMemo.js +2 -0
  139. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  140. package/react/hooks/internal/useRenderGuard.js +1 -1
  141. package/react/hooks/internal/useRenderGuard.js.map +1 -1
  142. package/react/hooks/internal/useSuspenseHookCacheKey.d.ts +11 -0
  143. package/react/hooks/internal/useSuspenseHookCacheKey.js +24 -0
  144. package/react/hooks/internal/useSuspenseHookCacheKey.js.map +1 -0
  145. package/react/hooks/useBackgroundQuery.js +4 -12
  146. package/react/hooks/useBackgroundQuery.js.map +1 -1
  147. package/react/hooks/useFragment.d.ts +65 -6
  148. package/react/hooks/useFragment.js +38 -87
  149. package/react/hooks/useFragment.js.map +1 -1
  150. package/react/hooks/useLazyQuery.d.ts +1 -1
  151. package/react/hooks/useLazyQuery.js +2 -0
  152. package/react/hooks/useLazyQuery.js.map +1 -1
  153. package/react/hooks/useMutation.d.ts +3 -1
  154. package/react/hooks/useQuery.d.ts +1 -1
  155. package/react/hooks/useQuery.js +1 -4
  156. package/react/hooks/useQuery.js.map +1 -1
  157. package/react/hooks/useQueryRefHandlers.js +1 -3
  158. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  159. package/react/hooks/useReactiveVar.d.ts +2 -1
  160. package/react/hooks/useReactiveVar.js +2 -1
  161. package/react/hooks/useReactiveVar.js.map +1 -1
  162. package/react/hooks/useReadQuery.d.ts +1 -1
  163. package/react/hooks/useReadQuery.js +1 -3
  164. package/react/hooks/useReadQuery.js.map +1 -1
  165. package/react/hooks/useSubscription.js +1 -1
  166. package/react/hooks/useSubscription.js.map +1 -1
  167. package/react/hooks/useSuspenseFragment.d.ts +33 -7
  168. package/react/hooks/useSuspenseFragment.js +17 -17
  169. package/react/hooks/useSuspenseFragment.js.map +1 -1
  170. package/react/hooks/useSuspenseQuery.d.ts +1 -1
  171. package/react/hooks/useSuspenseQuery.js +7 -13
  172. package/react/hooks/useSuspenseQuery.js.map +1 -1
  173. package/react/hooks/useSyncExternalStore.js +1 -1
  174. package/react/hooks/useSyncExternalStore.js.map +1 -1
  175. package/react/hooks-compiled/internal/index.d.ts +1 -0
  176. package/react/hooks-compiled/internal/index.js +1 -0
  177. package/react/hooks-compiled/internal/index.js.map +1 -1
  178. package/react/hooks-compiled/internal/useDeepMemo.js +2 -0
  179. package/react/hooks-compiled/internal/useDeepMemo.js.map +1 -1
  180. package/react/hooks-compiled/internal/useRenderGuard.js +1 -1
  181. package/react/hooks-compiled/internal/useRenderGuard.js.map +1 -1
  182. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.d.ts +11 -0
  183. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js +71 -0
  184. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js.map +1 -0
  185. package/react/hooks-compiled/useBackgroundQuery.js +6 -14
  186. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  187. package/react/hooks-compiled/useFragment.d.ts +65 -6
  188. package/react/hooks-compiled/useFragment.js +110 -88
  189. package/react/hooks-compiled/useFragment.js.map +1 -1
  190. package/react/hooks-compiled/useLazyQuery.d.ts +1 -1
  191. package/react/hooks-compiled/useLazyQuery.js +2 -0
  192. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  193. package/react/hooks-compiled/useLoadableQuery.js +69 -75
  194. package/react/hooks-compiled/useMutation.d.ts +3 -1
  195. package/react/hooks-compiled/useMutation.js +0 -12
  196. package/react/hooks-compiled/useMutation.js.map +1 -1
  197. package/react/hooks-compiled/useQuery.d.ts +1 -1
  198. package/react/hooks-compiled/useQuery.js +44 -56
  199. package/react/hooks-compiled/useQuery.js.map +1 -1
  200. package/react/hooks-compiled/useQueryRefHandlers.js +1 -5
  201. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  202. package/react/hooks-compiled/useReactiveVar.d.ts +2 -1
  203. package/react/hooks-compiled/useReactiveVar.js +2 -1
  204. package/react/hooks-compiled/useReactiveVar.js.map +1 -1
  205. package/react/hooks-compiled/useReadQuery.d.ts +1 -1
  206. package/react/hooks-compiled/useReadQuery.js +77 -14
  207. package/react/hooks-compiled/useReadQuery.js.map +1 -1
  208. package/react/hooks-compiled/useSubscription.js +237 -93
  209. package/react/hooks-compiled/useSubscription.js.map +1 -1
  210. package/react/hooks-compiled/useSuspenseFragment.d.ts +33 -7
  211. package/react/hooks-compiled/useSuspenseFragment.js +17 -17
  212. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  213. package/react/hooks-compiled/useSuspenseQuery.d.ts +1 -1
  214. package/react/hooks-compiled/useSuspenseQuery.js +9 -19
  215. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  216. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  217. package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
  218. package/react/index.compiled.d.ts +1 -1
  219. package/react/index.compiled.js +1 -1
  220. package/react/index.compiled.js.map +1 -1
  221. package/react/internal/cache/FragmentReference.d.ts +2 -4
  222. package/react/internal/cache/FragmentReference.js +3 -22
  223. package/react/internal/cache/FragmentReference.js.map +1 -1
  224. package/react/internal/cache/QueryReference.d.ts +4 -0
  225. package/react/internal/cache/QueryReference.js +1 -1
  226. package/react/internal/cache/QueryReference.js.map +1 -1
  227. package/react/internal/cache/SuspenseCache.d.ts +1 -1
  228. package/react/internal/cache/SuspenseCache.js.map +1 -1
  229. package/react/internal/cache/types.d.ts +2 -2
  230. package/react/internal/cache/types.js.map +1 -1
  231. package/react/ssr/useSSRQuery.js +1 -0
  232. package/react/ssr/useSSRQuery.js.map +1 -1
  233. package/react/types/types.documentation.d.ts +4 -16
  234. package/react/types/types.documentation.js.map +1 -1
  235. package/testing/core/mocking/mockLink.d.ts +3 -1
  236. package/testing/core/mocking/mockLink.js +2 -2
  237. package/testing/core/mocking/mockLink.js.map +1 -1
  238. package/utilities/DeepPartial.d.ts +1 -1
  239. package/utilities/DeepPartial.js.map +1 -1
  240. package/utilities/internal/combineLatestBatched.d.ts +14 -0
  241. package/utilities/internal/combineLatestBatched.js +68 -0
  242. package/utilities/internal/combineLatestBatched.js.map +1 -0
  243. package/utilities/internal/getMemoryInternals.js.map +1 -1
  244. package/utilities/internal/globals/global.js +2 -2
  245. package/utilities/internal/globals/global.js.map +1 -1
  246. package/utilities/internal/index.d.ts +1 -0
  247. package/utilities/internal/index.js +1 -0
  248. package/utilities/internal/index.js.map +1 -1
  249. package/utilities/internal/types/DocumentationTypes.d.ts +1 -1
  250. package/version.js +1 -1
@@ -214,7 +214,9 @@ export declare namespace ApolloClient {
214
214
  } & VariablesOption<NoInfer<TVariables>>;
215
215
  interface MutateResult<TData = unknown> {
216
216
  /**
217
- * The data returned from your mutation. Can be `undefined` if `ignoreResults` is `true`.
217
+ * The data returned from your mutation. Can be `undefined` if the `errorPolicy`
218
+ * is `all` or `ignore` and the server returns a GraphQL response with `errors`
219
+ * but not `data` or a network error is returned.
218
220
  */
219
221
  data: TData | undefined;
220
222
  /**
@@ -275,7 +277,7 @@ export declare namespace ApolloClient {
275
277
  */
276
278
  data: TData | undefined;
277
279
  /**
278
- * A single ErrorLike object describing the error that occured during the latest
280
+ * A single ErrorLike object describing the error that occurred during the latest
279
281
  * query execution.
280
282
  *
281
283
  * For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
@@ -365,7 +367,9 @@ export declare namespace ApolloClient {
365
367
  } & VariablesOption<NoInfer<TVariables>>;
366
368
  interface SubscribeResult<TData = unknown> {
367
369
  /**
368
- * The data returned from your mutation. Can be `undefined` if `ignoreResults` is `true`.
370
+ * The data returned from your mutation. Can be `undefined` if the `errorPolicy`
371
+ * is `all` or `ignore` and the server returns a GraphQL response with `errors`
372
+ * but not `data` or a network error is returned.
369
373
  */
370
374
  data: TData | undefined;
371
375
  /**
@@ -380,7 +384,13 @@ export declare namespace ApolloClient {
380
384
  extensions?: Record<string, unknown>;
381
385
  }
382
386
  type WatchFragmentOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = ApolloCache.WatchFragmentOptions<TData, TVariables>;
383
- type WatchFragmentResult<TData = unknown> = ApolloCache.WatchFragmentResult<TData>;
387
+ type WatchFragmentResult<TData = unknown> = ApolloCache.WatchFragmentResult<MaybeMasked<TData>>;
388
+ interface ObservableFragment<TData = unknown> extends Observable<ApolloClient.WatchFragmentResult<TData>> {
389
+ /**
390
+ * Return the current result for the fragment.
391
+ */
392
+ getCurrentResult: () => ApolloClient.WatchFragmentResult<TData>;
393
+ }
384
394
  /**
385
395
  * Watched query options.
386
396
  */
@@ -819,7 +829,86 @@ export declare class ApolloClient {
819
829
  * the cache to identify the fragment and optionally specify whether to react
820
830
  * to optimistic updates.
821
831
  */
822
- watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables>): Observable<ApolloClient.WatchFragmentResult<MaybeMasked<TData>>>;
832
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
833
+ from: Array<NonNullable<ApolloCache.WatchFragmentFromValue<TData>>>;
834
+ }): ApolloClient.ObservableFragment<Array<TData>>;
835
+ /**
836
+ * Watches the cache store of the fragment according to the options specified
837
+ * and returns an `Observable`. We can subscribe to this
838
+ * `Observable` and receive updated results through an
839
+ * observer when the cache store changes.
840
+ *
841
+ * You must pass in a GraphQL document with a single fragment or a document
842
+ * with multiple fragments that represent what you are reading. If you pass
843
+ * in a document with multiple fragments then you must also specify a
844
+ * `fragmentName`.
845
+ *
846
+ * @since 3.10.0
847
+ * @param options - An object of type `WatchFragmentOptions` that allows
848
+ * the cache to identify the fragment and optionally specify whether to react
849
+ * to optimistic updates.
850
+ */
851
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
852
+ from: Array<null>;
853
+ }): ApolloClient.ObservableFragment<Array<null>>;
854
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
855
+ from: Array<ApolloCache.WatchFragmentFromValue<TData>>;
856
+ }): ApolloClient.ObservableFragment<Array<TData | null>>;
857
+ /**
858
+ * Watches the cache store of the fragment according to the options specified
859
+ * and returns an `Observable`. We can subscribe to this
860
+ * `Observable` and receive updated results through an
861
+ * observer when the cache store changes.
862
+ *
863
+ * You must pass in a GraphQL document with a single fragment or a document
864
+ * with multiple fragments that represent what you are reading. If you pass
865
+ * in a document with multiple fragments then you must also specify a
866
+ * `fragmentName`.
867
+ *
868
+ * @since 3.10.0
869
+ * @param options - An object of type `WatchFragmentOptions` that allows
870
+ * the cache to identify the fragment and optionally specify whether to react
871
+ * to optimistic updates.
872
+ */
873
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
874
+ from: null;
875
+ }): ApolloClient.ObservableFragment<null>;
876
+ /**
877
+ * Watches the cache store of the fragment according to the options specified
878
+ * and returns an `Observable`. We can subscribe to this
879
+ * `Observable` and receive updated results through an
880
+ * observer when the cache store changes.
881
+ *
882
+ * You must pass in a GraphQL document with a single fragment or a document
883
+ * with multiple fragments that represent what you are reading. If you pass
884
+ * in a document with multiple fragments then you must also specify a
885
+ * `fragmentName`.
886
+ *
887
+ * @since 3.10.0
888
+ * @param options - An object of type `WatchFragmentOptions` that allows
889
+ * the cache to identify the fragment and optionally specify whether to react
890
+ * to optimistic updates.
891
+ */
892
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
893
+ from: NonNullable<ApolloCache.WatchFragmentFromValue<TData>>;
894
+ }): ApolloClient.ObservableFragment<TData>;
895
+ /**
896
+ * Watches the cache store of the fragment according to the options specified
897
+ * and returns an `Observable`. We can subscribe to this
898
+ * `Observable` and receive updated results through an
899
+ * observer when the cache store changes.
900
+ *
901
+ * You must pass in a GraphQL document with a single fragment or a document
902
+ * with multiple fragments that represent what you are reading. If you pass
903
+ * in a document with multiple fragments then you must also specify a
904
+ * `fragmentName`.
905
+ *
906
+ * @since 3.10.0
907
+ * @param options - An object of type `WatchFragmentOptions` that allows
908
+ * the cache to identify the fragment and optionally specify whether to react
909
+ * to optimistic updates.
910
+ */
911
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables>): ApolloClient.ObservableFragment<TData | null>;
823
912
  /**
824
913
  * Tries to read some data from the store in the shape of the provided
825
914
  * GraphQL fragment without making a network request. This method will read a
@@ -284,7 +284,7 @@ class ObservableQuery {
284
284
  // not be notified about future cache changes with an equal `diff`.
285
285
  // That would be the case if we are working with client-only fields
286
286
  // that are forced or with `exports` fields that might change, causing
287
- // local resovlers to return a new result.
287
+ // local resolvers to return a new result.
288
288
  // This is based on an implementation detail of `InMemoryCache`, which
289
289
  // is not optimal - but the only alternative to this would be to
290
290
  // resubscribe to the cache asynchonouly, which would bear the risk of
@@ -464,6 +464,9 @@ class ObservableQuery {
464
464
  finalize();
465
465
  }
466
466
  if (isCached) {
467
+ // Separately getting a diff here before the batch - `onWatchUpdated` might be
468
+ // called with an `undefined` `lastDiff` on the watcher if the cache was just subscribed to.
469
+ const lastDiff = this.getCacheDiff();
467
470
  // Performing this cache update inside a cache.batch transaction ensures
468
471
  // any affected cache.watch watchers are notified at most once about any
469
472
  // updates. Most watchers will be using the QueryInfo class, which
@@ -496,7 +499,8 @@ class ObservableQuery {
496
499
  }
497
500
  },
498
501
  onWatchUpdated: (watch, diff) => {
499
- if (watch.watcher === this) {
502
+ if (watch.watcher === this &&
503
+ !(0, equality_1.equal)(diff.result, lastDiff.result)) {
500
504
  wasUpdated = true;
501
505
  const lastResult = this.getCurrentResult();
502
506
  // Let the cache watch from resubscribeCache handle the final
@@ -1021,7 +1025,7 @@ class ObservableQuery {
1021
1025
  .then((result) => (0, internal_1.toQueryResult)(this.maskResult(result)))
1022
1026
  .finally(() => {
1023
1027
  if (!this.hasObservers() && this.activeOperations.size === 0) {
1024
- // If `reobserve` was called on a query without any obervers,
1028
+ // If `reobserve` was called on a query without any observers,
1025
1029
  // the teardown logic would never be called, so we need to
1026
1030
  // call it here to ensure the query is properly torn down.
1027
1031
  this.tearDownQuery();
@@ -1129,7 +1133,7 @@ class ObservableQuery {
1129
1133
  !this.activeOperations.size)) {
1130
1134
  const diff = this.getCacheDiff();
1131
1135
  if (
1132
- // `fromOptimisticTransaction` is not avaiable through the `cache.diff`
1136
+ // `fromOptimisticTransaction` is not available through the `cache.diff`
1133
1137
  // code path, so we need to check it this way
1134
1138
  (0, equality_1.equal)(diff.result, this.getCacheDiff({ optimistic: false }).result)) {
1135
1139
  //If this diff did not come from an optimistic transaction