@apollo/client 4.3.0-alpha.1 → 4.3.0-alpha.11

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 (416) hide show
  1. package/CHANGELOG.md +503 -0
  2. package/README.md +3 -7
  3. package/__cjs/cache/core/Scalar.cjs +36 -0
  4. package/__cjs/cache/core/Scalar.cjs.map +1 -0
  5. package/__cjs/cache/core/Scalar.d.cts +19 -0
  6. package/__cjs/cache/core/cache.cjs +32 -1
  7. package/__cjs/cache/core/cache.cjs.map +1 -1
  8. package/__cjs/cache/core/cache.d.cts +89 -6
  9. package/__cjs/cache/core/types/Cache.d.cts +25 -0
  10. package/__cjs/cache/index.cjs +3 -1
  11. package/__cjs/cache/index.cjs.map +1 -1
  12. package/__cjs/cache/index.d.cts +3 -2
  13. package/__cjs/cache/inmemory/entityStore.cjs +48 -5
  14. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  15. package/__cjs/cache/inmemory/entityStore.d.cts +3 -0
  16. package/__cjs/cache/inmemory/helpers.d.cts +9 -1
  17. package/__cjs/cache/inmemory/inMemoryCache.cjs +83 -4
  18. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  19. package/__cjs/cache/inmemory/inMemoryCache.d.cts +44 -5
  20. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  21. package/__cjs/cache/inmemory/policies.cjs +35 -6
  22. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  23. package/__cjs/cache/inmemory/policies.d.cts +4 -1
  24. package/__cjs/cache/inmemory/readFromStore.cjs +490 -49
  25. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  26. package/__cjs/cache/inmemory/readFromStore.d.cts +11 -2
  27. package/__cjs/cache/inmemory/types.d.cts +29 -4
  28. package/__cjs/cache/inmemory/writeToStore.cjs +6 -6
  29. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  30. package/__cjs/core/ApolloClient.cjs +37 -38
  31. package/__cjs/core/ApolloClient.cjs.map +1 -1
  32. package/__cjs/core/ApolloClient.d.cts +44 -10
  33. package/__cjs/core/ObservableQuery.cjs +228 -76
  34. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  35. package/__cjs/core/ObservableQuery.d.cts +16 -8
  36. package/__cjs/core/QueryInfo.cjs +178 -190
  37. package/__cjs/core/QueryInfo.cjs.map +1 -1
  38. package/__cjs/core/QueryInfo.d.cts +16 -21
  39. package/__cjs/core/QueryManager.cjs +88 -59
  40. package/__cjs/core/QueryManager.cjs.map +1 -1
  41. package/__cjs/core/QueryManager.d.cts +1 -3
  42. package/__cjs/core/RefetchEventManager.cjs +3 -3
  43. package/__cjs/core/dataStateErrorCache.cjs +12 -0
  44. package/__cjs/core/dataStateErrorCache.cjs.map +1 -0
  45. package/__cjs/core/dataStateErrorCache.d.cts +3 -0
  46. package/__cjs/core/index.cjs +2 -1
  47. package/__cjs/core/index.cjs.map +1 -1
  48. package/__cjs/core/index.d.cts +4 -3
  49. package/__cjs/core/types.d.cts +10 -3
  50. package/__cjs/incremental/GraphQLCodegenIncremental.cjs +3 -0
  51. package/__cjs/incremental/GraphQLCodegenIncremental.cjs.map +1 -0
  52. package/__cjs/incremental/GraphQLCodegenIncremental.d.cts +55 -0
  53. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  54. package/__cjs/incremental/handlers/defer20220824.d.cts +2 -4
  55. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +47 -16
  56. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  57. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +29 -6
  58. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  59. package/__cjs/incremental/index.cjs.map +1 -1
  60. package/__cjs/incremental/index.d.cts +1 -0
  61. package/__cjs/{utilities/internal/types/NoInfer.cjs → incremental/internal/types.cjs} +1 -1
  62. package/__cjs/incremental/internal/types.cjs.map +1 -0
  63. package/__cjs/incremental/internal/types.d.cts +17 -0
  64. package/__cjs/incremental/types.d.cts +55 -4
  65. package/__cjs/invariantErrorCodes.cjs +167 -112
  66. package/__cjs/link/core/ApolloLink.cjs +3 -3
  67. package/__cjs/link/http/checkFetcher.cjs +1 -1
  68. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +2 -2
  69. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  70. package/__cjs/link/persisted-queries/index.cjs +2 -2
  71. package/__cjs/link/ws/index.cjs +1 -1
  72. package/__cjs/local-state/LocalState.cjs +11 -11
  73. package/__cjs/local-state/LocalState.cjs.map +1 -1
  74. package/__cjs/local-state/LocalState.d.cts +1 -1
  75. package/__cjs/masking/internal/types.d.cts +1 -2
  76. package/__cjs/masking/maskDefinition.cjs +2 -2
  77. package/__cjs/masking/maskFragment.cjs +2 -2
  78. package/__cjs/masking/maskOperation.cjs +1 -1
  79. package/__cjs/masking/utils.cjs +3 -3
  80. package/__cjs/react/context/ApolloContext.cjs +1 -1
  81. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  82. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
  83. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  84. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  85. package/__cjs/react/hooks/useBackgroundQuery.d.cts +100 -47
  86. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  87. package/__cjs/react/hooks/useFragment.d.cts +0 -1
  88. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  89. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  90. package/__cjs/react/hooks/useLazyQuery.d.cts +40 -34
  91. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  92. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  93. package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
  94. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  95. package/__cjs/react/hooks/useMutation.d.cts +10 -7
  96. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  97. package/__cjs/react/hooks/useQuery.d.cts +74 -32
  98. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  99. package/__cjs/react/hooks/useSubscription.cjs +7 -3
  100. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  101. package/__cjs/react/hooks/useSubscription.d.cts +7 -4
  102. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  103. package/__cjs/react/hooks/useSuspenseFragment.d.cts +1 -1
  104. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  105. package/__cjs/react/hooks/useSuspenseQuery.d.cts +83 -34
  106. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  107. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  108. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  109. package/__cjs/react/internal/types.d.cts +14 -3
  110. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  111. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
  112. package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
  113. package/__cjs/testing/core/mocking/mockLink.cjs +25 -5
  114. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  115. package/__cjs/testing/core/mocking/mockLink.d.cts +1 -2
  116. package/__cjs/utilities/caching/sizes.cjs.map +1 -1
  117. package/__cjs/utilities/caching/sizes.d.cts +39 -1
  118. package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
  119. package/__cjs/utilities/index.cjs.map +1 -1
  120. package/__cjs/utilities/index.d.cts +1 -0
  121. package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
  122. package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
  123. package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
  124. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs +33 -0
  125. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs.map +1 -0
  126. package/__cjs/utilities/internal/addDeferFragmentLabels.d.cts +3 -0
  127. package/__cjs/utilities/internal/capitalize.cjs +12 -0
  128. package/__cjs/utilities/internal/capitalize.cjs.map +1 -0
  129. package/__cjs/utilities/internal/capitalize.d.cts +7 -0
  130. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs +69 -0
  131. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs.map +1 -0
  132. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.d.cts +9 -0
  133. package/__cjs/utilities/internal/constants.cjs +20 -1
  134. package/__cjs/utilities/internal/constants.cjs.map +1 -1
  135. package/__cjs/utilities/internal/constants.d.cts +19 -0
  136. package/__cjs/utilities/internal/getDirectiveArgValue.cjs +19 -0
  137. package/__cjs/utilities/internal/getDirectiveArgValue.cjs.map +1 -0
  138. package/__cjs/utilities/internal/getDirectiveArgValue.d.cts +9 -0
  139. package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
  140. package/__cjs/utilities/internal/getFragmentFromSelection.cjs +2 -2
  141. package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
  142. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +2 -2
  143. package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
  144. package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
  145. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  146. package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
  147. package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
  148. package/__cjs/utilities/internal/getUnwrappedType.cjs +20 -0
  149. package/__cjs/utilities/internal/getUnwrappedType.cjs.map +1 -0
  150. package/__cjs/utilities/internal/getUnwrappedType.d.cts +8 -0
  151. package/__cjs/utilities/internal/index.cjs +25 -2
  152. package/__cjs/utilities/internal/index.cjs.map +1 -1
  153. package/__cjs/utilities/internal/index.d.cts +16 -2
  154. package/__cjs/utilities/internal/isDeferredFragment.cjs +38 -0
  155. package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -0
  156. package/__cjs/utilities/internal/isDeferredFragment.d.cts +9 -0
  157. package/__cjs/utilities/internal/isStreamField.cjs +37 -0
  158. package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
  159. package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
  160. package/__cjs/utilities/internal/isTypenameField.cjs +7 -0
  161. package/__cjs/utilities/internal/isTypenameField.cjs.map +1 -0
  162. package/__cjs/utilities/internal/isTypenameField.d.cts +3 -0
  163. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
  164. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
  165. package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
  166. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
  167. package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
  168. package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
  169. package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
  170. package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
  171. package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
  172. package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
  173. package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
  174. package/__cjs/utilities/internal/types/Exact.cjs +3 -0
  175. package/__cjs/utilities/internal/types/Exact.cjs.map +1 -0
  176. package/__cjs/utilities/internal/types/Exact.d.cts +2 -0
  177. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs +3 -0
  178. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs.map +1 -0
  179. package/__cjs/utilities/internal/types/IsLooselyEqual.d.cts +10 -0
  180. package/__cjs/utilities/internal/types/IsNeverish.cjs +3 -0
  181. package/__cjs/utilities/internal/types/IsNeverish.cjs.map +1 -0
  182. package/__cjs/utilities/internal/types/IsNeverish.d.cts +4 -0
  183. package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
  184. package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
  185. package/__cjs/utilities/policies/pagination.cjs.map +1 -1
  186. package/__cjs/utilities/policies/pagination.d.cts +1 -1
  187. package/__cjs/utilities/subscriptions/relay/index.cjs +1 -0
  188. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  189. package/__cjs/version.cjs +1 -1
  190. package/__cjs/version.cjs.map +1 -1
  191. package/cache/core/Scalar.d.ts +19 -0
  192. package/cache/core/Scalar.js +32 -0
  193. package/cache/core/Scalar.js.map +1 -0
  194. package/cache/core/cache.d.ts +89 -6
  195. package/cache/core/cache.js +33 -2
  196. package/cache/core/cache.js.map +1 -1
  197. package/cache/core/types/Cache.d.ts +25 -0
  198. package/cache/core/types/Cache.js.map +1 -1
  199. package/cache/index.d.ts +3 -2
  200. package/cache/index.js +1 -0
  201. package/cache/index.js.map +1 -1
  202. package/cache/inmemory/entityStore.d.ts +3 -0
  203. package/cache/inmemory/entityStore.js +49 -6
  204. package/cache/inmemory/entityStore.js.map +1 -1
  205. package/cache/inmemory/helpers.d.ts +9 -1
  206. package/cache/inmemory/inMemoryCache.d.ts +44 -5
  207. package/cache/inmemory/inMemoryCache.js +84 -5
  208. package/cache/inmemory/inMemoryCache.js.map +1 -1
  209. package/cache/inmemory/key-extractor.js +1 -1
  210. package/cache/inmemory/policies.d.ts +4 -1
  211. package/cache/inmemory/policies.js +35 -6
  212. package/cache/inmemory/policies.js.map +1 -1
  213. package/cache/inmemory/readFromStore.d.ts +11 -2
  214. package/cache/inmemory/readFromStore.js +486 -49
  215. package/cache/inmemory/readFromStore.js.map +1 -1
  216. package/cache/inmemory/types.d.ts +30 -5
  217. package/cache/inmemory/types.js.map +1 -1
  218. package/cache/inmemory/writeToStore.js +7 -7
  219. package/cache/inmemory/writeToStore.js.map +1 -1
  220. package/core/ApolloClient.d.ts +44 -10
  221. package/core/ApolloClient.js +37 -38
  222. package/core/ApolloClient.js.map +1 -1
  223. package/core/ObservableQuery.d.ts +16 -8
  224. package/core/ObservableQuery.js +225 -77
  225. package/core/ObservableQuery.js.map +1 -1
  226. package/core/QueryInfo.d.ts +17 -22
  227. package/core/QueryInfo.js +174 -190
  228. package/core/QueryInfo.js.map +1 -1
  229. package/core/QueryManager.d.ts +1 -3
  230. package/core/QueryManager.js +89 -60
  231. package/core/QueryManager.js.map +1 -1
  232. package/core/RefetchEventManager.js +3 -3
  233. package/core/dataStateErrorCache.d.ts +3 -0
  234. package/core/dataStateErrorCache.js +9 -0
  235. package/core/dataStateErrorCache.js.map +1 -0
  236. package/core/index.d.ts +4 -3
  237. package/core/index.js +1 -1
  238. package/core/index.js.map +1 -1
  239. package/core/types.d.ts +10 -3
  240. package/core/types.js.map +1 -1
  241. package/incremental/GraphQLCodegenIncremental.d.ts +55 -0
  242. package/incremental/GraphQLCodegenIncremental.js +2 -0
  243. package/incremental/GraphQLCodegenIncremental.js.map +1 -0
  244. package/incremental/handlers/defer20220824.d.ts +2 -4
  245. package/incremental/handlers/defer20220824.js.map +1 -1
  246. package/incremental/handlers/graphql17Alpha9.d.ts +29 -6
  247. package/incremental/handlers/graphql17Alpha9.js +48 -17
  248. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  249. package/incremental/handlers/notImplemented.js +1 -1
  250. package/incremental/index.d.ts +1 -0
  251. package/incremental/index.js.map +1 -1
  252. package/incremental/internal/types.d.ts +17 -0
  253. package/incremental/internal/types.js +2 -0
  254. package/incremental/internal/types.js.map +1 -0
  255. package/incremental/types.d.ts +55 -4
  256. package/incremental/types.js.map +1 -1
  257. package/invariantErrorCodes.js +167 -112
  258. package/link/core/ApolloLink.js +3 -3
  259. package/link/http/checkFetcher.js +1 -1
  260. package/link/http/parseAndCheckHttpResponse.js +2 -2
  261. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  262. package/link/persisted-queries/index.js +2 -2
  263. package/link/ws/index.js +1 -1
  264. package/local-state/LocalState.d.ts +1 -1
  265. package/local-state/LocalState.js +11 -11
  266. package/local-state/LocalState.js.map +1 -1
  267. package/masking/internal/types.d.ts +1 -2
  268. package/masking/internal/types.js.map +1 -1
  269. package/masking/maskDefinition.js +2 -2
  270. package/masking/maskFragment.js +2 -2
  271. package/masking/maskOperation.js +1 -1
  272. package/masking/utils.js +3 -3
  273. package/package.json +1 -1
  274. package/react/context/ApolloContext.js +1 -1
  275. package/react/context/ApolloProvider.js +1 -1
  276. package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
  277. package/react/hooks/useApolloClient.js +1 -1
  278. package/react/hooks/useBackgroundQuery.d.ts +100 -47
  279. package/react/hooks/useBackgroundQuery.js.map +1 -1
  280. package/react/hooks/useFragment.d.ts +0 -1
  281. package/react/hooks/useFragment.js.map +1 -1
  282. package/react/hooks/useLazyQuery.d.ts +40 -34
  283. package/react/hooks/useLazyQuery.js +2 -2
  284. package/react/hooks/useLazyQuery.js.map +1 -1
  285. package/react/hooks/useLoadableQuery.d.ts +23 -15
  286. package/react/hooks/useLoadableQuery.js +2 -2
  287. package/react/hooks/useLoadableQuery.js.map +1 -1
  288. package/react/hooks/useMutation.d.ts +10 -7
  289. package/react/hooks/useMutation.js.map +1 -1
  290. package/react/hooks/useQuery.d.ts +74 -32
  291. package/react/hooks/useQuery.js.map +1 -1
  292. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  293. package/react/hooks/useSubscription.d.ts +7 -4
  294. package/react/hooks/useSubscription.js +7 -3
  295. package/react/hooks/useSubscription.js.map +1 -1
  296. package/react/hooks/useSuspenseFragment.d.ts +1 -1
  297. package/react/hooks/useSuspenseFragment.js.map +1 -1
  298. package/react/hooks/useSuspenseQuery.d.ts +83 -34
  299. package/react/hooks/useSuspenseQuery.js.map +1 -1
  300. package/react/hooks/useSyncExternalStore.js +1 -1
  301. package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
  302. package/react/hooks-compiled/useApolloClient.js +1 -1
  303. package/react/hooks-compiled/useBackgroundQuery.d.ts +100 -47
  304. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  305. package/react/hooks-compiled/useFragment.d.ts +0 -1
  306. package/react/hooks-compiled/useFragment.js.map +1 -1
  307. package/react/hooks-compiled/useLazyQuery.d.ts +40 -34
  308. package/react/hooks-compiled/useLazyQuery.js +2 -2
  309. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  310. package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
  311. package/react/hooks-compiled/useLoadableQuery.js +2 -2
  312. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  313. package/react/hooks-compiled/useMutation.d.ts +10 -7
  314. package/react/hooks-compiled/useMutation.js.map +1 -1
  315. package/react/hooks-compiled/useQuery.d.ts +74 -32
  316. package/react/hooks-compiled/useQuery.js.map +1 -1
  317. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  318. package/react/hooks-compiled/useSubscription.d.ts +7 -4
  319. package/react/hooks-compiled/useSubscription.js +107 -93
  320. package/react/hooks-compiled/useSubscription.js.map +1 -1
  321. package/react/hooks-compiled/useSuspenseFragment.d.ts +1 -1
  322. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  323. package/react/hooks-compiled/useSuspenseQuery.d.ts +83 -34
  324. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  325. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  326. package/react/internal/cache/QueryReference.js +1 -1
  327. package/react/internal/cache/QueryReference.js.map +1 -1
  328. package/react/internal/types.d.ts +15 -4
  329. package/react/internal/types.js.map +1 -1
  330. package/react/query-preloader/createQueryPreloader.d.ts +20 -5
  331. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  332. package/react/ssr/prerenderStatic.js +2 -2
  333. package/testing/core/mocking/mockLink.d.ts +1 -2
  334. package/testing/core/mocking/mockLink.js +25 -5
  335. package/testing/core/mocking/mockLink.js.map +1 -1
  336. package/utilities/caching/sizes.d.ts +39 -1
  337. package/utilities/caching/sizes.js.map +1 -1
  338. package/utilities/graphql/DocumentTransform.js +1 -1
  339. package/utilities/index.d.ts +1 -0
  340. package/utilities/index.js.map +1 -1
  341. package/utilities/internal/StreamArrayState.d.ts +12 -0
  342. package/utilities/internal/StreamArrayState.js +23 -0
  343. package/utilities/internal/StreamArrayState.js.map +1 -0
  344. package/utilities/internal/addDeferFragmentLabels.d.ts +3 -0
  345. package/utilities/internal/addDeferFragmentLabels.js +30 -0
  346. package/utilities/internal/addDeferFragmentLabels.js.map +1 -0
  347. package/utilities/internal/capitalize.d.ts +7 -0
  348. package/utilities/internal/capitalize.js +9 -0
  349. package/utilities/internal/capitalize.js.map +1 -0
  350. package/utilities/internal/coerceScalarFieldsToParsed.d.ts +9 -0
  351. package/utilities/internal/coerceScalarFieldsToParsed.js +66 -0
  352. package/utilities/internal/coerceScalarFieldsToParsed.js.map +1 -0
  353. package/utilities/internal/constants.d.ts +19 -0
  354. package/utilities/internal/constants.js +19 -0
  355. package/utilities/internal/constants.js.map +1 -1
  356. package/utilities/internal/getDirectiveArgValue.d.ts +9 -0
  357. package/utilities/internal/getDirectiveArgValue.js +16 -0
  358. package/utilities/internal/getDirectiveArgValue.js.map +1 -0
  359. package/utilities/internal/getFragmentDefinition.js +3 -3
  360. package/utilities/internal/getFragmentFromSelection.js +2 -2
  361. package/utilities/internal/getFragmentFromSelection.js.map +1 -1
  362. package/utilities/internal/getFragmentQueryDocument.js +2 -2
  363. package/utilities/internal/getMainDefinition.js +1 -1
  364. package/utilities/internal/getMemoryInternals.d.ts +4 -0
  365. package/utilities/internal/getMemoryInternals.js +6 -0
  366. package/utilities/internal/getMemoryInternals.js.map +1 -1
  367. package/utilities/internal/getQueryDefinition.js +1 -1
  368. package/utilities/internal/getUnwrappedType.d.ts +8 -0
  369. package/utilities/internal/getUnwrappedType.js +17 -0
  370. package/utilities/internal/getUnwrappedType.js.map +1 -0
  371. package/utilities/internal/index.d.ts +16 -2
  372. package/utilities/internal/index.js +12 -1
  373. package/utilities/internal/index.js.map +1 -1
  374. package/utilities/internal/isDeferredFragment.d.ts +9 -0
  375. package/utilities/internal/isDeferredFragment.js +35 -0
  376. package/utilities/internal/isDeferredFragment.js.map +1 -0
  377. package/utilities/internal/isStreamField.d.ts +9 -0
  378. package/utilities/internal/isStreamField.js +34 -0
  379. package/utilities/internal/isStreamField.js.map +1 -0
  380. package/utilities/internal/isTypenameField.d.ts +3 -0
  381. package/utilities/internal/isTypenameField.js +4 -0
  382. package/utilities/internal/isTypenameField.js.map +1 -0
  383. package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
  384. package/utilities/internal/makeStreamInfoTrie.js +14 -0
  385. package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
  386. package/utilities/internal/removeDirectivesFromDocument.js +1 -1
  387. package/utilities/internal/shouldInclude.js +4 -4
  388. package/utilities/internal/toDiffWithDataState.d.ts +8 -0
  389. package/utilities/internal/toDiffWithDataState.js +17 -0
  390. package/utilities/internal/toDiffWithDataState.js.map +1 -0
  391. package/utilities/internal/types/DeferInfo.d.ts +10 -0
  392. package/utilities/internal/types/DeferInfo.js +2 -0
  393. package/utilities/internal/types/DeferInfo.js.map +1 -0
  394. package/utilities/internal/types/Exact.d.ts +2 -0
  395. package/utilities/internal/types/Exact.js +2 -0
  396. package/utilities/internal/types/Exact.js.map +1 -0
  397. package/utilities/internal/types/IsLooselyEqual.d.ts +10 -0
  398. package/utilities/internal/types/IsLooselyEqual.js +2 -0
  399. package/utilities/internal/types/IsLooselyEqual.js.map +1 -0
  400. package/utilities/internal/types/IsNeverish.d.ts +4 -0
  401. package/utilities/internal/types/IsNeverish.js +2 -0
  402. package/utilities/internal/types/IsNeverish.js.map +1 -0
  403. package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
  404. package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
  405. package/utilities/internal/valueToObjectRepresentation.js +1 -1
  406. package/utilities/policies/pagination.d.ts +1 -1
  407. package/utilities/policies/pagination.js.map +1 -1
  408. package/utilities/subscriptions/relay/index.js +1 -0
  409. package/utilities/subscriptions/relay/index.js.map +1 -1
  410. package/version.js +1 -1
  411. package/version.js.map +1 -1
  412. package/__cjs/utilities/internal/types/NoInfer.cjs.map +0 -1
  413. package/__cjs/utilities/internal/types/NoInfer.d.cts +0 -35
  414. package/utilities/internal/types/NoInfer.d.ts +0 -35
  415. package/utilities/internal/types/NoInfer.js +0 -2
  416. package/utilities/internal/types/NoInfer.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n TypeOverrides,\n} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\nimport type { ExtensionsWithStreamInfo } from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache } from \"../cache.js\";\n\nimport type {\n AllFieldsModifier,\n MissingFieldError,\n Modifiers,\n} from \"./common.js\";\nexport declare namespace Cache {\n export type WatchCallback<TData = unknown> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export type Implementation =\n TypeOverrides extends { cache: infer TCache } ?\n TCache extends ApolloCache ?\n TCache\n : \"The cache type declared in TypeOverrides does not extend `ApolloCache` and cannot be used with Apollo Client. See https://www.apollographql.com/docs/react/data/typescript#declaring-the-cache-type.\"\n : ApolloCache;\n\n export interface ReadOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n }\n\n export interface WriteOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n dataId?: string;\n result: Unmasked<TData>;\n\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export interface DiffOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Omit<ReadOptions<TData, TVariables>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends Cache.Implementation,\n TUpdateResult = void,\n > {\n /**\n * A function that performs cache operations. Receives the cache instance as its argument.\n *\n * The return value of this function becomes the return value of `batch`.\n */\n update(cache: TCache): TUpdateResult;\n\n /**\n * Controls how optimistic data is handled:\n *\n * - `string`: Creates a new optimistic layer with this ID. Use `removeOptimistic` later to remove it.\n * - `true`: Updates the current top layer of the cache (including any optimistic data).\n * - `false`: Updates only the root (non-optimistic) cache data.\n *\n * @defaultValue false\n */\n optimistic?: string | boolean;\n\n /**\n * If provided, removes the optimistic layer with this ID after the batch completes.\n *\n * This is useful for atomically applying server data while removing a pending optimistic update, triggering at most one broadcast for both operations.\n *\n * Note: this option is needed because calling `cache.removeOptimistic` during the transaction function may not be safe, since any modifications to cache layers may be discarded after the transaction finishes.\n */\n removeOptimistic?: string;\n\n /**\n * Optional callback invoked for each watcher affected by the batch operation.\n *\n * Receives the watch options, the new diff result, and optionally the previous diff result.\n *\n * Return `false` to prevent broadcasting to that specific watcher.\n */\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export interface ReadQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes readQuery capable of reading data\n * from any object in the cache.\n */\n id?: string;\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n }\n\n export type ReadFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readFragment method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface WriteQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export type WriteFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string\n * with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface UpdateQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > extends Omit<\n ReadQueryOptions<TData, TVariables> &\n WriteQueryOptions<TData, TVariables>,\n \"data\"\n > {}\n\n export type UpdateFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = Omit<\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>,\n \"data\" | \"id\" | \"from\"\n > &\n Cache.CacheIdentifierOption<TData>;\n\n export type DiffResult<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData> | null;\n complete: false;\n missing?: MissingFieldError;\n fromOptimisticTransaction?: boolean;\n };\n\n export type CacheIdentifierOption<TData> =\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: never;\n }\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: never;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: ApolloCache.FromOptionValue<TData>;\n };\n}\n"]}
