@apollo/client 4.3.0-alpha.0 → 4.3.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/CHANGELOG.md +490 -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 +20 -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 +17 -22
  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 +12 -6
  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/incremental/internal/types.cjs +3 -0
  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/masking/internal/types.d.cts +1 -2
  74. package/__cjs/masking/maskDefinition.cjs +2 -2
  75. package/__cjs/masking/maskFragment.cjs +2 -2
  76. package/__cjs/masking/maskOperation.cjs +1 -1
  77. package/__cjs/masking/utils.cjs +3 -3
  78. package/__cjs/react/context/ApolloContext.cjs +1 -1
  79. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  80. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
  81. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  82. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  83. package/__cjs/react/hooks/useBackgroundQuery.d.cts +100 -47
  84. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  85. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  86. package/__cjs/react/hooks/useLazyQuery.d.cts +39 -33
  87. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  88. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  89. package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
  90. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  91. package/__cjs/react/hooks/useMutation.d.cts +10 -7
  92. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  93. package/__cjs/react/hooks/useQuery.d.cts +74 -32
  94. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  95. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  96. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  97. package/__cjs/react/hooks/useSuspenseQuery.d.cts +83 -34
  98. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  99. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  100. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  101. package/__cjs/react/internal/types.d.cts +14 -3
  102. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  103. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
  104. package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
  105. package/__cjs/react/types/deprecated.d.cts +5 -4
  106. package/__cjs/testing/core/mocking/mockLink.cjs +25 -5
  107. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  108. package/__cjs/testing/core/mocking/mockLink.d.cts +1 -2
  109. package/__cjs/utilities/caching/sizes.cjs.map +1 -1
  110. package/__cjs/utilities/caching/sizes.d.cts +39 -1
  111. package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
  112. package/__cjs/utilities/index.cjs.map +1 -1
  113. package/__cjs/utilities/index.d.cts +1 -0
  114. package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
  115. package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
  116. package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
  117. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs +33 -0
  118. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs.map +1 -0
  119. package/__cjs/utilities/internal/addDeferFragmentLabels.d.cts +3 -0
  120. package/__cjs/utilities/internal/capitalize.cjs +12 -0
  121. package/__cjs/utilities/internal/capitalize.cjs.map +1 -0
  122. package/__cjs/utilities/internal/capitalize.d.cts +7 -0
  123. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs +69 -0
  124. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs.map +1 -0
  125. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.d.cts +9 -0
  126. package/__cjs/utilities/internal/constants.cjs +20 -1
  127. package/__cjs/utilities/internal/constants.cjs.map +1 -1
  128. package/__cjs/utilities/internal/constants.d.cts +19 -0
  129. package/__cjs/utilities/internal/getDirectiveArgValue.cjs +19 -0
  130. package/__cjs/utilities/internal/getDirectiveArgValue.cjs.map +1 -0
  131. package/__cjs/utilities/internal/getDirectiveArgValue.d.cts +9 -0
  132. package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
  133. package/__cjs/utilities/internal/getFragmentFromSelection.cjs +2 -2
  134. package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
  135. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +2 -2
  136. package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
  137. package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
  138. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  139. package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
  140. package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
  141. package/__cjs/utilities/internal/getUnwrappedType.cjs +20 -0
  142. package/__cjs/utilities/internal/getUnwrappedType.cjs.map +1 -0
  143. package/__cjs/utilities/internal/getUnwrappedType.d.cts +8 -0
  144. package/__cjs/utilities/internal/index.cjs +25 -2
  145. package/__cjs/utilities/internal/index.cjs.map +1 -1
  146. package/__cjs/utilities/internal/index.d.cts +16 -1
  147. package/__cjs/utilities/internal/isDeferredFragment.cjs +38 -0
  148. package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -0
  149. package/__cjs/utilities/internal/isDeferredFragment.d.cts +9 -0
  150. package/__cjs/utilities/internal/isStreamField.cjs +37 -0
  151. package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
  152. package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
  153. package/__cjs/utilities/internal/isTypenameField.cjs +7 -0
  154. package/__cjs/utilities/internal/isTypenameField.cjs.map +1 -0
  155. package/__cjs/utilities/internal/isTypenameField.d.cts +3 -0
  156. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
  157. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
  158. package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
  159. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
  160. package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
  161. package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
  162. package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
  163. package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
  164. package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
  165. package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
  166. package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
  167. package/__cjs/utilities/internal/types/Exact.cjs +3 -0
  168. package/__cjs/utilities/internal/types/Exact.cjs.map +1 -0
  169. package/__cjs/utilities/internal/types/Exact.d.cts +2 -0
  170. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs +3 -0
  171. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs.map +1 -0
  172. package/__cjs/utilities/internal/types/IsLooselyEqual.d.cts +10 -0
  173. package/__cjs/utilities/internal/types/IsNeverish.cjs +3 -0
  174. package/__cjs/utilities/internal/types/IsNeverish.cjs.map +1 -0
  175. package/__cjs/utilities/internal/types/IsNeverish.d.cts +4 -0
  176. package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
  177. package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
  178. package/__cjs/utilities/policies/pagination.cjs.map +1 -1
  179. package/__cjs/utilities/policies/pagination.d.cts +1 -1
  180. package/__cjs/utilities/subscriptions/relay/index.cjs +1 -0
  181. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  182. package/__cjs/version.cjs +1 -1
  183. package/__cjs/version.cjs.map +1 -1
  184. package/cache/core/Scalar.d.ts +20 -0
  185. package/cache/core/Scalar.js +32 -0
  186. package/cache/core/Scalar.js.map +1 -0
  187. package/cache/core/cache.d.ts +89 -6
  188. package/cache/core/cache.js +33 -2
  189. package/cache/core/cache.js.map +1 -1
  190. package/cache/core/types/Cache.d.ts +25 -0
  191. package/cache/core/types/Cache.js.map +1 -1
  192. package/cache/index.d.ts +3 -2
  193. package/cache/index.js +1 -0
  194. package/cache/index.js.map +1 -1
  195. package/cache/inmemory/entityStore.d.ts +3 -0
  196. package/cache/inmemory/entityStore.js +49 -6
  197. package/cache/inmemory/entityStore.js.map +1 -1
  198. package/cache/inmemory/helpers.d.ts +9 -1
  199. package/cache/inmemory/inMemoryCache.d.ts +44 -5
  200. package/cache/inmemory/inMemoryCache.js +84 -5
  201. package/cache/inmemory/inMemoryCache.js.map +1 -1
  202. package/cache/inmemory/key-extractor.js +1 -1
  203. package/cache/inmemory/policies.d.ts +4 -1
  204. package/cache/inmemory/policies.js +35 -6
  205. package/cache/inmemory/policies.js.map +1 -1
  206. package/cache/inmemory/readFromStore.d.ts +11 -2
  207. package/cache/inmemory/readFromStore.js +486 -49
  208. package/cache/inmemory/readFromStore.js.map +1 -1
  209. package/cache/inmemory/types.d.ts +30 -5
  210. package/cache/inmemory/types.js.map +1 -1
  211. package/cache/inmemory/writeToStore.js +7 -7
  212. package/cache/inmemory/writeToStore.js.map +1 -1
  213. package/core/ApolloClient.d.ts +44 -10
  214. package/core/ApolloClient.js +37 -38
  215. package/core/ApolloClient.js.map +1 -1
  216. package/core/ObservableQuery.d.ts +16 -8
  217. package/core/ObservableQuery.js +225 -77
  218. package/core/ObservableQuery.js.map +1 -1
  219. package/core/QueryInfo.d.ts +18 -23
  220. package/core/QueryInfo.js +174 -190
  221. package/core/QueryInfo.js.map +1 -1
  222. package/core/QueryManager.d.ts +1 -3
  223. package/core/QueryManager.js +89 -60
  224. package/core/QueryManager.js.map +1 -1
  225. package/core/RefetchEventManager.js +3 -3
  226. package/core/dataStateErrorCache.d.ts +3 -0
  227. package/core/dataStateErrorCache.js +9 -0
  228. package/core/dataStateErrorCache.js.map +1 -0
  229. package/core/index.d.ts +4 -3
  230. package/core/index.js +1 -1
  231. package/core/index.js.map +1 -1
  232. package/core/types.d.ts +12 -6
  233. package/core/types.js.map +1 -1
  234. package/incremental/GraphQLCodegenIncremental.d.ts +55 -0
  235. package/incremental/GraphQLCodegenIncremental.js +2 -0
  236. package/incremental/GraphQLCodegenIncremental.js.map +1 -0
  237. package/incremental/handlers/defer20220824.d.ts +2 -4
  238. package/incremental/handlers/defer20220824.js.map +1 -1
  239. package/incremental/handlers/graphql17Alpha9.d.ts +29 -6
  240. package/incremental/handlers/graphql17Alpha9.js +48 -17
  241. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  242. package/incremental/handlers/notImplemented.js +1 -1
  243. package/incremental/index.d.ts +1 -0
  244. package/incremental/index.js.map +1 -1
  245. package/incremental/internal/types.d.ts +17 -0
  246. package/incremental/internal/types.js +2 -0
  247. package/incremental/internal/types.js.map +1 -0
  248. package/incremental/types.d.ts +55 -4
  249. package/incremental/types.js.map +1 -1
  250. package/invariantErrorCodes.js +167 -112
  251. package/link/core/ApolloLink.js +3 -3
  252. package/link/http/checkFetcher.js +1 -1
  253. package/link/http/parseAndCheckHttpResponse.js +2 -2
  254. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  255. package/link/persisted-queries/index.js +2 -2
  256. package/link/ws/index.js +1 -1
  257. package/local-state/LocalState.js +11 -11
  258. package/masking/internal/types.d.ts +1 -2
  259. package/masking/internal/types.js.map +1 -1
  260. package/masking/maskDefinition.js +2 -2
  261. package/masking/maskFragment.js +2 -2
  262. package/masking/maskOperation.js +1 -1
  263. package/masking/utils.js +3 -3
  264. package/package.json +1 -1
  265. package/react/context/ApolloContext.js +1 -1
  266. package/react/context/ApolloProvider.js +1 -1
  267. package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
  268. package/react/hooks/useApolloClient.js +1 -1
  269. package/react/hooks/useBackgroundQuery.d.ts +100 -47
  270. package/react/hooks/useBackgroundQuery.js.map +1 -1
  271. package/react/hooks/useLazyQuery.d.ts +39 -33
  272. package/react/hooks/useLazyQuery.js +2 -2
  273. package/react/hooks/useLazyQuery.js.map +1 -1
  274. package/react/hooks/useLoadableQuery.d.ts +23 -15
  275. package/react/hooks/useLoadableQuery.js +2 -2
  276. package/react/hooks/useLoadableQuery.js.map +1 -1
  277. package/react/hooks/useMutation.d.ts +10 -7
  278. package/react/hooks/useMutation.js.map +1 -1
  279. package/react/hooks/useQuery.d.ts +74 -32
  280. package/react/hooks/useQuery.js.map +1 -1
  281. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  282. package/react/hooks/useSubscription.js +1 -1
  283. package/react/hooks/useSuspenseQuery.d.ts +83 -34
  284. package/react/hooks/useSuspenseQuery.js.map +1 -1
  285. package/react/hooks/useSyncExternalStore.js +1 -1
  286. package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
  287. package/react/hooks-compiled/useApolloClient.js +1 -1
  288. package/react/hooks-compiled/useBackgroundQuery.d.ts +100 -47
  289. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  290. package/react/hooks-compiled/useLazyQuery.d.ts +39 -33
  291. package/react/hooks-compiled/useLazyQuery.js +2 -2
  292. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  293. package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
  294. package/react/hooks-compiled/useLoadableQuery.js +2 -2
  295. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  296. package/react/hooks-compiled/useMutation.d.ts +10 -7
  297. package/react/hooks-compiled/useMutation.js.map +1 -1
  298. package/react/hooks-compiled/useQuery.d.ts +74 -32
  299. package/react/hooks-compiled/useQuery.js.map +1 -1
  300. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  301. package/react/hooks-compiled/useSubscription.js +1 -1
  302. package/react/hooks-compiled/useSuspenseQuery.d.ts +83 -34
  303. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  304. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  305. package/react/internal/cache/QueryReference.js +1 -1
  306. package/react/internal/cache/QueryReference.js.map +1 -1
  307. package/react/internal/types.d.ts +15 -4
  308. package/react/internal/types.js.map +1 -1
  309. package/react/query-preloader/createQueryPreloader.d.ts +20 -5
  310. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  311. package/react/ssr/prerenderStatic.js +2 -2
  312. package/react/types/deprecated.d.ts +5 -4
  313. package/react/types/deprecated.js.map +1 -1
  314. package/testing/core/mocking/mockLink.d.ts +1 -2
  315. package/testing/core/mocking/mockLink.js +25 -5
  316. package/testing/core/mocking/mockLink.js.map +1 -1
  317. package/utilities/caching/sizes.d.ts +39 -1
  318. package/utilities/caching/sizes.js.map +1 -1
  319. package/utilities/graphql/DocumentTransform.js +1 -1
  320. package/utilities/index.d.ts +1 -0
  321. package/utilities/index.js.map +1 -1
  322. package/utilities/internal/StreamArrayState.d.ts +12 -0
  323. package/utilities/internal/StreamArrayState.js +23 -0
  324. package/utilities/internal/StreamArrayState.js.map +1 -0
  325. package/utilities/internal/addDeferFragmentLabels.d.ts +3 -0
  326. package/utilities/internal/addDeferFragmentLabels.js +30 -0
  327. package/utilities/internal/addDeferFragmentLabels.js.map +1 -0
  328. package/utilities/internal/capitalize.d.ts +7 -0
  329. package/utilities/internal/capitalize.js +9 -0
  330. package/utilities/internal/capitalize.js.map +1 -0
  331. package/utilities/internal/coerceScalarFieldsToParsed.d.ts +9 -0
  332. package/utilities/internal/coerceScalarFieldsToParsed.js +66 -0
  333. package/utilities/internal/coerceScalarFieldsToParsed.js.map +1 -0
  334. package/utilities/internal/constants.d.ts +19 -0
  335. package/utilities/internal/constants.js +19 -0
  336. package/utilities/internal/constants.js.map +1 -1
  337. package/utilities/internal/getDirectiveArgValue.d.ts +9 -0
  338. package/utilities/internal/getDirectiveArgValue.js +16 -0
  339. package/utilities/internal/getDirectiveArgValue.js.map +1 -0
  340. package/utilities/internal/getFragmentDefinition.js +3 -3
  341. package/utilities/internal/getFragmentFromSelection.js +2 -2
  342. package/utilities/internal/getFragmentFromSelection.js.map +1 -1
  343. package/utilities/internal/getFragmentQueryDocument.js +2 -2
  344. package/utilities/internal/getMainDefinition.js +1 -1
  345. package/utilities/internal/getMemoryInternals.d.ts +4 -0
  346. package/utilities/internal/getMemoryInternals.js +6 -0
  347. package/utilities/internal/getMemoryInternals.js.map +1 -1
  348. package/utilities/internal/getQueryDefinition.js +1 -1
  349. package/utilities/internal/getUnwrappedType.d.ts +8 -0
  350. package/utilities/internal/getUnwrappedType.js +17 -0
  351. package/utilities/internal/getUnwrappedType.js.map +1 -0
  352. package/utilities/internal/index.d.ts +16 -1
  353. package/utilities/internal/index.js +12 -1
  354. package/utilities/internal/index.js.map +1 -1
  355. package/utilities/internal/isDeferredFragment.d.ts +9 -0
  356. package/utilities/internal/isDeferredFragment.js +35 -0
  357. package/utilities/internal/isDeferredFragment.js.map +1 -0
  358. package/utilities/internal/isStreamField.d.ts +9 -0
  359. package/utilities/internal/isStreamField.js +34 -0
  360. package/utilities/internal/isStreamField.js.map +1 -0
  361. package/utilities/internal/isTypenameField.d.ts +3 -0
  362. package/utilities/internal/isTypenameField.js +4 -0
  363. package/utilities/internal/isTypenameField.js.map +1 -0
  364. package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
  365. package/utilities/internal/makeStreamInfoTrie.js +14 -0
  366. package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
  367. package/utilities/internal/removeDirectivesFromDocument.js +1 -1
  368. package/utilities/internal/shouldInclude.js +4 -4
  369. package/utilities/internal/toDiffWithDataState.d.ts +8 -0
  370. package/utilities/internal/toDiffWithDataState.js +17 -0
  371. package/utilities/internal/toDiffWithDataState.js.map +1 -0
  372. package/utilities/internal/types/DeferInfo.d.ts +10 -0
  373. package/utilities/internal/types/DeferInfo.js +2 -0
  374. package/utilities/internal/types/DeferInfo.js.map +1 -0
  375. package/utilities/internal/types/Exact.d.ts +2 -0
  376. package/utilities/internal/types/Exact.js +2 -0
  377. package/utilities/internal/types/Exact.js.map +1 -0
  378. package/utilities/internal/types/IsLooselyEqual.d.ts +10 -0
  379. package/utilities/internal/types/IsLooselyEqual.js +2 -0
  380. package/utilities/internal/types/IsLooselyEqual.js.map +1 -0
  381. package/utilities/internal/types/IsNeverish.d.ts +4 -0
  382. package/utilities/internal/types/IsNeverish.js +2 -0
  383. package/utilities/internal/types/IsNeverish.js.map +1 -0
  384. package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
  385. package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
  386. package/utilities/internal/valueToObjectRepresentation.js +1 -1
  387. package/utilities/policies/pagination.d.ts +1 -1
  388. package/utilities/policies/pagination.js.map +1 -1
  389. package/utilities/subscriptions/relay/index.js +1 -0
  390. package/utilities/subscriptions/relay/index.js.map +1 -1
  391. package/version.js +1 -1
  392. package/version.js.map +1 -1
