@apollo/client 4.0.10 → 4.0.12-beta.0

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 (319) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/__cjs/cache/core/cache.cjs +216 -52
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +141 -25
  5. package/__cjs/cache/core/types/Cache.d.cts +77 -17
  6. package/__cjs/cache/index.cjs.map +1 -1
  7. package/__cjs/cache/index.d.cts +1 -1
  8. package/__cjs/cache/inmemory/entityStore.cjs +6 -4
  9. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  10. package/__cjs/cache/inmemory/helpers.d.cts +1 -1
  11. package/__cjs/cache/inmemory/inMemoryCache.cjs +62 -1
  12. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  13. package/__cjs/cache/inmemory/inMemoryCache.d.cts +48 -0
  14. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  15. package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
  16. package/__cjs/cache/inmemory/policies.cjs +56 -17
  17. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  18. package/__cjs/cache/inmemory/policies.d.cts +30 -6
  19. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  20. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  21. package/__cjs/cache/inmemory/types.d.cts +2 -0
  22. package/__cjs/cache/inmemory/writeToStore.cjs +24 -10
  23. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  24. package/__cjs/cache/inmemory/writeToStore.d.cts +2 -1
  25. package/__cjs/core/ApolloClient.cjs +31 -49
  26. package/__cjs/core/ApolloClient.cjs.map +1 -1
  27. package/__cjs/core/ApolloClient.d.cts +159 -18
  28. package/__cjs/core/ObservableQuery.cjs +173 -128
  29. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  30. package/__cjs/core/ObservableQuery.d.cts +2 -0
  31. package/__cjs/core/QueryInfo.cjs +9 -1
  32. package/__cjs/core/QueryInfo.cjs.map +1 -1
  33. package/__cjs/core/QueryInfo.d.cts +2 -1
  34. package/__cjs/core/QueryManager.cjs +47 -25
  35. package/__cjs/core/QueryManager.cjs.map +1 -1
  36. package/__cjs/core/QueryManager.d.cts +18 -2
  37. package/__cjs/incremental/handlers/defer20220824.cjs +44 -19
  38. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  39. package/__cjs/incremental/handlers/defer20220824.d.cts +15 -7
  40. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +222 -0
  41. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -0
  42. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +98 -0
  43. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  44. package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
  45. package/__cjs/incremental/index.cjs +3 -1
  46. package/__cjs/incremental/index.cjs.map +1 -1
  47. package/__cjs/incremental/index.d.cts +1 -0
  48. package/__cjs/incremental/types.d.cts +9 -0
  49. package/__cjs/invariantErrorCodes.cjs +83 -61
  50. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +13 -1
  51. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
  52. package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +1 -1
  53. package/__cjs/link/core/ApolloLink.cjs +3 -3
  54. package/__cjs/link/error/index.cjs +1 -1
  55. package/__cjs/link/error/index.cjs.map +1 -1
  56. package/__cjs/link/error/index.d.cts +1 -1
  57. package/__cjs/link/http/checkFetcher.cjs +1 -1
  58. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +2 -2
  59. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  60. package/__cjs/link/persisted-queries/index.cjs +2 -2
  61. package/__cjs/link/ws/index.cjs +1 -1
  62. package/__cjs/local-state/LocalState.cjs +28 -14
  63. package/__cjs/local-state/LocalState.cjs.map +1 -1
  64. package/__cjs/local-state/LocalState.d.cts +3 -2
  65. package/__cjs/masking/types.d.cts +2 -1
  66. package/__cjs/react/hooks/internal/useDeepMemo.cjs +2 -0
  67. package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
  68. package/__cjs/react/hooks/useBackgroundQuery.cjs +1 -3
  69. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  70. package/__cjs/react/hooks/useFragment.cjs +38 -87
  71. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  72. package/__cjs/react/hooks/useFragment.d.cts +65 -6
  73. package/__cjs/react/hooks/useLazyQuery.cjs +3 -0
  74. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  75. package/__cjs/react/hooks/useMutation.cjs +7 -1
  76. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  77. package/__cjs/react/hooks/useMutation.d.cts +13 -1
  78. package/__cjs/react/hooks/useQuery.cjs +8 -8
  79. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  80. package/__cjs/react/hooks/useQuery.d.cts +1 -1
  81. package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -3
  82. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  83. package/__cjs/react/hooks/useReadQuery.cjs +1 -3
  84. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  85. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  86. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  87. package/__cjs/react/hooks/useSuspenseFragment.cjs +16 -16
  88. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  89. package/__cjs/react/hooks/useSuspenseFragment.d.cts +33 -7
  90. package/__cjs/react/hooks/useSuspenseQuery.cjs +6 -4
  91. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  92. package/__cjs/react/internal/cache/FragmentReference.cjs +3 -22
  93. package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
  94. package/__cjs/react/internal/cache/FragmentReference.d.cts +2 -4
  95. package/__cjs/react/internal/cache/QueryReference.cjs +16 -0
  96. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  97. package/__cjs/react/internal/cache/QueryReference.d.cts +5 -0
  98. package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
  99. package/__cjs/react/internal/cache/SuspenseCache.d.cts +1 -1
  100. package/__cjs/react/internal/cache/types.d.cts +2 -2
  101. package/__cjs/react/query-preloader/createQueryPreloader.cjs +41 -1
  102. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  103. package/__cjs/react/ssr/useSSRQuery.cjs +1 -0
  104. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
  105. package/__cjs/utilities/DeepPartial.cjs.map +1 -1
  106. package/__cjs/utilities/DeepPartial.d.cts +1 -1
  107. package/__cjs/utilities/internal/DeepMerger.cjs +36 -4
  108. package/__cjs/utilities/internal/DeepMerger.cjs.map +1 -1
  109. package/__cjs/utilities/internal/DeepMerger.d.cts +20 -4
  110. package/__cjs/utilities/internal/combineLatestBatched.cjs +71 -0
  111. package/__cjs/utilities/internal/combineLatestBatched.cjs.map +1 -0
  112. package/__cjs/utilities/internal/combineLatestBatched.d.cts +14 -0
  113. package/__cjs/utilities/internal/constants.cjs +29 -0
  114. package/__cjs/utilities/internal/constants.cjs.map +1 -0
  115. package/__cjs/utilities/internal/constants.d.cts +26 -0
  116. package/__cjs/utilities/internal/getStoreKeyName.cjs +1 -0
  117. package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
  118. package/__cjs/utilities/internal/index.cjs +10 -2
  119. package/__cjs/utilities/internal/index.cjs.map +1 -1
  120. package/__cjs/utilities/internal/index.d.cts +4 -0
  121. package/__cjs/utilities/internal/mapObservableFragment.cjs +27 -0
  122. package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -0
  123. package/__cjs/utilities/internal/mapObservableFragment.d.cts +3 -0
  124. package/__cjs/utilities/internal/memoize.cjs +2 -2
  125. package/__cjs/utilities/internal/memoize.cjs.map +1 -1
  126. package/__cjs/utilities/internal/memoize.d.cts +2 -1
  127. package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs +61 -0
  128. package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs.map +1 -0
  129. package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.d.cts +11 -0
  130. package/__cjs/utilities/internal/ponyfills/index.cjs +6 -0
  131. package/__cjs/utilities/internal/ponyfills/index.cjs.map +1 -0
  132. package/__cjs/utilities/internal/ponyfills/index.d.cts +3 -0
  133. package/__cjs/utilities/internal/ponyfills/index.react-native.cjs +6 -0
  134. package/__cjs/utilities/internal/ponyfills/index.react-native.cjs.map +1 -0
  135. package/__cjs/utilities/internal/ponyfills/index.react-native.d.cts +2 -0
  136. package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs +3 -0
  137. package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs.map +1 -0
  138. package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.d.cts +24 -0
  139. package/__cjs/version.cjs +1 -1
  140. package/__cjs/version.cjs.map +1 -1
  141. package/cache/core/cache.d.ts +141 -25
  142. package/cache/core/cache.js +219 -55
  143. package/cache/core/cache.js.map +1 -1
  144. package/cache/core/types/Cache.d.ts +77 -17
  145. package/cache/core/types/Cache.js.map +1 -1
  146. package/cache/index.d.ts +1 -1
  147. package/cache/index.js.map +1 -1
  148. package/cache/inmemory/entityStore.js +6 -4
  149. package/cache/inmemory/entityStore.js.map +1 -1
  150. package/cache/inmemory/helpers.d.ts +1 -1
  151. package/cache/inmemory/inMemoryCache.d.ts +48 -0
  152. package/cache/inmemory/inMemoryCache.js +62 -1
  153. package/cache/inmemory/inMemoryCache.js.map +1 -1
  154. package/cache/inmemory/key-extractor.js +1 -1
  155. package/cache/inmemory/key-extractor.js.map +1 -1
  156. package/cache/inmemory/policies.d.ts +30 -6
  157. package/cache/inmemory/policies.js +45 -7
  158. package/cache/inmemory/policies.js.map +1 -1
  159. package/cache/inmemory/readFromStore.js +3 -3
  160. package/cache/inmemory/readFromStore.js.map +1 -1
  161. package/cache/inmemory/types.d.ts +2 -0
  162. package/cache/inmemory/types.js.map +1 -1
  163. package/cache/inmemory/writeToStore.d.ts +2 -1
  164. package/cache/inmemory/writeToStore.js +26 -12
  165. package/cache/inmemory/writeToStore.js.map +1 -1
  166. package/core/ApolloClient.d.ts +159 -18
  167. package/core/ApolloClient.js +32 -50
  168. package/core/ApolloClient.js.map +1 -1
  169. package/core/ObservableQuery.d.ts +2 -0
  170. package/core/ObservableQuery.js +176 -131
  171. package/core/ObservableQuery.js.map +1 -1
  172. package/core/QueryInfo.d.ts +2 -1
  173. package/core/QueryInfo.js +10 -2
  174. package/core/QueryInfo.js.map +1 -1
  175. package/core/QueryManager.d.ts +18 -2
  176. package/core/QueryManager.js +48 -26
  177. package/core/QueryManager.js.map +1 -1
  178. package/incremental/handlers/defer20220824.d.ts +15 -7
  179. package/incremental/handlers/defer20220824.js +44 -19
  180. package/incremental/handlers/defer20220824.js.map +1 -1
  181. package/incremental/handlers/graphql17Alpha9.d.ts +98 -0
  182. package/incremental/handlers/graphql17Alpha9.js +218 -0
  183. package/incremental/handlers/graphql17Alpha9.js.map +1 -0
  184. package/incremental/handlers/notImplemented.js +1 -1
  185. package/incremental/handlers/notImplemented.js.map +1 -1
  186. package/incremental/index.d.ts +1 -0
  187. package/incremental/index.js +3 -2
  188. package/incremental/index.js.map +1 -1
  189. package/incremental/types.d.ts +9 -0
  190. package/incremental/types.js.map +1 -1
  191. package/invariantErrorCodes.js +83 -61
  192. package/legacyEntryPoints/utilities/internal/ponyfills/index.d.ts +1 -0
  193. package/legacyEntryPoints/utilities/internal/ponyfills/index.js +1 -0
  194. package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.cjs +1 -0
  195. package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.d.cts +1 -0
  196. package/link/client-awareness/ClientAwarenessLink.d.ts +1 -1
  197. package/link/client-awareness/ClientAwarenessLink.js +13 -1
  198. package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
  199. package/link/core/ApolloLink.js +3 -3
  200. package/link/error/index.d.ts +1 -1
  201. package/link/error/index.js +1 -1
  202. package/link/error/index.js.map +1 -1
  203. package/link/http/checkFetcher.js +1 -1
  204. package/link/http/parseAndCheckHttpResponse.js +2 -2
  205. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  206. package/link/persisted-queries/index.js +2 -2
  207. package/link/ws/index.js +1 -1
  208. package/local-state/LocalState.d.ts +3 -2
  209. package/local-state/LocalState.js +28 -14
  210. package/local-state/LocalState.js.map +1 -1
  211. package/masking/types.d.ts +2 -1
  212. package/masking/types.js.map +1 -1
  213. package/package.json +15 -1
  214. package/react/hooks/internal/useDeepMemo.js +2 -0
  215. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  216. package/react/hooks/useBackgroundQuery.js +1 -3
  217. package/react/hooks/useBackgroundQuery.js.map +1 -1
  218. package/react/hooks/useFragment.d.ts +65 -6
  219. package/react/hooks/useFragment.js +38 -87
  220. package/react/hooks/useFragment.js.map +1 -1
  221. package/react/hooks/useLazyQuery.js +4 -1
  222. package/react/hooks/useLazyQuery.js.map +1 -1
  223. package/react/hooks/useMutation.d.ts +13 -1
  224. package/react/hooks/useMutation.js +7 -1
  225. package/react/hooks/useMutation.js.map +1 -1
  226. package/react/hooks/useQuery.js +9 -9
  227. package/react/hooks/useQuery.js.map +1 -1
  228. package/react/hooks/useQueryRefHandlers.js +1 -3
  229. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  230. package/react/hooks/useReadQuery.js +1 -3
  231. package/react/hooks/useReadQuery.js.map +1 -1
  232. package/react/hooks/useSubscription.js +1 -1
  233. package/react/hooks/useSubscription.js.map +1 -1
  234. package/react/hooks/useSuspenseFragment.d.ts +33 -7
  235. package/react/hooks/useSuspenseFragment.js +17 -17
  236. package/react/hooks/useSuspenseFragment.js.map +1 -1
  237. package/react/hooks/useSuspenseQuery.js +6 -4
  238. package/react/hooks/useSuspenseQuery.js.map +1 -1
  239. package/react/hooks-compiled/internal/useDeepMemo.js +2 -0
  240. package/react/hooks-compiled/internal/useDeepMemo.js.map +1 -1
  241. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js +0 -2
  242. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js.map +1 -1
  243. package/react/hooks-compiled/useBackgroundQuery.js +1 -3
  244. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  245. package/react/hooks-compiled/useFragment.d.ts +65 -6
  246. package/react/hooks-compiled/useFragment.js +110 -88
  247. package/react/hooks-compiled/useFragment.js.map +1 -1
  248. package/react/hooks-compiled/useLazyQuery.js +4 -1
  249. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  250. package/react/hooks-compiled/useLoadableQuery.js +69 -75
  251. package/react/hooks-compiled/useMutation.d.ts +13 -1
  252. package/react/hooks-compiled/useMutation.js +5 -13
  253. package/react/hooks-compiled/useMutation.js.map +1 -1
  254. package/react/hooks-compiled/useQuery.js +53 -61
  255. package/react/hooks-compiled/useQuery.js.map +1 -1
  256. package/react/hooks-compiled/useQueryRefHandlers.js +1 -5
  257. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  258. package/react/hooks-compiled/useReadQuery.js +77 -14
  259. package/react/hooks-compiled/useReadQuery.js.map +1 -1
  260. package/react/hooks-compiled/useSubscription.js +237 -93
  261. package/react/hooks-compiled/useSubscription.js.map +1 -1
  262. package/react/hooks-compiled/useSuspenseFragment.d.ts +33 -7
  263. package/react/hooks-compiled/useSuspenseFragment.js +17 -17
  264. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  265. package/react/hooks-compiled/useSuspenseQuery.js +7 -9
  266. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  267. package/react/index.compiled.d.ts +1 -1
  268. package/react/index.compiled.js +1 -1
  269. package/react/index.compiled.js.map +1 -1
  270. package/react/internal/cache/FragmentReference.d.ts +2 -4
  271. package/react/internal/cache/FragmentReference.js +3 -22
  272. package/react/internal/cache/FragmentReference.js.map +1 -1
  273. package/react/internal/cache/QueryReference.d.ts +5 -0
  274. package/react/internal/cache/QueryReference.js +16 -0
  275. package/react/internal/cache/QueryReference.js.map +1 -1
  276. package/react/internal/cache/SuspenseCache.d.ts +1 -1
  277. package/react/internal/cache/SuspenseCache.js.map +1 -1
  278. package/react/internal/cache/types.d.ts +2 -2
  279. package/react/internal/cache/types.js.map +1 -1
  280. package/react/query-preloader/createQueryPreloader.js +41 -1
  281. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  282. package/react/ssr/useSSRQuery.js +1 -0
  283. package/react/ssr/useSSRQuery.js.map +1 -1
  284. package/utilities/DeepPartial.d.ts +1 -1
  285. package/utilities/DeepPartial.js.map +1 -1
  286. package/utilities/internal/DeepMerger.d.ts +20 -4
  287. package/utilities/internal/DeepMerger.js +36 -4
  288. package/utilities/internal/DeepMerger.js.map +1 -1
  289. package/utilities/internal/combineLatestBatched.d.ts +14 -0
  290. package/utilities/internal/combineLatestBatched.js +68 -0
  291. package/utilities/internal/combineLatestBatched.js.map +1 -0
  292. package/utilities/internal/constants.d.ts +26 -0
  293. package/utilities/internal/constants.js +26 -0
  294. package/utilities/internal/constants.js.map +1 -0
  295. package/utilities/internal/getStoreKeyName.js +1 -0
  296. package/utilities/internal/getStoreKeyName.js.map +1 -1
  297. package/utilities/internal/index.d.ts +4 -0
  298. package/utilities/internal/index.js +3 -0
  299. package/utilities/internal/index.js.map +1 -1
  300. package/utilities/internal/mapObservableFragment.d.ts +3 -0
  301. package/utilities/internal/mapObservableFragment.js +24 -0
  302. package/utilities/internal/mapObservableFragment.js.map +1 -0
  303. package/utilities/internal/memoize.d.ts +2 -1
  304. package/utilities/internal/memoize.js +2 -2
  305. package/utilities/internal/memoize.js.map +1 -1
  306. package/utilities/internal/ponyfills/FinalizationRegistry.d.ts +11 -0
  307. package/utilities/internal/ponyfills/FinalizationRegistry.js +57 -0
  308. package/utilities/internal/ponyfills/FinalizationRegistry.js.map +1 -0
  309. package/utilities/internal/ponyfills/index.d.ts +3 -0
  310. package/utilities/internal/ponyfills/index.js +3 -0
  311. package/utilities/internal/ponyfills/index.js.map +1 -0
  312. package/utilities/internal/ponyfills/index.react-native.d.ts +2 -0
  313. package/utilities/internal/ponyfills/index.react-native.js +2 -0
  314. package/utilities/internal/ponyfills/index.react-native.js.map +1 -0
  315. package/utilities/internal/types/ExtensionsWithStreamDetails.d.ts +24 -0
  316. package/utilities/internal/types/ExtensionsWithStreamDetails.js +2 -0
  317. package/utilities/internal/types/ExtensionsWithStreamDetails.js.map +1 -0
  318. package/version.js +1 -1
  319. package/version.js.map +1 -1