1
+ {"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n TypeOverrides,\n} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\nimport type { ExtensionsWithStreamInfo } from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache } from \"../cache.js\";\n\nimport type {\n AllFieldsModifier,\n MissingFieldError,\n Modifiers,\n} from \"./common.js\";\nexport declare namespace Cache {\n export type WatchCallback<TData = unknown> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export type Implementation =\n TypeOverrides extends { cache: infer TCache } ?\n TCache extends ApolloCache ?\n TCache\n : \"The cache type declared in TypeOverrides does not extend `ApolloCache` and cannot be used with Apollo Client. See https://www.apollographql.com/docs/react/data/typescript#declaring-the-cache-type.\"\n : ApolloCache;\n\n export interface ReadOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n }\n\n export interface WriteOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n dataId?: string;\n result: Unmasked<TData>;\n\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export interface DiffOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Omit<ReadOptions<TData, TVariables>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends Cache.Implementation,\n TUpdateResult = void,\n > {\n /**\n * A function that performs cache operations. Receives the cache instance as its argument.\n *\n * The return value of this function becomes the return value of `batch`.\n */\n update(cache: TCache): TUpdateResult;\n\n /**\n * Controls how optimistic data is handled:\n *\n * - `string`: Creates a new optimistic layer with this ID. Use `removeOptimistic` later to remove it.\n * - `true`: Updates the current top layer of the cache (including any optimistic data).\n * - `false`: Updates only the root (non-optimistic) cache data.\n *\n * @defaultValue false\n */\n optimistic?: string | boolean;\n\n /**\n * If provided, removes the optimistic layer with this ID after the batch completes.\n *\n * This is useful for atomically applying server data while removing a pending optimistic update, triggering at most one broadcast for both operations.\n *\n * Note: this option is needed because calling `cache.removeOptimistic` during the transaction function may not be safe, since any modifications to cache layers may be discarded after the transaction finishes.\n */\n removeOptimistic?: string;\n\n /**\n * Optional callback invoked for each watcher affected by the batch operation.\n *\n * Receives the watch options, the new diff result, and optionally the previous diff result.\n *\n * Return `false` to prevent broadcasting to that specific watcher.\n */\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export interface ReadQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes readQuery capable of reading data\n * from any object in the cache.\n */\n id?: string;\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n }\n\n export type ReadFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readFragment method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface WriteQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export type WriteFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string\n * with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface UpdateQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > extends Omit<\n ReadQueryOptions<TData, TVariables> &\n WriteQueryOptions<TData, TVariables>,\n \"data\"\n > {}\n\n export type UpdateFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = Omit<\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>,\n \"data\" | \"id\" | \"from\"\n > &\n Cache.CacheIdentifierOption<TData>;\n\n export type DiffResult<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData> | null;\n complete: false;\n missing?: MissingFieldError;\n fromOptimisticTransaction?: boolean;\n };\n\n export type InternalDiffResultWithDataState<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n dataState: \"complete\";\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Streaming<TData>;\n complete: false;\n missing?: never;\n dataState: \"streaming\";\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData>;\n complete: false;\n missing?: MissingFieldError;\n dataState: \"partial\";\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: null;\n complete: false;\n missing?: MissingFieldError;\n dataState: \"empty\";\n fromOptimisticTransaction?: boolean;\n };\n\n export type CacheIdentifierOption<TData> =\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: never;\n }\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: never;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: ApolloCache.FromOptionValue<TData>;\n };\n}\n"]}
package/cache/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type { Transaction } from "./core/cache.js";
2
2
  export type { WatchFragmentOptions, WatchFragmentResult, } from "./deprecated.js";