@@ -1,6 +1,12 @@
1
- "use strict";
1
+ "use strict";;
2
+ const {
3
+ __DEV__
4
+ } = require("@apollo/client/utilities/environment");
5
+
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.StoreReader = void 0;
8
+ const equality_1 = require("@wry/equality");
9
+ const trie_1 = require("@wry/trie");
4
10
  const graphql_1 = require("graphql");
5
11
  const optimism_1 = require("optimism");
6
12
  const utilities_1 = require("@apollo/client/utilities");
@@ -18,8 +24,11 @@ class StoreReader {
18
24
  executeSelectionSet;
19
25
  // cached version of executeSubSelectedArray
20
26
  executeSubSelectedArray;
27
+ prunePartialStreamArray;
28
+ prunePartialBoundaries;
21
29
  config;
22
30
  knownResults = new WeakMap();
31
+ keyMaker = new trie_1.Trie();
23
32
  constructor(config) {
24
33
  this.config = config;
25
34
  // memoized functions in this class will be "garbage-collected"
@@ -62,47 +71,124 @@ class StoreReader {
62
71
  }
63
72
  },
64
73
  });
74
+ this.prunePartialBoundaries = (0, optimism_1.wrap)((options) => this.prunePartialBoundariesImpl(options), {
75
+ max: utilities_1.cacheSizes["inMemoryCache.prunePartialBoundaries"] ||
76
+ 20000 /* defaultCacheSizes["inMemoryCache.prunePartialBoundaries"] */,
77
+ makeCacheKey: ({ boundaries, context, selectionSet }) => {
78
+ if ((0, entityStore_js_1.supportsResultCaching)(context.store)) {
79
+ return this.keyMaker.lookup(selectionSet, boundaries, context.streamInfo, context.deferInfo);
80
+ }
81
+ },
82
+ });
83
+ this.prunePartialStreamArray = (0, optimism_1.wrap)((options) => {
84
+ const { field, context, path } = options;
85
+ if ((0, internal_1.isStreamField)(field, context.variables)) {
86
+ context.streamInfo?.lookupArray(path).state.depend();
87
+ }
88
+ return this.prunePartialStreamArrayImpl(options);
89
+ }, {
90
+ max: utilities_1.cacheSizes["inMemoryCache.prunePartialStreamArray"] ||
91
+ 20000 /* defaultCacheSizes["inMemoryCache.prunePartialStreamArray"] */,
92
+ makeCacheKey: ({ field, context, boundaries }) => {
93
+ if ((0, entityStore_js_1.supportsResultCaching)(context.store)) {
94
+ return this.keyMaker.lookup(field, boundaries, context.streamInfo, context.deferInfo);
95
+ }
96
+ },
97
+ });
65
98
  }