@@ -0,0 +1,2 @@
1
+ export { FinalizationRegistry } from "./FinalizationRegistry.cjs";
2
+ //# sourceMappingURL=index.react-native.d.cts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ExtensionsWithStreamDetails.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionsWithStreamDetails.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,24 @@
1
+ import type { Trie } from "@wry/trie";
2
+ import type { Incremental } from "@apollo/client/incremental";
3
+ import type { streamDetailsSymbol } from "../constants.cjs";
4
+ /**
5
+ * @internal
6
+ *
7
+ * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
8
+ */
9
+ export interface ExtensionsWithStreamDetails extends Record<string, unknown> {
10
+ [streamDetailsSymbol]?: {
11
+ current: Trie<{
12
+ current: Incremental.StreamFieldInfo;
13
+ }>;
14
+ };
15
+ }
16
+ /**
17
+ * @internal
18
+ *
19
+ * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
20
+ */
21
+ export interface WithExtensionsWithStreamDetails {
22
+ extensions?: ExtensionsWithStreamDetails;
23
+ }
24
+ //# sourceMappingURL=ExtensionsWithStreamDetails.d.cts.map
package/__cjs/version.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = exports.version = void 0;
4
- exports.version = "4.0.10";
4
+ exports.version = "4.0.12-beta.0";
5
5
  exports.build = "cjs";