3
3
  export { ApolloCache } from "./core/cache.js";
4
+ export { Scalar } from "./core/Scalar.js";
4
5
  export type { Cache } from "./core/types/Cache.js";
5
6
  export type { IgnoreModifier, MissingTree, Modifier, ModifierDetails, Modifiers, ReadFieldOptions, } from "./core/types/common.js";
6
7
  export { MissingFieldError } from "./core/types/common.js";
@@ -11,9 +12,9 @@ export { defaultDataIdFromObject, fieldNameFromStoreName, } from "./inmemory/hel
11
12
  export { InMemoryCache } from "./inmemory/inMemoryCache.js";
12
13
  export type { ReactiveVar } from "./inmemory/reactiveVars.js";
13
14
  export { cacheSlot, makeVar } from "./inmemory/reactiveVars.js";
14
- export type { FieldFunctionOptions, FieldMergeFunction, FieldMergeFunctionOptions, FieldPolicy, FieldReadFunction, FieldReadFunctionOptions, PossibleTypesMap, TypePolicies, TypePolicy, } from "./inmemory/policies.js";
15
+ export type { FieldFunctionOptions, FieldMergeFunction, FieldMergeFunctionOptions, FieldPolicy, FieldReadFunction, FieldReadFunctionOptions, KeyArgsFunction, PossibleTypesMap, TypePolicies, TypePolicy, } from "./inmemory/policies.js";
15
16
  export { Policies } from "./inmemory/policies.js";