66
- /**
67
- * Given a store and a query, return as much of the result as possible and
68
- * identify if any data was missing from the store.
69
- */
70
- diffQueryAgainstStore({ store, query, rootId = "ROOT_QUERY", variables, returnPartialData = true, }) {
99
+ diffQueryAgainstStore({ store, query, rootId = "ROOT_QUERY", variables, returnPartialData = true, ...options }) {
100
+ const returnIncremental = Object.hasOwn(options, internal_1.handleIncrementalSymbol);
71
101
  const policies = this.config.cache.policies;
72
- variables = {
73
- ...(0, internal_1.getDefaultValues)((0, internal_1.getQueryDefinition)(query)),
74
- ...variables,
75
- };
102
+ variables = (0, internal_1.compact)((0, internal_1.getDefaultValues)((0, internal_1.getQueryDefinition)(query)), variables);
76
103
  const rootRef = (0, internal_1.makeReference)(rootId);
77
- const execResult = this.executeSelectionSet({
104
+ const context = {
105
+ store,
106
+ query,
107
+ policies,
108
+ variables,
109
+ varString: (0, utilities_1.canonicalStringify)(variables),
110
+ ...(0, helpers_js_1.extractFragmentContext)(query, this.config.fragments),
111
+ ...options[internal_1.handleIncrementalSymbol],
112
+ };
113
+ let execResult = this.executeSelectionSet({
78
114
  selectionSet: (0, internal_1.getMainDefinition)(query).selectionSet,
79
115
  objectOrReference: rootRef,
80
116
  enclosingRef: rootRef,
81
- context: {
82
- store,
83
- query,
84
- policies,
85
- variables,
86
- varString: (0, utilities_1.canonicalStringify)(variables),
87
- ...(0, helpers_js_1.extractFragmentContext)(query, this.config.fragments),
88
- },
117
+ context,
89
118
  });
90
- let missing;
91
- if (execResult.missing) {
92
- missing = new common_js_1.MissingFieldError(firstMissing(execResult.missing), execResult.missing, query, variables);
119
+ // Since executeSelectionSet doesn't know about returnPartialData, we need
120
+ // to perform a 2nd pass over the result to prune any fields inside
121
+ // partial defer boundaries. The "deferPartial" data state tells us that the
122
+ // only part of the result that contributed to its partiality is data inside
123
+ // a defer boundary.
124
+ if (returnIncremental && shouldPrune(execResult, context)) {
125
+ const pruned = this.prunePartialBoundaries({
126
+ selectionSet: (0, internal_1.getMainDefinition)(query).selectionSet,
127
+ data: execResult.result,
128
+ boundaries: execResult.partialBoundaries,
129
+ context,
130
+ path: [],
131
+ });
132
+ const changed = execResult.result !== pruned.result;
133
+ // It's possible that pruning didn't actually change the result which can
134
+ // happen if a defer boundary is misclassified as "deferPartial" instead
135
+ // of "streaming" (sibling defer boundaries with overlapping selection
136
+ // sets, one of which is complete). In this case, pruning corrects the
137
+ // dataState to streaming instead of leaving it as partial. If we tolerate
138
+ // partial results and pruning changed the result by dropping fields, then
139
+ // we want to keep the original execResult which contains the partial
140
+ // data.
141
+ if (!changed || !returnPartialData) {
142
+ // Omit `missing` property since pruning puts it in a state that doesn't
143
+ // report missing fields.
144
+ execResult = {
145
+ result: pruned.result,
146
+ partialBoundaries: execResult.partialBoundaries,
147
+ dataState: pruned.dataState,
148
+ };
149
+ }
93
150
  }
94
- const complete = !missing;
95
- const { result } = execResult;
96
- return {
97
- result: complete ? result
98
- : returnPartialData ?
99
- Object.keys(result).length === 0 ?
100
- null
101
- : result
102
- : null,
151
+ let { result, dataState, missing } = execResult;
152
+ // Evaluate this condition before we start mucking with dataState for the
153
+ // publicly returned value
154
+ const includeMissing = !!missing &&
155
+ // We don't need to report missing fields inside defer boundaries since
156
+ // the "streaming" dataState tells us that the only missing fields in
157
+ // the object is inside a defer boundary.
158
+ (dataState !== "streaming" || !returnIncremental);
159
+ // If we get all root @defer boundaries with an empty result, report it as
160
+ // empty instead of streaming.
161
+ if (dataState === "streaming" && Object.keys(result).length === 0) {
162
+ dataState = "empty";
163
+ }
164
+ let missingError;
165
+ if (dataState === "deferPartial" ||
166
+ dataState === "streamPartial" ||
167
+ (dataState === "streaming" && !returnIncremental)) {
168
+ dataState = "partial";
169
+ }
170
+ if (dataState === "partial" && !returnPartialData) {
171
+ dataState = "empty";
172
+ }
173
+ const complete = dataState === "complete";
174
+ const keepResult = complete ||
175
+ dataState === "streaming" ||
176
+ (returnPartialData && Object.keys(result).length);
177
+ const diffResult = {
178
+ result: keepResult ? result : null,
103
179
  complete,
104
- missing,
180
+ get missing() {
181
+ if (includeMissing) {
182
+ missingError ||= new common_js_1.MissingFieldError(firstMissing(missing), missing, query, variables);
183
+ }
184
+ return missingError;
185
+ },
105
186
  };
187
+ if (returnIncremental) {
188
+ diffResult.dataState =
189
+ dataState;
190
+ }
191
+ return diffResult;
106
192
  }
107
193
  isFresh(result, parent, selectionSet, context) {
108
194
  if ((0, entityStore_js_1.supportsResultCaching)(context.store) &&
@@ -121,14 +207,18 @@ class StoreReader {
121
207
  !context.store.has(objectOrReference.__ref)) {
122
208
  return {
123
209
  result: {},
210
+ dataState: "empty",
124
211
  missing: `Dangling reference to missing ${objectOrReference.__ref} object`,
212
+ partialBoundaries: new PartialBoundaries(),
125
213
  };
126
214
  }
127
215
  const { variables, policies, store } = context;
128
216
  const typename = store.getFieldValue(objectOrReference, "__typename");
129
217
  const objectsToMerge = [];
218
+ let dataState;
130
219
  let missing;
131
220
  const missingMerger = new internal_1.DeepMerger();
221
+ const partialBoundaries = new PartialBoundaries();
132
222
  if (typeof typename === "string" && !policies.rootIdsByTypename[typename]) {
133
223
  // Ensure we always include a default value for the __typename
134
224
  // field, if we have one. Note that this field can be overridden by other
@@ -141,7 +231,7 @@ class StoreReader {
141
231
  [resultName]: result.missing,
142
232
  });
143
233
  }
144
- return result.result;
234
+ return result;
145
235
  }
146
236
  const workSet = new Set(selectionSet.selections);
147
237
  workSet.forEach((selection) => {
@@ -159,36 +249,75 @@ class StoreReader {
159
249
  const resultName = (0, internal_1.resultKeyNameFromField)(selection);
160
250
  if (fieldValue === void 0) {
161
251
  if (!utilities_1.addTypenameToDocument.added(selection)) {
252
+ const id = (0, utilities_1.isReference)(objectOrReference) ? objectOrReference.__ref
253
+ : objectOrReference ? policies.identify(objectOrReference)[0]
254
+ : undefined;
162
255
  missing = missingMerger.merge(missing, {
163
- [resultName]: `Can't find field '${selection.name.value}' on ${(0, utilities_1.isReference)(objectOrReference) ?
164
- objectOrReference.__ref + " object"
165
- : "object " + JSON.stringify(objectOrReference, null, 2)}`,
256
+ [resultName]: `Can't find field '${selection.name.value}' on ${id ?
257
+ `${id} object`
258
+ : `object ${JSON.stringify(objectOrReference || {}, null, 2)}`}`,
166
259
  });
260
+ dataState = mergeDataState(dataState, "empty");
167
261
  }
168
262
  }
169
263
  else if ((0, internal_1.isArray)(fieldValue)) {
170
264
  if (fieldValue.length > 0) {
171
- fieldValue = handleMissing(this.executeSubSelectedArray({
265
+ const execResult = handleMissing(this.executeSubSelectedArray({
172
266
  field: selection,
173
267
  array: fieldValue,
174
268
  enclosingRef,
175
269
  context,
176
270
  }), resultName);
271
+ fieldValue = execResult.result;
272
+ dataState = mergeDataState(dataState, execResult.dataState);
273
+ partialBoundaries.set(resultName, execResult.partialBoundaries);
274
+ }
275
+ else {
276
+ dataState = mergeDataState(dataState, "complete");
177
277
  }
178
278
  }
179
279
  else if (!selection.selectionSet) {
180
- // do nothing
280
+ // Auto-inserted __typename should not affect dataState (see empty
281
+ // @defer boundaries, which must stay "empty" → parent "streaming").
282
+ if (!utilities_1.addTypenameToDocument.added(selection)) {
283
+ dataState = mergeDataState(dataState, "complete");
284
+ }
181
285
  }
182
286
  else if (fieldValue != null) {
287
+ if (environment_1.__DEV__) {
288
+ const fieldName = selection.name.value;
289
+ if (typename) {
290
+ const policy = policies["getFieldPolicy"](typename, fieldName);
291
+ if (policy?.scalar) {
292
+ __DEV__ && invariant_1.invariant.warn(116, `${typename}.${fieldName}`, policy.scalar);
293
+ }
294
+ }
295
+ }
183
296
  // In this case, because we know the field has a selection set,
184
297
  // it must be trying to query a GraphQLObjectType, which is why
185
298
  // fieldValue must be != null.
186
- fieldValue = handleMissing(this.executeSelectionSet({
299
+ const execResult = handleMissing(this.executeSelectionSet({
187
300
  selectionSet: selection.selectionSet,
188
301
  objectOrReference: fieldValue,
189
302
  enclosingRef: (0, utilities_1.isReference)(fieldValue) ? fieldValue : enclosingRef,
190
303
  context,
191
304
  }), resultName);
305
+ fieldValue = execResult.result;
306
+ partialBoundaries.set(resultName, execResult.partialBoundaries);
307
+ // If the object's fields resolved to an "empty" dataState (e.g. no
308
+ // field resolved with a non-undefined value), but the fieldValue
309
+ // object itself is present, this object should be considered
310
+ // partial instead of empty. This also ensures defer boundaries that
311
+ // select this object remain as partial defer boundaries rather than
312
+ // mistakenly get reported as streaming. This is especially necessary
313
+ // when combined with GraphQL Codegen which generates its type and
314
+ // relies on the outer object to be absent when its fields haven't
315
+ // streamed in. Reporting the defer boundary as "streaming" instead of
316
+ // "partial" would otherwise have the potential to cause runtime
317
+ // crashes since the runtime values and types would not line up
318
+ // properly (types expect object to be undefined, but its instead
319
+ // present without its fields)
320
+ dataState = mergeDataState(dataState, execResult.dataState === "empty" ? "partial" : execResult.dataState);
192
321
  }
193
322
  if (fieldValue !== void 0) {
194
323
  objectsToMerge.push({ [resultName]: fieldValue });
@@ -197,15 +326,60 @@ class StoreReader {
197
326
  else {
198
327
  const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
199
328
  if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
200
- throw (0, invariant_1.newInvariantError)(112, selection.name.value);
329
+ throw (0, invariant_1.newInvariantError)(117, selection.name.value);
201
330
  }
202
331
  if (fragment && policies.fragmentMatches(fragment, typename)) {
203
- fragment.selectionSet.selections.forEach(workSet.add, workSet);
332
+ const isDeferBoundary = (0, internal_1.isDeferredFragment)(selection, context.variables);
333
+ // Prior to 4.3, this branch just flattened the fragment's
334
+ // selectionSet into the existing workSet so that it continued
335
+ // iterating as if the fragment didn't exist. The cache is
336
+ // incremental aware as of 4.3 and as such, we need to resolve the
337
+ // per-fragment selection set so that we can properly strip partial
338
+ // defer fragment data when returnPartialData is false. We need to
339
+ // call execSelectionSetImpl directly (non-cached version) so that we
340
+ // scope the dataState correctly for its fields. Using the cached
341
+ // executeSelectionSet can result in cache poisoning when combined
342
+ // with the fragment registry where it might cache either a) an error
343
+ // thrown when a registered fragment references a named fragment that
344
+ // the query is expected to supply and doesn't or b) resolve to the
345
+ // wrong data result when combined with queries that provide different
346
+ // implementations of the same fragment (see inmemory/fragmentRegistry and
347
+ // cache.diff/incremental tests which provide guards against this
348
+ // behavior).
349
+ const execResult = this.execSelectionSetImpl({
350
+ selectionSet: fragment.selectionSet,
351
+ objectOrReference,
352
+ enclosingRef,
353
+ context,
354
+ });
355
+ const { result, dataState: nextDataState } = execResult;
356
+ partialBoundaries.merge(execResult.partialBoundaries);
357
+ if (result !== void 0) {
358
+ objectsToMerge.push(result);
359
+ }
360
+ if (execResult.missing) {
361
+ missing = missingMerger.merge(missing, execResult.missing);
362
+ }
363
+ if (isDeferBoundary &&
364
+ (nextDataState === "partial" || nextDataState === "empty")) {
365
+ partialBoundaries.add(selection);
366
+ }
367
+ dataState = mergeDataState(dataState, isDeferBoundary ?
368
+ nextDataState === "empty" ? "streaming"
369
+ : nextDataState === "partial" ? "deferPartial"
370
+ : nextDataState
371
+ : nextDataState);
204
372
  }
205
373
  }
206
374
  });
375
+ dataState ||= "complete";
207
376
  const result = (0, internal_1.mergeDeepArray)(objectsToMerge);
208
- const finalResult = { result, missing };
377
+ const finalResult = {
378
+ result,
379
+ missing,
380
+ dataState,
381
+ partialBoundaries,
382
+ };
209
383
  const frozen = (0, internal_1.maybeDeepFreeze)(finalResult);
210
384
  // Store this result with its selection set so that we can quickly
211
385
  // recognize it again in the StoreReader#isFresh method.
@@ -216,8 +390,11 @@ class StoreReader {
216
390
  }
217
391
  // Uncached version of executeSubSelectedArray.
218
392
  execSubSelectedArrayImpl({ field, array, enclosingRef, context, }) {
393
+ let dataState = "complete";
219
394
  let missing;
220
395
  let missingMerger = new internal_1.DeepMerger();
396
+ const partialBoundaries = new PartialBoundaries();
397
+ const isStreamed = (0, internal_1.isStreamField)(field, context.variables);
221
398
  function handleMissing(childResult, i) {
222
399
  if (childResult.missing) {
223
400
  missing = missingMerger.merge(missing, { [i]: childResult.missing });
@@ -232,23 +409,36 @@ class StoreReader {
232
409
  if (item === null) {
233
410
  return null;
234
411
  }
412
+ let execResult;
235
413
  // This is a nested array, recurse
236
414
  if ((0, internal_1.isArray)(item)) {
237
- return handleMissing(this.executeSubSelectedArray({
415
+ execResult = this.executeSubSelectedArray({
238
416
  field,
239
417
  array: item,
240
418
  enclosingRef,
241
419
  context,
242
- }), i);
420
+ });
243
421
  }
244
- // This is an object, run the selection set on it
245
- if (field.selectionSet) {
246
- return handleMissing(this.executeSelectionSet({
422
+ else if (field.selectionSet) {
423
+ execResult = this.executeSelectionSet({
247
424
  selectionSet: field.selectionSet,
248
425
  objectOrReference: item,
249
426
  enclosingRef: (0, utilities_1.isReference)(item) ? item : enclosingRef,
250
427
  context,
251
- }), i);
428
+ });
429
+ }
430
+ if (execResult) {
431
+ const { dataState: nextDataState } = execResult;
432
+ partialBoundaries.set(i, nextDataState === "partial" ?
433
+ // avoid mutating the execResult partialBoundaries object
434
+ execResult.partialBoundaries.clone().add(field)
435
+ : execResult.partialBoundaries);
436
+ dataState = mergeDataState(dataState, isStreamed ?
437
+ nextDataState === "partial" ?
438
+ "streamPartial"
439
+ : nextDataState
440
+ : nextDataState);
441
+ return handleMissing(execResult, i);
252
442
  }
253
443
  if (environment_1.__DEV__) {
254
444
  assertSelectionSetForIdValue(context.store, field, item);
@@ -257,9 +447,162 @@ class StoreReader {
257
447
  });
258
448
  return {
259
449
  result: array,
450
+ dataState,
260
451
  missing,
452
+ partialBoundaries,
261
453
  };
262
454
  }
455
+ prunePartialBoundariesImpl({ boundaries, context, data, path, selectionSet, }) {
456
+ const { variables, lookupFragment, policies } = context;
457
+ if (data == null || !boundaries) {
458
+ return { result: data, dataState: "complete" };
459
+ }
460
+ const merger = new internal_1.DeepMerger();
461
+ let changed = false;
462
+ let dataState = "complete";
463
+ const result = {};
464
+ // __typename might not be part of the selection set, so preserve it when
465
+ // available, otherwise it gets removed since it's never visited when
466
+ // iterating the selection set.
467
+ if (Object.hasOwn(data, "__typename")) {
468
+ result.__typename = data.__typename;
469
+ }
470
+ const workSet = new Set(selectionSet.selections);
471
+ workSet.forEach((selection) => {
472
+ if (!(0, internal_1.shouldInclude)(selection, variables))
473
+ return;
474
+ if ((0, internal_1.isField)(selection)) {
475
+ const resultName = (0, internal_1.resultKeyNameFromField)(selection);
476
+ if (!Object.hasOwn(data, resultName)) {
477
+ return;
478
+ }
479
+ const fieldValue = data[resultName];
480
+ if (Array.isArray(fieldValue)) {
481
+ const pruned = this.prunePartialStreamArray({
482
+ field: selection,
483
+ array: fieldValue,
484
+ boundaries: boundaries.getChild(resultName),
485
+ context,
486
+ path: path.concat(resultName),
487
+ });
488
+ changed ||= pruned.result !== fieldValue;
489
+ result[resultName] = pruned.result;
490
+ dataState = mergeDataState(dataState, pruned.dataState);
491
+ }
492
+ else if (!selection.selectionSet) {
493
+ result[resultName] = fieldValue;
494
+ }
495
+ else {
496
+ const pruned = this.prunePartialBoundaries({
497
+ data: fieldValue,
498
+ selectionSet: selection.selectionSet,
499
+ boundaries: boundaries.getChild(resultName),
500
+ context,
501
+ path: path.concat(resultName),
502
+ });
503
+ changed ||= pruned.result !== fieldValue;
504
+ dataState = mergeDataState(dataState, pruned.dataState);
505
+ // A response key can be selected by more than one selection (e.g. a
506
+ // field and an overlapping fragment), so merge their kept fields.
507
+ result[resultName] =
508
+ Object.hasOwn(result, resultName) ?
509
+ merger.merge(result[resultName], pruned.result)
510
+ : pruned.result;
511
+ }
512
+ return;
513
+ }
514
+ // Note: we do NOT set `changed` to true anywhere in this branch of the
515
+ // conditional, despite the fact that we might have encountered a
516
+ // partial @defer boundary. Dropping a fragment does not guarantee keys
517
+ // are actually dropped which can happen when overlapping sibling
518
+ // selections contribute to the construction of the object. The final
519
+ // Object.keys(result).length check actually detects whether keys were
520
+ // dropped or not.
521
+ const fragment = (0, internal_1.getFragmentFromSelection)(selection, lookupFragment);
522
+ let prune = false;
523
+ if (context.deferInfo && (0, internal_1.isDeferredFragment)(selection, variables)) {
524
+ const directive = selection.directives?.find((d) => d.name.value === "defer");
525
+ const label = directive && (0, internal_1.getDirectiveArgValue)(directive, "label", graphql_1.Kind.STRING);
526
+ prune = !!context.deferInfo.peekArray(path.concat(label || []));
527
+ }
528
+ if (fragment && policies.fragmentMatches(fragment, data.__typename)) {
529
+ if (boundaries.has(selection) || prune) {
530
+ dataState = mergeDataState(dataState, "streaming");
531
+ }
532
+ else {
533
+ fragment.selectionSet.selections.forEach(workSet.add, workSet);
534
+ }
535
+ }
536
+ });
537
+ if (Object.keys(result).length !== Object.keys(data).length) {
538
+ changed = true;
539
+ }
540
+ else if (changed && boundaries.hasSelections()) {
541
+ // Overlapping siblings may rebuild the same fields under a new object
542
+ // identity (e.g. changed === true) after a partial @defer is skipped.
543
+ // We perform a deep equality check to verify whether anything was
544
+ // actually dropped by the partial @defer fragment.
545
+ changed = !(0, equality_1.equal)(result, data);
546
+ }
547
+ return { result: changed ? result : data, dataState };
548
+ }
549
+ prunePartialStreamArrayImpl({ field, array, boundaries, context, path, }) {
550
+ if (!boundaries)
551
+ return { result: array, dataState: "complete" };
552
+ let changed = false;
553
+ let dataState = "complete";
554
+ let pruned = [];
555
+ const state = context.streamInfo?.peekArray(path)?.state;
556
+ const length = Math.min(array.length, state?.truncate ? state.streamPosition : Number.MAX_SAFE_INTEGER);
557
+ for (let i = 0; i < length; i++) {
558
+ const item = array[i];
559
+ let prunedResult = {
560
+ result: item,
561
+ dataState: "complete",
562
+ };
563
+ const boundary = boundaries.getChild(i);
564
+ if (boundary?.has(field)) {
565
+ // The presence of streamInfo determines how we truncate partial
566
+ // stream arrays. Stream info is only given to cache.diff during
567
+ // in-flight requests so we want keep items in the array equal to the
568
+ // total that have streamed in (this is represented by streamPosition
569
+ // above). For all other cache reads, partial stream boundaries are
570
+ // pruned back to an empty array.
571
+ if (state) {
572
+ state.truncate = true;
573
+ pruned = pruned.slice(0, state.streamPosition);
574
+ }
575
+ else {
576
+ pruned = [];
577
+ dataState = "complete";
578
+ }
579
+ break;
580
+ }
581
+ if (Array.isArray(item)) {
582
+ prunedResult = this.prunePartialStreamArray({
583
+ field,
584
+ array: item,
585
+ boundaries: boundaries.getChild(i),
586
+ context,
587
+ path: path.concat(i),
588
+ });
589
+ }
590
+ else if (field.selectionSet) {
591
+ prunedResult = this.prunePartialBoundaries({
592
+ data: item,
593
+ selectionSet: field.selectionSet,
594
+ boundaries: boundaries.getChild(i),
595
+ context,
596
+ path: path.concat(i),
597
+ });
598
+ }
599
+ pruned.push(prunedResult.result);
600
+ changed ||= prunedResult.result !== item;
601
+ dataState = mergeDataState(dataState, prunedResult.dataState);
602
+ }
603
+ changed ||= pruned.length !== array.length;
604
+ return { result: changed ? pruned : array, dataState };
605
+ }
263
606
  }
264
607
  exports.StoreReader = StoreReader;
265
608
  function firstMissing(tree) {
@@ -281,7 +624,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
281
624
  if ((0, internal_1.isNonNullObject)(value)) {
282
625
  (0, invariant_1.invariant)(
283
626
  !(0, utilities_1.isReference)(value),
284
- 113,
627
+ 118,
285
628
  (0, helpers_js_1.getTypenameFromStoreObject)(store, value),
286
629
  field.name.value
287
630
  );
@@ -290,4 +633,102 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
290
633
  });
291
634
  }
292
635
  }
636
+ // We deliberately leave `returnPartialData` out of `executeSelectionSet`'s
637
+ // cache key. `isFresh` runs during writes and cannot provide a reliable value
638
+ // for this option, so including it would prevent a reliable cache hit.
639
+ //
640
+ // When `returnPartialData` is false, `diffQueryAgainstStore` prunes data from
641
+ // partial @defer boundaries after reading the cached result. `PartialBoundaries`
642
+ // records the selection paths needed for that pass, including empty nodes along
643
+ // a path. Overlapping non-deferred selections must still be rebuilt so fields
644
+ // contributed only by a partial deferred sibling are removed. The prune pass
645
+ // can then skip unrelated result branches.
646
+ class PartialBoundaries {
647
+ selections = new Set();
648
+ children = new Map();
649
+ add(selection) {
650
+ this.selections.add(selection);
651
+ return this;
652
+ }
653
+ has(selection) {
654
+ return this.selections.has(selection);
655
+ }
656
+ hasSelections() {
657
+ return this.selections.size > 0;
658
+ }
659
+ getChild(key) {
660
+ return this.children.get(key);
661
+ }
662
+ clone() {
663
+ return new PartialBoundaries().merge(this);
664
+ }
665
+ set(key, boundary) {
666
+ const child = this.getChild(key);
667
+ this.children.set(key,
668
+ // Create a new PartialBoundaries instance to avoid mutating any cached
669
+ // execResult partialBoundaries objects
670
+ child ? child.clone().merge(boundary) : boundary);
671
+ }
672
+ merge(boundaries) {
673
+ boundaries.selections.forEach((selection) => this.add(selection));
674
+ boundaries.children.forEach((child, key) => this.set(key, child));
675
+ return this;
676
+ }
677
+ }
678
+ function shouldPrune({ dataState }, context) {
679
+ if (dataState === "deferPartial" || dataState === "streamPartial") {
680
+ return true;
681
+ }
682
+ if (dataState === "complete" || dataState === "streaming") {
683
+ return !!(
684
+ // If the last cache write repaired a partial @stream array to a
685
+ // complete array, the stream array might contain stale entries after
686
+ // the last written value. We only want to deliver the results up to
687
+ // the index the network wrote so we need to prune it too.
688
+ (context.streamInfo ||
689
+ // The network hasn't delivered these @defer boundaries yet, so prune
690
+ // the (possibly complete) cached data sitting at them.
691
+ context.deferInfo));
692
+ }
693
+ return false;
694
+ }
695
+ // Describes the data state transitions that change the running state when it's
696
+ // combined with the next data state. Omitted object values represent
697
+ // "impossible" merges where the data state should remain the same.
698
+ const DATA_STATE_MERGES = {
699
+ empty: {
700
+ complete: "partial",
701
+ deferPartial: "partial",
702
+ streaming: "partial",
703
+ streamPartial: "partial",
704
+ },
705
+ deferPartial: {
706
+ empty: "partial",
707
+ },
708
+ streamPartial: {
709
+ deferPartial: "deferPartial",
710
+ empty: "partial",
711
+ },
712
+ streaming: {
713
+ deferPartial: "deferPartial",
714
+ empty: "partial",
715
+ streamPartial: "streamPartial",
716
+ },
717
+ complete: {
718
+ deferPartial: "deferPartial",
719
+ streaming: "streaming",
720
+ streamPartial: "streamPartial",
721
+ empty: "partial",
722
+ },
723
+ partial: {},
724
+ };
725
+ function mergeDataState(current, next) {
726
+ if (next === "partial") {
727
+ return "partial";
728
+ }
729
+ if (!current || current === next) {
730
+ return next;
731
+ }
732
+ return DATA_STATE_MERGES[current][next] || current;
733
+ }
293
734
  //# sourceMappingURL=readFromStore.cjs.map