6
6
  //# sourceMappingURL=version.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,UAAwC;AAC3B,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,EAAA,OAAyD;"}
1
+ {"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,iBAAwC;AAC3B,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,EAAA,OAAyD;"}
@@ -1,14 +1,18 @@
1
1
  import type { DocumentNode, FragmentDefinitionNode, InlineFragmentNode } from "graphql";
2
2
  import { Observable } from "rxjs";
3
- import type { GetDataState, OperationVariables, TypedDocumentNode } from "@apollo/client";
3
+ import type { DataValue, GetDataState, OperationVariables, TypedDocumentNode } from "@apollo/client";
4
4
  import type { FragmentType, Unmasked } from "@apollo/client/masking";
5
5
  import type { Reference, StoreObject } from "@apollo/client/utilities";
6
- import type { NoInfer } from "@apollo/client/utilities/internal";
6
+ import type { IsAny, NoInfer, Prettify } from "@apollo/client/utilities/internal";
7
7
  import { getApolloCacheMemoryInternals } from "@apollo/client/utilities/internal";
8
8
  import type { Cache } from "./types/Cache.js";
9
9
  import type { MissingTree } from "./types/common.js";
10
10
  export type Transaction = (c: ApolloCache) => void;
11
11
  export declare namespace ApolloCache {
12
+ /**
13
+ * Acceptable values provided to the `from` option.
14
+ */
15
+ type FromOptionValue<TData> = StoreObject | Reference | FragmentType<NoInfer<TData>> | string;
12
16
  /**
13
17
  * Watched fragment options.
14
18
  */
@@ -28,7 +32,7 @@ export declare namespace ApolloCache {
28
32
  *
29
33
  * @docGroup 1. Required options
30
34
  */
31
- from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;
35
+ from: ApolloCache.FromOptionValue<TData> | Array<ApolloCache.FromOptionValue<TData> | null> | null;
32
36
  /**
33
37
  * Any variables that the GraphQL fragment may depend on.
34
38
  *
@@ -56,13 +60,51 @@ export declare namespace ApolloCache {
56
60
  /**
57
61
  * Watched fragment results.
58
62
  */
59
- type WatchFragmentResult<TData = unknown> = ({
63
+ type WatchFragmentResult<TData = unknown> = true extends IsAny<TData> ? ({
64
+ complete: true;
65
+ missing?: never;
66
+ } & GetDataState<any, "complete">) | ({
67
+ complete: false;
68
+ missing?: MissingTree;
69
+ } & GetDataState<any, "partial">) : TData extends null | null[] ? Prettify<{
70
+ complete: true;
71
+ missing?: never;
72
+ } & GetDataState<TData, "complete">> : Prettify<{
60
73
  complete: true;
61
74
  missing?: never;
62
- } & GetDataState<TData, "complete">) | ({
75
+ } & GetDataState<TData, "complete">> | {
63
76
  complete: false;
64
- missing: MissingTree;
65
- } & GetDataState<TData, "partial">);
77
+ missing?: MissingTree;
78
+ /**
79
+ * An object containing the result of your GraphQL query after it completes.
80
+ *
81
+ * This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
82
+ *
83
+ * @docGroup 1. Operation data
84
+ */
85
+ data: TData extends Array<infer TItem> ? Array<DataValue.Partial<TItem> | null> : DataValue.Partial<TData>;
86
+ /**
87
+ * Describes the completeness of `data`.
88
+ *
89
+ * - `empty`: No data could be fulfilled from the cache or the result is
90
+ * incomplete. `data` is `undefined`.
91
+ * - `partial`: Some data could be fulfilled from the cache but `data` is
92
+ * incomplete. This is only possible when `returnPartialData` is `true`.
93
+ * - `streaming`: `data` is incomplete as a result of a deferred query and
94
+ * the result is still streaming in.
95
+ * - `complete`: `data` is a fully satisfied query result fulfilled
96
+ * either from the cache or network.
97
+ *
98
+ * @docGroup 1. Operation data
99
+ */
100
+ dataState: "partial";
101
+ };
102
+ interface ObservableFragment<TData = unknown> extends Observable<ApolloCache.WatchFragmentResult<TData>> {
103
+ /**
104
+ * Return the current result for the fragment.
105
+ */
106
+ getCurrentResult: () => ApolloCache.WatchFragmentResult<TData>;
107
+ }
66
108
  }
67
109
  export declare abstract class ApolloCache {
68
110
  readonly assumeImmutableResults: boolean;
@@ -98,6 +140,72 @@ export declare abstract class ApolloCache {
98
140
  abstract removeOptimistic(id: string): void;
99
141
  abstract fragmentMatches(fragment: InlineFragmentNode | FragmentDefinitionNode, typename: string): boolean;
100
142
  lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
143
+ /**
144
+ * Determines whether a `@client` field can be resolved by the cache. Used
145
+ * when `LocalState` does not have a local resolver that can resolve the
146
+ * field.
147
+ *
148
+ * @remarks Cache implementations should return `true` if a mechanism in the
149
+ * cache is expected to provide a value for the field. `LocalState` will set
150
+ * the value of the field to `undefined` in order for the cache to handle it.
151
+ *
152
+ * Cache implementations should return `false` to indicate that it cannot
153
+ * handle resolving the field (either because it doesn't have a mechanism to
154
+ * do so, or because the user hasn't provided enough information to resolve
155
+ * the field). Returning `false` will emit a warning and set the value of the
156
+ * field to `null`.
157
+ *
158
+ * A cache that doesn't implement `resolvesClientField` will be treated the
159
+ * same as returning `false`.
160
+ */
161
+ resolvesClientField?(typename: string, fieldName: string): boolean;
162
+ /**
163
+ * Executes multiple cache operations as a single batch, ensuring that
164
+ * watchers are only notified once after all operations complete. This is
165
+ * useful for improving performance when making multiple cache updates, as it
166
+ * prevents unnecessary re-renders or query refetches between individual
167
+ * operations.
168
+ *
169
+ * The `batch` method supports both optimistic and non-optimistic updates, and
170
+ * provides fine-grained control over which cache layer receives the updates
171
+ * and when watchers are notified.
172
+ *
173
+ * For usage instructions, see [Interacting with cached data: `cache.batch`](https://www.apollographql.com/docs/react/caching/cache-interaction#using-cachebatch).
174
+ *
175
+ * @example
176
+ *
177
+ * ```js
178
+ * cache.batch({
179
+ * update(cache) {
180
+ * cache.writeQuery({
181
+ * query: GET_TODOS,
182
+ * data: { todos: updatedTodos },
183
+ * });
184
+ * cache.evict({ id: "Todo:123" });
185
+ * },
186
+ * });
187
+ * ```
188
+ *
189
+ * @example
190
+ *
191
+ * ```js
192
+ * // Optimistic update with a custom layer ID
193
+ * cache.batch({
194
+ * optimistic: "add-todo-optimistic",
195
+ * update(cache) {
196
+ * cache.modify({
197
+ * fields: {
198
+ * todos(existing = []) {
199
+ * return [...existing, newTodoRef];
200
+ * },
201
+ * },
202
+ * });
203
+ * },
204
+ * });
205
+ * ```
206
+ *
207
+ * @returns The return value of the `update` function.
208
+ */
101
209
  batch<U>(options: Cache.BatchOptions<this, U>): U;
102
210
  abstract performTransaction(transaction: Transaction, optimisticId?: string | null): void;
103
211
  recordOptimisticTransaction(transaction: Transaction, optimisticId: string): void;
@@ -119,28 +227,35 @@ export declare abstract class ApolloCache {
119
227
  * instead of passing it as a separate option.
120
228
  */
121
229
  optimistic: boolean): Unmasked<TData> | null;
230
+ private fragmentWatches;
231
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
232
+ from: Array<ApolloCache.FromOptionValue<TData>>;
233
+ }): ApolloCache.ObservableFragment<Array<Unmasked<TData>>>;
234
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
235
+ from: Array<null>;
236
+ }): ApolloCache.ObservableFragment<Array<null>>;
237
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
238
+ from: Array<ApolloCache.FromOptionValue<TData> | null>;
239
+ }): ApolloCache.ObservableFragment<Array<Unmasked<TData> | null>>;
240
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
241
+ from: null;
242
+ }): ApolloCache.ObservableFragment<null>;
243
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
244
+ from: ApolloCache.FromOptionValue<TData>;
245
+ }): ApolloCache.ObservableFragment<Unmasked<TData>>;
246
+ watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables>): ApolloCache.ObservableFragment<Unmasked<TData> | null>;
122
247
  /**
123
- * Watches the cache store of the fragment according to the options specified
124
- * and returns an `Observable`. We can subscribe to this
125
- * `Observable` and receive updated results through an
126
- * observer when the cache store changes.
127
- *
128
- * You must pass in a GraphQL document with a single fragment or a document
129
- * with multiple fragments that represent what you are reading. If you pass
130
- * in a document with multiple fragments then you must also specify a
131
- * `fragmentName`.
132
- *
133
- * @since 3.10.0
134
- * @param options - An object of type `WatchFragmentOptions` that allows
135
- * the cache to identify the fragment and optionally specify whether to react
136
- * to optimistic updates.
137
- */
138
- watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables>): Observable<ApolloCache.WatchFragmentResult<Unmasked<TData>>>;
248
+ * Can be overridden by subclasses to delay calling the provided callback
249
+ * until after all broadcasts have been completed - e.g. in a cache scenario
250
+ * where many watchers are notified in parallel.
251
+ */
252
+ protected onAfterBroadcast: (cb: () => void) => void;
253
+ private watchSingleFragment;
139
254
  private getFragmentDoc;