16
17
  export type { FragmentRegistryAPI } from "./inmemory/fragmentRegistry.js";
17
18
  export { createFragmentRegistry } from "./inmemory/fragmentRegistry.js";
18
- export type { ApolloReducerConfig, DiffQueryAgainstStoreOptions, IdGetter, IdGetterObj, InMemoryCacheConfig, MergeInfo, MergeTree, NormalizedCache, NormalizedCacheObject, OptimisticStoreItem, ReadMergeModifyContext, ReadQueryOptions, StoreObject, StoreValue, } from "./inmemory/types.js";
19
+ export type { ApolloReducerConfig, DiffIncrementalInfo, DiffQueryAgainstStoreOptions, IdGetter, IdGetterObj, InMemoryCacheConfig, InputObjectConfig, InputObjectsOption, MergeInfo, MergeTree, NormalizedCache, NormalizedCacheObject, OptimisticStoreItem, ReadMergeModifyContext, ReadQueryOptions, StoreObject, StoreValue, } from "./inmemory/types.js";
19
20
  //# sourceMappingURL=index.d.ts.map
package/cache/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ApolloCache } from "./core/cache.js";
2
+ export { Scalar } from "./core/Scalar.js";
2
3
  export { MissingFieldError } from "./core/types/common.js";
3
4
  export { canonicalStringify, isReference } from "@apollo/client/utilities";
4
5
  export { EntityStore } from "./inmemory/entityStore.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAU9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAahE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export type { Transaction } from \"./core/cache.js\";\nexport type {\n WatchFragmentOptions,\n WatchFragmentResult,\n} from \"./deprecated.js\";\nexport { ApolloCache } from \"./core/cache.js\";\nexport type { Cache } from \"./core/types/Cache.js\";\nexport type {\n IgnoreModifier,\n MissingTree,\n Modifier,\n ModifierDetails,\n Modifiers,\n ReadFieldOptions,\n} from \"./core/types/common.js\";\nexport { MissingFieldError } from \"./core/types/common.js\";\n\nexport type { Reference } from \"@apollo/client/utilities\";\nexport { canonicalStringify, isReference } from \"@apollo/client/utilities\";\n\nexport { EntityStore } from \"./inmemory/entityStore.js\";\nexport {\n defaultDataIdFromObject,\n fieldNameFromStoreName,\n} from \"./inmemory/helpers.js\";\n\nexport { InMemoryCache } from \"./inmemory/inMemoryCache.js\";\n\nexport type { ReactiveVar } from \"./inmemory/reactiveVars.js\";\nexport { cacheSlot, makeVar } from \"./inmemory/reactiveVars.js\";\n\nexport type {\n FieldFunctionOptions,\n FieldMergeFunction,\n FieldMergeFunctionOptions,\n FieldPolicy,\n FieldReadFunction,\n FieldReadFunctionOptions,\n PossibleTypesMap,\n TypePolicies,\n TypePolicy,\n} from \"./inmemory/policies.js\";\nexport { Policies } from \"./inmemory/policies.js\";\n\nexport type { FragmentRegistryAPI } from \"./inmemory/fragmentRegistry.js\";\nexport { createFragmentRegistry } from \"./inmemory/fragmentRegistry.js\";\n\nexport type {\n ApolloReducerConfig,\n DiffQueryAgainstStoreOptions,\n IdGetter,\n IdGetterObj,\n InMemoryCacheConfig,\n MergeInfo,\n MergeTree,\n NormalizedCache,\n NormalizedCacheObject,\n OptimisticStoreItem,\n ReadMergeModifyContext,\n ReadQueryOptions,\n StoreObject,\n StoreValue,\n} from \"./inmemory/types.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAU1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAchE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export type { Transaction } from \"./core/cache.js\";\nexport type {\n WatchFragmentOptions,\n WatchFragmentResult,\n} from \"./deprecated.js\";\nexport { ApolloCache } from \"./core/cache.js\";\nexport { Scalar } from \"./core/Scalar.js\";\nexport type { Cache } from \"./core/types/Cache.js\";\nexport type {\n IgnoreModifier,\n MissingTree,\n Modifier,\n ModifierDetails,\n Modifiers,\n ReadFieldOptions,\n} from \"./core/types/common.js\";\nexport { MissingFieldError } from \"./core/types/common.js\";\n\nexport type { Reference } from \"@apollo/client/utilities\";\nexport { canonicalStringify, isReference } from \"@apollo/client/utilities\";\n\nexport { EntityStore } from \"./inmemory/entityStore.js\";\nexport {\n defaultDataIdFromObject,\n fieldNameFromStoreName,\n} from \"./inmemory/helpers.js\";\n\nexport { InMemoryCache } from \"./inmemory/inMemoryCache.js\";\n\nexport type { ReactiveVar } from \"./inmemory/reactiveVars.js\";\nexport { cacheSlot, makeVar } from \"./inmemory/reactiveVars.js\";\n\nexport type {\n FieldFunctionOptions,\n FieldMergeFunction,\n FieldMergeFunctionOptions,\n FieldPolicy,\n FieldReadFunction,\n FieldReadFunctionOptions,\n KeyArgsFunction,\n PossibleTypesMap,\n TypePolicies,\n TypePolicy,\n} from \"./inmemory/policies.js\";\nexport { Policies } from \"./inmemory/policies.js\";\n\nexport type { FragmentRegistryAPI } from \"./inmemory/fragmentRegistry.js\";\nexport { createFragmentRegistry } from \"./inmemory/fragmentRegistry.js\";\n\nexport type {\n ApolloReducerConfig,\n DiffIncrementalInfo,\n DiffQueryAgainstStoreOptions,\n IdGetter,\n IdGetterObj,\n InMemoryCacheConfig,\n InputObjectConfig,\n InputObjectsOption,\n MergeInfo,\n MergeTree,\n NormalizedCache,\n NormalizedCacheObject,\n OptimisticStoreItem,\n ReadMergeModifyContext,\n ReadQueryOptions,\n StoreObject,\n StoreValue,\n} from \"./inmemory/types.js\";\n"]}