140
255
  /**
141
256
  * Read data from the cache for the specified fragment.
142
257
  */
143
- readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ fragment, variables, fragmentName, id, optimistic, returnPartialData, }: Cache.ReadFragmentOptions<TData, TVariables>): Unmasked<TData> | null;
258
+ readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ fragment, variables, fragmentName, id, from, optimistic, returnPartialData, }: Cache.ReadFragmentOptions<TData, TVariables>): Unmasked<TData> | null;
144
259
  readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.ReadFragmentOptions<TData, TVariables>,
145
260
  /**
146
261
  * @deprecated Pass the `optimistic` argument as part of the first argument
@@ -158,9 +273,10 @@ export declare abstract class ApolloCache {
158
273
  * fragment to validate that the shape of the data you’re writing to the cache
159
274
  * is the same as the shape of the data required by the fragment.
160
275
  */
161
- writeFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ data, fragment, fragmentName, variables, overwrite, id, broadcast, }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
276
+ writeFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ data, fragment, fragmentName, variables, overwrite, id, from, broadcast, }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
162
277
  updateQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.UpdateQueryOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
163
278
  updateFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.UpdateFragmentOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
279
+ private toCacheId;
164
280
  /**
165
281
  * @experimental
166
282
  * @internal
@@ -1,9 +1,11 @@
1
1
  import { WeakCache } from "@wry/caches";
2
+ import { equal } from "@wry/equality";
3
+ import { Trie } from "@wry/trie";
2
4
  import { wrap } from "optimism";
3
- import { Observable } from "rxjs";
4
- import { cacheSizes } from "@apollo/client/utilities";
5
+ import { distinctUntilChanged, map, Observable, ReplaySubject, share, shareReplay, tap, timer, } from "rxjs";
6
+ import { cacheSizes, canonicalStringify } from "@apollo/client/utilities";
5
7
  import { __DEV__ } from "@apollo/client/utilities/environment";
6
- import { equalByQuery, getApolloCacheMemoryInternals, getFragmentDefinition, getFragmentQueryDocument, } from "@apollo/client/utilities/internal";
8
+ import { combineLatestBatched, equalByQuery, getApolloCacheMemoryInternals, getFragmentDefinition, getFragmentQueryDocument, mapObservableFragmentMemoized, } from "@apollo/client/utilities/internal";
7
9
  import { invariant } from "@apollo/client/utilities/invariant";
8
10
  export class ApolloCache {
9
11
  assumeImmutableResults = false;
@@ -14,11 +16,53 @@ export class ApolloCache {
14
16
  return null;
15
17
  }
16
18
  // Transactional API
17
- // The batch method is intended to replace/subsume both performTransaction
18
- // and recordOptimisticTransaction, but performTransaction came first, so we
19
- // provide a default batch implementation that's just another way of calling
20
- // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can
21
- // override the batch method to do more interesting things with its options.
19
+ /**
20
+ * Executes multiple cache operations as a single batch, ensuring that
21
+ * watchers are only notified once after all operations complete. This is
22
+ * useful for improving performance when making multiple cache updates, as it
23
+ * prevents unnecessary re-renders or query refetches between individual
24
+ * operations.
25
+ *
26
+ * The `batch` method supports both optimistic and non-optimistic updates, and
27
+ * provides fine-grained control over which cache layer receives the updates
28
+ * and when watchers are notified.
29
+ *
30
+ * For usage instructions, see [Interacting with cached data: `cache.batch`](https://www.apollographql.com/docs/react/caching/cache-interaction#using-cachebatch).
31
+ *
32
+ * @example
33
+ *
34
+ * ```js
35
+ * cache.batch({
36
+ * update(cache) {
37
+ * cache.writeQuery({
38
+ * query: GET_TODOS,
39
+ * data: { todos: updatedTodos },
40
+ * });
41
+ * cache.evict({ id: "Todo:123" });
42
+ * },
43
+ * });
44
+ * ```
45
+ *
46
+ * @example
47
+ *
48
+ * ```js
49
+ * // Optimistic update with a custom layer ID
50
+ * cache.batch({
51
+ * optimistic: "add-todo-optimistic",
52
+ * update(cache) {
53
+ * cache.modify({
54
+ * fields: {
55
+ * todos(existing = []) {
56
+ * return [...existing, newTodoRef];
57
+ * },
58
+ * },
59
+ * });
60
+ * },
61
+ * });
62
+ * ```
63
+ *
64
+ * @returns The return value of the `update` function.
65
+ */
22
66
  batch(options) {
23
67
  const optimisticId = typeof options.optimistic === "string" ? options.optimistic
24
68
  : options.optimistic === false ? null
@@ -57,6 +101,7 @@ export class ApolloCache {
57
101
  optimistic,
58
102
  });