@@ -23,6 +23,9 @@ export declare abstract class EntityStore implements NormalizedCache {
23
23
  evict(options: Cache.EvictOptions, limit: EntityStore): boolean;
24
24
  clear(): void;
25
25
  extract(): NormalizedCacheObject;
26
+ private hasScalarConfig;
27
+ private coerceStoreObject;
28
+ private coerceValue;
26
29
  replace(newData: NormalizedCacheObject | null): void;
27
30
  abstract getStorage(idOrObj: string | StoreObject, ...storeFieldNames: (string | number)[]): StorageType;
28
31
  private rootIds;
@@ -3,7 +3,7 @@ import { Trie } from "@wry/trie";
3
3
  import { dep } from "optimism";
4
4
  import { isReference } from "@apollo/client/utilities";
5
5
  import { __DEV__ } from "@apollo/client/utilities/environment";
6
- import { DeepMerger, isNonNullObject, makeReference, maybeDeepFreeze, } from "@apollo/client/utilities/internal";
6
+ import { DeepMerger, isNonNullObject, isPlainObject, makeReference, maybeDeepFreeze, } from "@apollo/client/utilities/internal";
7
7
  import { invariant } from "@apollo/client/utilities/invariant";
8
8
  import { fieldNameFromStoreName, hasOwn } from "./helpers.js";
9
9
  const DELETE = {};
@@ -68,12 +68,17 @@ export class EntityStore {
68
68
  if (isReference(newer))
69
69
  newer = newer.__ref;
70
70
  const existing = typeof older === "string" ? this.lookup((dataId = older)) : older;
71
- const incoming = typeof newer === "string" ? this.lookup((dataId = newer)) : newer;
71
+ let incoming = typeof newer === "string" ? this.lookup((dataId = newer)) : newer;
72
72
  // If newer was a string ID, but that ID was not defined in this store,
73
73
  // then there are no fields to be merged, so we're done.
74
74
  if (!incoming)
75
75
  return;
76
- invariant(typeof dataId === "string", 104);
76
+ invariant(typeof dataId === "string", 107);
77
+ // Parse all scalars before merging so that the storeObjectReconciler can
78
+ // deep compare the parsed value with the existing value
79
+ incoming = this.coerceStoreObject(incoming, (scalar, value) => scalar.coerceToParsed(value), incoming.__typename ||
80
+ existing?.__typename ||
81
+ this.policies.rootTypenamesById[dataId]);
77
82
  const merged = new DeepMerger({
78
83
  reconciler: storeObjectReconciler,
79
84
  }).merge(existing, incoming);
@@ -175,7 +180,7 @@ export class EntityStore {
175
180
  if (__DEV__) {
176
181
  const checkReference = (ref) => {
177
182
  if (this.lookup(ref.__ref) === undefined) {
178
- __DEV__ && invariant.warn(105, ref);
183
+ __DEV__ && invariant.warn(108, ref);
179
184
  return true;
180
185
  }
181
186
  };
@@ -204,7 +209,7 @@ export class EntityStore {
204
209
  }
205
210
  }
206
211
  if (seenReference && someNonReference !== undefined) {
207
- __DEV__ && invariant.warn(106, someNonReference);
212
+ __DEV__ && invariant.warn(109, someNonReference);
208
213
  break;
209
214
  }
210
215
  }
@@ -277,7 +282,14 @@ export class EntityStore {
277
282
  this.replace(null);
278
283
  }
279
284
  extract() {
280
- const obj = this.toObject();
285
+ let obj = this.toObject();
286
+ if (this.hasScalarConfig()) {
287
+ obj = Object.fromEntries(Object.entries(obj).map(([dataId, storeObject]) => [
288
+ dataId,
289
+ storeObject &&
290
+ this.coerceStoreObject(storeObject, (scalar, value) => scalar.coerceToSerialized(value), storeObject?.__typename || this.policies.rootTypenamesById[dataId]),
291
+ ]));
292
+ }
281
293
  const extraRootIds = [];
282
294
  this.getRootIdSet().forEach((id) => {
283
295
  if (!hasOwn.call(this.policies.rootTypenamesById, id)) {
@@ -289,6 +301,37 @@ export class EntityStore {
289
301
  }
290
302
  return obj;
291
303
  }
304
+ hasScalarConfig() {
305
+ return !!this.policies.cache["config"].scalars;
306
+ }
307
+ coerceStoreObject(obj, coerce, typename = obj.__typename) {
308
+ if (!typename || !this.hasScalarConfig()) {
309
+ return obj;
310
+ }
311
+ let changed = false;
312
+ const entries = Object.entries(obj).map(([storeFieldName, value]) => {
313
+ const scalar = this.policies.getScalarForField(typename, fieldNameFromStoreName(storeFieldName));
314
+ const newValue = this.coerceValue(value, coerce, scalar);
315
+ changed ||= newValue !== value;
316
+ return [storeFieldName, newValue];
317
+ });
318
+ return changed ? Object.fromEntries(entries) : obj;
319
+ }
320
+ coerceValue(value, coerce, scalar) {
321
+ if (value == null) {
322
+ return value;
323
+ }
324
+ if (Array.isArray(value)) {
325
+ return value.map((item) => this.coerceValue(item, coerce, scalar));
326
+ }
327
+ if (scalar) {
328
+ return coerce(scalar, value);
329
+ }
330
+ if (isPlainObject(value) && "__typename" in value) {
331
+ return this.coerceStoreObject(value, coerce);
332
+ }
333
+ return value;
334
+ }
292
335
  replace(newData) {
293
336
  Object.keys(this.data).forEach((dataId) => {
294
337
  if (!(newData && hasOwn.call(newData, dataId))) {