59
103
  }
104
+ fragmentWatches = new Trie(true);
60
105
  /**
61
106
  * Watches the cache store of the fragment according to the options specified
62
107
  * and returns an `Observable`. We can subscribe to this
@@ -74,61 +119,159 @@ export class ApolloCache {
74
119
  * to optimistic updates.
75
120
  */
76
121
  watchFragment(options) {
77
- const { fragment, fragmentName, from, optimistic = true, ...otherOptions } = options;
122
+ const { fragment, fragmentName, from } = options;
78
123
  const query = this.getFragmentDoc(fragment, fragmentName);
79
- // While our TypeScript types do not allow for `undefined` as a valid
80
- // `from`, its possible `useFragment` gives us an `undefined` since it
81
- // calls` cache.identify` and provides that value to `from`. We are
82
- // adding this fix here however to ensure those using plain JavaScript
83
- // and using `cache.identify` themselves will avoid seeing the obscure
84
- // warning.
85
- const id = typeof from === "undefined" || typeof from === "string" ?
86
- from
87
- : this.identify(from);
88
- if (__DEV__) {
89
- const actualFragmentName = fragmentName || getFragmentDefinition(fragment).name.value;
90
- if (!id) {
91
- __DEV__ && invariant.warn(109, actualFragmentName);
124
+ const fromArray = Array.isArray(from) ? from : [from];
125
+ const ids = fromArray.map((value) => {
126
+ // While our TypeScript types do not allow for `undefined` as a valid
127
+ // `from`, its possible `useFragment` gives us an `undefined` since it
128
+ // calls` cache.identify` and provides that value to `from`. We are
129
+ // adding this fix here however to ensure those using plain JavaScript
130
+ // and using `cache.identify` themselves will avoid seeing the obscure
131
+ // warning.
132
+ const id = value == null ? value : this.toCacheId(value);
133
+ if (__DEV__) {
134
+ const actualFragmentName = fragmentName || getFragmentDefinition(fragment).name.value;
135
+ if (id === undefined) {
136
+ __DEV__ && invariant.warn(113, actualFragmentName);
137
+ }
92
138
  }
139
+ return id;
140
+ });
141
+ if (!Array.isArray(from)) {
142
+ const observable = this.watchSingleFragment(ids[0], query, options);
143
+ // Unfortunately we forgot to allow for `null` on watchFragment in 4.0
144
+ // when `from` is a single record. As such, we need to fallback to {}
145
+ // when diff.result is null to maintain backwards compatibility. We
146
+ // should plan to change this in v5. We do however support `null` if
147
+ // `from` is explicitly `null`.
148
+ //
149
+ // NOTE: Using `from` with an array will maintain `null` properly
150
+ // without the need for a similar fallback since watchFragment with
151
+ // arrays is new functionality in v4.1.
152
+ return from === null ? observable : (mapObservableFragmentMemoized(observable, Symbol.for("apollo.transform.individualResult"), (result) => ({
153
+ ...result,
154
+ data: result.data ?? {},
155
+ })));
93
156
  }
94
- const diffOptions = {
95
- ...otherOptions,
96
- returnPartialData: true,
97
- id,
98
- query,
99
- optimistic,
100
- };
101
- let latestDiff;
102
- return new Observable((observer) => {
103
- return this.watch({
104
- ...diffOptions,
105
- immediate: true,
106
- callback: (diff) => {
107
- let data = diff.result;
108
- // TODO: Remove this once `watchFragment` supports `null` as valid
109
- // value emitted
110
- if (data === null) {
111
- data = {};
112
- }
113
- if (
114
- // Always ensure we deliver the first result
115
- latestDiff &&
116
- equalByQuery(query, { data: latestDiff.result }, { data }, options.variables)) {
117
- return;
118
- }
119
- const result = {
157
+ let currentResult;
158
+ function toResult(results) {
159
+ const result = results.reduce((memo, result, idx) => {
160
+ memo.data.push(result.data);
161
+ memo.complete &&= result.complete;
162
+ memo.dataState = memo.complete ? "complete" : "partial";
163
+ if (result.missing) {
164
+ memo.missing ||= {};
165
+ memo.missing[idx] = result.missing;
166
+ }
167
+ return memo;
168
+ }, {
169
+ data: [],
170
+ dataState: "complete",
171
+ complete: true,
172
+ });
173
+ if (!equal(currentResult, result)) {
174
+ currentResult = result;
175
+ }
176
+ return currentResult;
177
+ }
178
+ if (ids.length === 0) {
179
+ return emptyArrayObservable;
180
+ }
181
+ let subscribed = false;
182
+ const observables = ids.map((id) => this.watchSingleFragment(id, query, options));
183
+ const observable = combineLatestBatched(observables).pipe(map(toResult), tap({
184
+ subscribe: () => (subscribed = true),
185
+ unsubscribe: () => (subscribed = false),
186
+ }), shareReplay({ bufferSize: 1, refCount: true }));
187
+ return Object.assign(observable, {
188
+ getCurrentResult: () => {
189
+ if (subscribed && currentResult) {
190
+ return currentResult;
191
+ }
192
+ const results = observables.map((observable) => observable.getCurrentResult());
193
+ return toResult(results);
194
+ },
195
+ });
196
+ }
197
+ /**
198
+ * Can be overridden by subclasses to delay calling the provided callback
199
+ * until after all broadcasts have been completed - e.g. in a cache scenario
200
+ * where many watchers are notified in parallel.
201
+ */
202
+ onAfterBroadcast = (cb) => cb();
203
+ watchSingleFragment(id, fragmentQuery, options) {
204
+ if (id === null) {
205
+ return nullObservable;
206
+ }
207
+ const { optimistic = true, variables } = options;
208
+ const cacheKey = [
209
+ fragmentQuery,
210
+ canonicalStringify({ id, optimistic, variables }),
211
+ ];
212
+ const cacheEntry = this.fragmentWatches.lookupArray(cacheKey);
213
+ if (!cacheEntry.observable) {
214
+ let subscribed = false;
215
+ let currentResult;
216
+ function getNewestResult(diff) {
217
+ const data = diff.result;
218
+ if (!currentResult ||
219
+ !equalByQuery(fragmentQuery, { data: currentResult.data }, { data }, options.variables)) {
220
+ currentResult = {
120
221
  data,
121
222
  dataState: diff.complete ? "complete" : "partial",
122
- complete: !!diff.complete,
223
+ complete: diff.complete,
123
224
  };
124
225
  if (diff.missing) {
125
- result.missing = diff.missing.missing;
226
+ currentResult.missing = diff.missing.missing;
126
227
  }
127
- latestDiff = { ...diff, result: data };
128
- observer.next(result);
228
+ }
229
+ return currentResult;
230
+ }
231
+ const observable = new Observable((observer) => {
232
+ subscribed = true;
233
+ const cleanup = this.watch({
234
+ variables,
235
+ returnPartialData: true,
236
+ id,
237
+ query: fragmentQuery,
238
+ optimistic,
239
+ immediate: true,
240
+ callback: (diff) => {
241
+ observable.dirty = true;
242
+ this.onAfterBroadcast(() => {
243
+ observer.next(getNewestResult(diff));
244
+ observable.dirty = false;
245
+ });
246
+ },
247
+ });
248
+ return () => {
249
+ subscribed = false;
250
+ cleanup();
251
+ this.fragmentWatches.removeArray(cacheKey);
252
+ };
253
+ }).pipe(distinctUntilChanged(), share({
254
+ connector: () => new ReplaySubject(1),
255
+ // debounce so a synchronous unsubscribe+resubscribe doesn't tear down the watch and create a new one
256
+ resetOnRefCountZero: () => timer(0),
257
+ }));
258
+ cacheEntry.observable = Object.assign(observable, {
259
+ dirty: false,
260
+ getCurrentResult: () => {
261
+ if (subscribed && currentResult) {
262
+ return currentResult;
263
+ }
264
+ return getNewestResult(this.diff({
265
+ id,
266
+ query: fragmentQuery,
267
+ returnPartialData: true,
268
+ optimistic,
269
+ variables,
270
+ }));
129
271
  },
130
272
  });
131
- });
273
+ }
274
+ return cacheEntry.observable;
132
275
  }
133
276
  // Make sure we compute the same (===) fragment query document every
134
277
  // time we receive the same fragment in readFragment.
@@ -138,10 +281,11 @@ export class ApolloCache {
138
281
  cache: WeakCache,
139
282
  });
140
283
  readFragment(options, optimistic = !!options.optimistic) {
284
+ const id = options.from !== undefined ? this.toCacheId(options.from) : options.id;
141
285
  return this.read({
142
286
  ...options,
143
287
  query: this.getFragmentDoc(options.fragment, options.fragmentName),
144
- rootId: options.id,
288
+ rootId: id,
145
289
  optimistic,
146
290
  });
147
291
  }
@@ -151,7 +295,8 @@ export class ApolloCache {
151
295
  result: data,
152
296
  }));
153
297
  }
154
- writeFragment({ id, data, fragment, fragmentName, ...options }) {
298
+ writeFragment({ data, fragment, fragmentName, ...options }) {
299
+ const id = options.from !== undefined ? this.toCacheId(options.from) : options.id;
155
300
  return this.write(Object.assign(options, {
156
301
  query: this.getFragmentDoc(fragment, fragmentName),
157
302
  dataId: id,
@@ -182,8 +327,27 @@ export class ApolloCache {
182
327
  },
183
328
  });
184
329
  }
330
+ toCacheId(from) {
331
+ return typeof from === "string" ? from : this.identify(from);
332
+ }
185
333
  }
186
334
  if (__DEV__) {
187
335
  ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;
188
336
  }
337
+ const nullResult = Object.freeze({
338
+ data: null,
339
+ dataState: "complete",
340
+ complete: true,
341
+ });
342
+ const nullObservable = Object.assign(new Observable((observer) => {
343
+ observer.next(nullResult);
344
+ }), { dirty: false, getCurrentResult: () => nullResult });
345
+ const emptyArrayResult = Object.freeze({
346
+ data: [],
347
+ dataState: "complete",
348
+ complete: true,
349
+ });
350
+ const emptyArrayObservable = Object.assign(new Observable((observer) => {
351
+ observer.next(emptyArrayResult);
352
+ }), { getCurrentResult: () => emptyArrayResult });
189
353
  //# sourceMappingURL=cache.js.map