@apollo/client 4.0.0-alpha.7 → 4.0.0-alpha.9

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 (424) hide show
  1. package/.changeset/afraid-moons-arrive.md +5 -0
  2. package/.changeset/beige-mirrors-talk.md +15 -0
  3. package/.changeset/early-eggs-develop.md +22 -0
  4. package/.changeset/forty-tomatoes-punch.md +5 -0
  5. package/.changeset/fuzzy-tips-sit.md +5 -0
  6. package/.changeset/giant-apes-thank.md +5 -0
  7. package/.changeset/khaki-keys-deliver.md +5 -0
  8. package/.changeset/large-plants-know.md +5 -0
  9. package/.changeset/mean-lizards-think.md +5 -0
  10. package/.changeset/ninety-bags-bake.md +17 -0
  11. package/.changeset/perfect-vans-give.md +7 -0
  12. package/.changeset/pre.json +16 -0
  13. package/.changeset/shaggy-pugs-add.md +52 -0
  14. package/.changeset/short-months-complain.md +5 -0
  15. package/.changeset/swift-rivers-share.md +13 -0
  16. package/.changeset/thin-peas-hear.md +16 -0
  17. package/.changeset/wicked-forks-double.md +33 -0
  18. package/CHANGELOG.md +195 -0
  19. package/__cjs/cache/core/cache.cjs +1 -1
  20. package/__cjs/cache/core/cache.cjs.map +1 -1
  21. package/__cjs/cache/core/cache.d.cts +1 -1
  22. package/__cjs/cache/core/types/Cache.cjs.map +1 -1
  23. package/__cjs/cache/core/types/Cache.d.cts +1 -1
  24. package/__cjs/cache/core/types/DataProxy.d.cts +1 -1
  25. package/__cjs/cache/core/types/common.cjs +1 -0
  26. package/__cjs/cache/core/types/common.cjs.map +1 -1
  27. package/__cjs/cache/inmemory/entityStore.cjs +7 -4
  28. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  29. package/__cjs/cache/inmemory/entityStore.d.cts +1 -0
  30. package/__cjs/cache/inmemory/fragmentRegistry.cjs.map +1 -1
  31. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  32. package/__cjs/cache/inmemory/inMemoryCache.d.cts +1 -1
  33. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  34. package/__cjs/cache/inmemory/policies.cjs +4 -4
  35. package/__cjs/cache/inmemory/reactiveVars.cjs.map +1 -1
  36. package/__cjs/cache/inmemory/reactiveVars.d.cts +1 -1
  37. package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
  38. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  39. package/__cjs/cache/inmemory/types.d.cts +1 -1
  40. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  41. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  42. package/__cjs/cache/inmemory/writeToStore.d.cts +1 -1
  43. package/__cjs/config/jest/areCombinedGraphQLErrorsEqual.cjs +2 -3
  44. package/__cjs/config/jest/areCombinedGraphQLErrorsEqual.cjs.map +1 -1
  45. package/__cjs/config/jest/areCombinedProtocolErrorsEqual.cjs +2 -3
  46. package/__cjs/config/jest/areCombinedProtocolErrorsEqual.cjs.map +1 -1
  47. package/__cjs/config/jest/areMissingFieldErrorsEqual.cjs +2 -3
  48. package/__cjs/config/jest/areMissingFieldErrorsEqual.cjs.map +1 -1
  49. package/__cjs/config/jest/areServerErrorsEqual.cjs +21 -0
  50. package/__cjs/config/jest/areServerErrorsEqual.cjs.map +1 -0
  51. package/__cjs/config/jest/areServerErrorsEqual.d.cts +3 -0
  52. package/__cjs/config/jest/resolver.cjs +11 -0
  53. package/__cjs/config/jest/resolver.cjs.map +1 -1
  54. package/__cjs/config/jest/setup.cjs +12 -1
  55. package/__cjs/config/jest/setup.cjs.map +1 -1
  56. package/__cjs/core/ApolloClient.cjs +7 -7
  57. package/__cjs/core/LocalState.cjs +2 -2
  58. package/__cjs/core/ObservableQuery.cjs +196 -66
  59. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  60. package/__cjs/core/ObservableQuery.d.cts +20 -2
  61. package/__cjs/core/QueryInfo.cjs +4 -71
  62. package/__cjs/core/QueryInfo.cjs.map +1 -1
  63. package/__cjs/core/QueryInfo.d.cts +0 -8
  64. package/__cjs/core/QueryManager.cjs +29 -50
  65. package/__cjs/core/QueryManager.cjs.map +1 -1
  66. package/__cjs/core/QueryManager.d.cts +3 -3
  67. package/__cjs/core/index.cjs +3 -1
  68. package/__cjs/core/index.cjs.map +1 -1
  69. package/__cjs/core/index.d.cts +1 -0
  70. package/__cjs/core/watchQueryOptions.d.cts +2 -2
  71. package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
  72. package/__cjs/errors/CombinedGraphQLErrors.d.cts +1 -1
  73. package/__cjs/errors/index.cjs +21 -2
  74. package/__cjs/errors/index.cjs.map +1 -1
  75. package/__cjs/errors/index.d.cts +2 -0
  76. package/__cjs/invariantErrorCodes.cjs +82 -70
  77. package/__cjs/link/context/index.cjs.map +1 -1
  78. package/__cjs/link/context/index.d.cts +1 -1
  79. package/__cjs/link/core/ApolloLink.cjs +2 -20
  80. package/__cjs/link/core/ApolloLink.cjs.map +1 -1
  81. package/__cjs/link/core/ApolloLink.d.cts +1 -3
  82. package/__cjs/link/core/types.d.cts +1 -1
  83. package/__cjs/link/error/index.cjs +13 -28
  84. package/__cjs/link/error/index.cjs.map +1 -1
  85. package/__cjs/link/error/index.d.cts +4 -15
  86. package/__cjs/link/http/checkFetcher.cjs +1 -1
  87. package/__cjs/link/http/createHttpLink.cjs +1 -1
  88. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  89. package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
  90. package/__cjs/link/persisted-queries/index.cjs +2 -2
  91. package/__cjs/link/persisted-queries/index.cjs.map +1 -1
  92. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
  93. package/__cjs/link/utils/validateOperation.cjs +1 -1
  94. package/__cjs/masking/maskDefinition.cjs +2 -2
  95. package/__cjs/masking/maskFragment.cjs +2 -2
  96. package/__cjs/masking/maskFragment.cjs.map +1 -1
  97. package/__cjs/masking/maskFragment.d.cts +1 -1
  98. package/__cjs/masking/maskOperation.cjs +1 -1
  99. package/__cjs/masking/maskOperation.cjs.map +1 -1
  100. package/__cjs/masking/maskOperation.d.cts +1 -1
  101. package/__cjs/masking/utils.cjs +1 -1
  102. package/__cjs/react/context/ApolloConsumer.cjs +1 -1
  103. package/__cjs/react/context/ApolloConsumer.cjs.map +1 -1
  104. package/__cjs/react/context/ApolloConsumer.d.cts +1 -1
  105. package/__cjs/react/context/ApolloContext.cjs +1 -1
  106. package/__cjs/react/context/ApolloContext.cjs.map +1 -1
  107. package/__cjs/react/context/ApolloContext.d.cts +1 -1
  108. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  109. package/__cjs/react/context/ApolloProvider.cjs.map +1 -1
  110. package/__cjs/react/context/ApolloProvider.d.cts +1 -1
  111. package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
  112. package/__cjs/react/hooks/internal/wrapHook.d.cts +2 -2
  113. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  114. package/__cjs/react/hooks/useApolloClient.cjs.map +1 -1
  115. package/__cjs/react/hooks/useApolloClient.d.cts +1 -1
  116. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  117. package/__cjs/react/hooks/useBackgroundQuery.d.cts +2 -2
  118. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  119. package/__cjs/react/hooks/useFragment.d.cts +1 -1
  120. package/__cjs/react/hooks/useLazyQuery.cjs +21 -24
  121. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  122. package/__cjs/react/hooks/useLazyQuery.d.cts +3 -3
  123. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  124. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  125. package/__cjs/react/hooks/useLoadableQuery.d.cts +2 -2
  126. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  127. package/__cjs/react/hooks/useMutation.d.cts +2 -2
  128. package/__cjs/react/hooks/useQuery.cjs +4 -4
  129. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  130. package/__cjs/react/hooks/useQuery.d.cts +3 -4
  131. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  132. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +2 -2
  133. package/__cjs/react/hooks/useReactiveVar.cjs.map +1 -1
  134. package/__cjs/react/hooks/useReactiveVar.d.cts +1 -1
  135. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  136. package/__cjs/react/hooks/useReadQuery.d.cts +1 -1
  137. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  138. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  139. package/__cjs/react/hooks/useSubscription.d.cts +1 -1
  140. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  141. package/__cjs/react/hooks/useSuspenseFragment.d.cts +1 -1
  142. package/__cjs/react/hooks/useSuspenseQuery.cjs +4 -4
  143. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  144. package/__cjs/react/hooks/useSuspenseQuery.d.cts +3 -3
  145. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  146. package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
  147. package/__cjs/react/internal/cache/FragmentReference.d.cts +1 -1
  148. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  149. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  150. package/__cjs/react/internal/cache/QueryReference.d.cts +1 -1
  151. package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
  152. package/__cjs/react/internal/cache/SuspenseCache.d.cts +1 -1
  153. package/__cjs/react/internal/cache/getSuspenseCache.cjs.map +1 -1
  154. package/__cjs/react/internal/cache/getSuspenseCache.d.cts +2 -2
  155. package/__cjs/react/internal/types.d.cts +1 -1
  156. package/__cjs/react/query-preloader/createQueryPreloader.cjs +1 -0
  157. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  158. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +1 -1
  159. package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
  160. package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -1
  161. package/__cjs/react/ssr/prerenderStatic.d.cts +1 -1
  162. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
  163. package/__cjs/react/types/deprecated.d.cts +1 -1
  164. package/__cjs/react/types/types.documentation.d.cts +2 -2
  165. package/__cjs/testing/core/index.cjs +2 -1
  166. package/__cjs/testing/core/index.cjs.map +1 -1
  167. package/__cjs/testing/core/index.d.cts +2 -2
  168. package/__cjs/testing/core/mocking/mockClient.cjs +3 -4
  169. package/__cjs/testing/core/mocking/mockClient.cjs.map +1 -1
  170. package/__cjs/testing/core/mocking/mockClient.d.cts +1 -1
  171. package/__cjs/testing/core/mocking/mockLink.cjs +118 -112
  172. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  173. package/__cjs/testing/core/mocking/mockLink.d.cts +26 -7
  174. package/__cjs/testing/experimental/createSchemaFetch.cjs +2 -2
  175. package/__cjs/testing/experimental/createSchemaFetch.cjs.map +1 -1
  176. package/__cjs/testing/experimental/createTestSchema.cjs.map +1 -1
  177. package/__cjs/testing/experimental/createTestSchema.d.cts +1 -1
  178. package/__cjs/testing/index.cjs +2 -1
  179. package/__cjs/testing/index.cjs.map +1 -1
  180. package/__cjs/testing/index.d.cts +1 -1
  181. package/__cjs/testing/internal/incremental.cjs.map +1 -1
  182. package/__cjs/testing/internal/incremental.d.cts +1 -1
  183. package/__cjs/testing/internal/renderHelpers.cjs.map +1 -1
  184. package/__cjs/testing/internal/renderHelpers.d.cts +1 -1
  185. package/__cjs/testing/internal/scenarios/index.cjs +9 -7
  186. package/__cjs/testing/internal/scenarios/index.cjs.map +1 -1
  187. package/__cjs/testing/internal/scenarios/index.d.cts +6 -8
  188. package/__cjs/testing/matchers/arrayWithLength.cjs +15 -0
  189. package/__cjs/testing/matchers/arrayWithLength.cjs.map +1 -0
  190. package/__cjs/testing/matchers/arrayWithLength.d.cts +3 -0
  191. package/__cjs/testing/matchers/index.cjs +2 -0
  192. package/__cjs/testing/matchers/index.cjs.map +1 -1
  193. package/__cjs/testing/matchers/toHaveSuspenseCacheEntryUsing.cjs +2 -2
  194. package/__cjs/testing/matchers/toHaveSuspenseCacheEntryUsing.cjs.map +1 -1
  195. package/__cjs/testing/matchers/toHaveSuspenseCacheEntryUsing.d.cts +1 -1
  196. package/__cjs/testing/matchers/toMatchDocument.cjs.map +1 -1
  197. package/__cjs/testing/matchers/toMatchDocument.d.cts +1 -1
  198. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs +2 -2
  199. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs.map +1 -1
  200. package/__cjs/testing/react/MockedProvider.cjs +9 -5
  201. package/__cjs/testing/react/MockedProvider.cjs.map +1 -1
  202. package/__cjs/testing/react/MockedProvider.d.cts +5 -3
  203. package/__cjs/utilities/common/mergeOptions.cjs.map +1 -1
  204. package/__cjs/utilities/common/mergeOptions.d.cts +1 -1
  205. package/__cjs/utilities/graphql/operations.cjs.map +1 -1
  206. package/__cjs/utilities/graphql/operations.d.cts +1 -1
  207. package/__cjs/utilities/index.cjs.map +1 -1
  208. package/__cjs/utilities/index.d.cts +1 -1
  209. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  210. package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -1
  211. package/__cjs/utilities/internal/toQueryResult.d.cts +1 -1
  212. package/__cjs/utilities/subscriptions/relay/index.cjs +2 -2
  213. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  214. package/__cjs/utilities/subscriptions/relay/index.d.cts +1 -1
  215. package/__cjs/version.cjs +1 -1
  216. package/__cjs/version.cjs.map +1 -1
  217. package/__cjs/version.d.cts +1 -1
  218. package/cache/core/cache.d.ts +1 -1
  219. package/cache/core/cache.js +1 -1
  220. package/cache/core/cache.js.map +1 -1
  221. package/cache/core/types/Cache.d.ts +1 -1
  222. package/cache/core/types/Cache.js.map +1 -1
  223. package/cache/core/types/DataProxy.d.ts +1 -1
  224. package/cache/core/types/common.js +1 -0
  225. package/cache/core/types/common.js.map +1 -1
  226. package/cache/inmemory/entityStore.d.ts +1 -0
  227. package/cache/inmemory/entityStore.js +7 -4
  228. package/cache/inmemory/entityStore.js.map +1 -1
  229. package/cache/inmemory/fragmentRegistry.js +1 -1
  230. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  231. package/cache/inmemory/inMemoryCache.d.ts +1 -1
  232. package/cache/inmemory/inMemoryCache.js.map +1 -1
  233. package/cache/inmemory/key-extractor.js +1 -1
  234. package/cache/inmemory/policies.js +4 -4
  235. package/cache/inmemory/reactiveVars.d.ts +1 -1
  236. package/cache/inmemory/reactiveVars.js.map +1 -1
  237. package/cache/inmemory/readFromStore.js +2 -2
  238. package/cache/inmemory/readFromStore.js.map +1 -1
  239. package/cache/inmemory/types.d.ts +1 -1
  240. package/cache/inmemory/writeToStore.d.ts +1 -1
  241. package/cache/inmemory/writeToStore.js +4 -4
  242. package/cache/inmemory/writeToStore.js.map +1 -1
  243. package/config/jest/areCombinedGraphQLErrorsEqual.js +2 -3
  244. package/config/jest/areCombinedGraphQLErrorsEqual.js.map +1 -1
  245. package/config/jest/areCombinedProtocolErrorsEqual.js +2 -3
  246. package/config/jest/areCombinedProtocolErrorsEqual.js.map +1 -1
  247. package/config/jest/areMissingFieldErrorsEqual.js +2 -3
  248. package/config/jest/areMissingFieldErrorsEqual.js.map +1 -1
  249. package/config/jest/areServerErrorsEqual.d.ts +3 -0
  250. package/config/jest/areServerErrorsEqual.js +17 -0
  251. package/config/jest/areServerErrorsEqual.js.map +1 -0
  252. package/config/jest/resolver.js +12 -1
  253. package/config/jest/resolver.js.map +1 -1
  254. package/config/jest/setup.js +13 -2
  255. package/config/jest/setup.js.map +1 -1
  256. package/core/ApolloClient.js +7 -7
  257. package/core/LocalState.js +2 -2
  258. package/core/ObservableQuery.d.ts +20 -2
  259. package/core/ObservableQuery.js +195 -64
  260. package/core/ObservableQuery.js.map +1 -1
  261. package/core/QueryInfo.d.ts +0 -8
  262. package/core/QueryInfo.js +4 -71
  263. package/core/QueryInfo.js.map +1 -1
  264. package/core/QueryManager.d.ts +3 -3
  265. package/core/QueryManager.js +30 -51
  266. package/core/QueryManager.js.map +1 -1
  267. package/core/index.d.ts +1 -0
  268. package/core/index.js +2 -1
  269. package/core/index.js.map +1 -1
  270. package/core/watchQueryOptions.d.ts +2 -2
  271. package/errors/CombinedGraphQLErrors.d.ts +1 -1
  272. package/errors/CombinedGraphQLErrors.js.map +1 -1
  273. package/errors/index.d.ts +2 -0
  274. package/errors/index.js +18 -0
  275. package/errors/index.js.map +1 -1
  276. package/invariantErrorCodes.js +82 -70
  277. package/link/context/index.d.ts +1 -1
  278. package/link/context/index.js.map +1 -1
  279. package/link/core/ApolloLink.d.ts +1 -3
  280. package/link/core/ApolloLink.js +2 -20
  281. package/link/core/ApolloLink.js.map +1 -1
  282. package/link/core/types.d.ts +1 -1
  283. package/link/error/index.d.ts +4 -15
  284. package/link/error/index.js +14 -29
  285. package/link/error/index.js.map +1 -1
  286. package/link/http/checkFetcher.js +1 -1
  287. package/link/http/createHttpLink.js +1 -1
  288. package/link/http/parseAndCheckHttpResponse.js +1 -1
  289. package/link/http/serializeFetchParameter.js +1 -1
  290. package/link/persisted-queries/index.js +3 -3
  291. package/link/persisted-queries/index.js.map +1 -1
  292. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  293. package/link/utils/validateOperation.js +1 -1
  294. package/masking/maskDefinition.js +2 -2
  295. package/masking/maskFragment.d.ts +1 -1
  296. package/masking/maskFragment.js +2 -2
  297. package/masking/maskFragment.js.map +1 -1
  298. package/masking/maskOperation.d.ts +1 -1
  299. package/masking/maskOperation.js +1 -1
  300. package/masking/maskOperation.js.map +1 -1
  301. package/masking/utils.js +1 -1
  302. package/package.json +10 -10
  303. package/react/context/ApolloConsumer.d.ts +1 -1
  304. package/react/context/ApolloConsumer.js +1 -1
  305. package/react/context/ApolloConsumer.js.map +1 -1
  306. package/react/context/ApolloContext.d.ts +1 -1
  307. package/react/context/ApolloContext.js +1 -1
  308. package/react/context/ApolloContext.js.map +1 -1
  309. package/react/context/ApolloProvider.d.ts +1 -1
  310. package/react/context/ApolloProvider.js +1 -1
  311. package/react/context/ApolloProvider.js.map +1 -1
  312. package/react/hooks/internal/wrapHook.d.ts +2 -2
  313. package/react/hooks/internal/wrapHook.js.map +1 -1
  314. package/react/hooks/useApolloClient.d.ts +1 -1
  315. package/react/hooks/useApolloClient.js +1 -1
  316. package/react/hooks/useApolloClient.js.map +1 -1
  317. package/react/hooks/useBackgroundQuery.d.ts +2 -2
  318. package/react/hooks/useBackgroundQuery.js.map +1 -1
  319. package/react/hooks/useFragment.d.ts +1 -1
  320. package/react/hooks/useFragment.js.map +1 -1
  321. package/react/hooks/useLazyQuery.d.ts +3 -3
  322. package/react/hooks/useLazyQuery.js +20 -23
  323. package/react/hooks/useLazyQuery.js.map +1 -1
  324. package/react/hooks/useLoadableQuery.d.ts +2 -2
  325. package/react/hooks/useLoadableQuery.js +2 -2
  326. package/react/hooks/useLoadableQuery.js.map +1 -1
  327. package/react/hooks/useMutation.d.ts +2 -2
  328. package/react/hooks/useMutation.js.map +1 -1
  329. package/react/hooks/useQuery.d.ts +3 -4
  330. package/react/hooks/useQuery.js +2 -2
  331. package/react/hooks/useQuery.js.map +1 -1
  332. package/react/hooks/useQueryRefHandlers.d.ts +2 -2
  333. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  334. package/react/hooks/useReactiveVar.d.ts +1 -1
  335. package/react/hooks/useReactiveVar.js.map +1 -1
  336. package/react/hooks/useReadQuery.d.ts +1 -1
  337. package/react/hooks/useReadQuery.js.map +1 -1
  338. package/react/hooks/useSubscription.d.ts +1 -1
  339. package/react/hooks/useSubscription.js +1 -1
  340. package/react/hooks/useSubscription.js.map +1 -1
  341. package/react/hooks/useSuspenseFragment.d.ts +1 -1
  342. package/react/hooks/useSuspenseFragment.js.map +1 -1
  343. package/react/hooks/useSuspenseQuery.d.ts +3 -3
  344. package/react/hooks/useSuspenseQuery.js +3 -3
  345. package/react/hooks/useSuspenseQuery.js.map +1 -1
  346. package/react/hooks/useSyncExternalStore.js +1 -1
  347. package/react/internal/cache/FragmentReference.d.ts +1 -1
  348. package/react/internal/cache/FragmentReference.js.map +1 -1
  349. package/react/internal/cache/QueryReference.d.ts +1 -1
  350. package/react/internal/cache/QueryReference.js +1 -1
  351. package/react/internal/cache/QueryReference.js.map +1 -1
  352. package/react/internal/cache/SuspenseCache.d.ts +1 -1
  353. package/react/internal/cache/SuspenseCache.js.map +1 -1
  354. package/react/internal/cache/getSuspenseCache.d.ts +2 -2
  355. package/react/internal/cache/getSuspenseCache.js.map +1 -1
  356. package/react/internal/types.d.ts +1 -1
  357. package/react/query-preloader/createQueryPreloader.d.ts +1 -1
  358. package/react/query-preloader/createQueryPreloader.js +1 -0
  359. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  360. package/react/ssr/prerenderStatic.d.ts +1 -1
  361. package/react/ssr/prerenderStatic.js +2 -2
  362. package/react/ssr/prerenderStatic.js.map +1 -1
  363. package/react/ssr/useSSRQuery.js.map +1 -1
  364. package/react/types/deprecated.d.ts +1 -1
  365. package/react/types/types.documentation.d.ts +2 -2
  366. package/testing/core/index.d.ts +2 -2
  367. package/testing/core/index.js +1 -1
  368. package/testing/core/index.js.map +1 -1
  369. package/testing/core/mocking/mockClient.d.ts +1 -1
  370. package/testing/core/mocking/mockClient.js +2 -3
  371. package/testing/core/mocking/mockClient.js.map +1 -1
  372. package/testing/core/mocking/mockLink.d.ts +26 -7
  373. package/testing/core/mocking/mockLink.js +117 -113
  374. package/testing/core/mocking/mockLink.js.map +1 -1
  375. package/testing/experimental/createSchemaFetch.js +1 -1
  376. package/testing/experimental/createSchemaFetch.js.map +1 -1
  377. package/testing/experimental/createTestSchema.d.ts +1 -1
  378. package/testing/experimental/createTestSchema.js.map +1 -1
  379. package/testing/index.d.ts +1 -1
  380. package/testing/index.js +1 -1
  381. package/testing/index.js.map +1 -1
  382. package/testing/internal/incremental.d.ts +1 -1
  383. package/testing/internal/incremental.js.map +1 -1
  384. package/testing/internal/renderHelpers.d.ts +1 -1
  385. package/testing/internal/renderHelpers.js.map +1 -1
  386. package/testing/internal/scenarios/index.d.ts +6 -8
  387. package/testing/internal/scenarios/index.js +4 -2
  388. package/testing/internal/scenarios/index.js.map +1 -1
  389. package/testing/matchers/arrayWithLength.d.ts +3 -0
  390. package/testing/matchers/arrayWithLength.js +11 -0
  391. package/testing/matchers/arrayWithLength.js.map +1 -0
  392. package/testing/matchers/index.js +2 -0
  393. package/testing/matchers/index.js.map +1 -1
  394. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts +1 -1
  395. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js +1 -1
  396. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  397. package/testing/matchers/toMatchDocument.d.ts +1 -1
  398. package/testing/matchers/toMatchDocument.js.map +1 -1
  399. package/testing/matchers/utils/getSerializableProperties.js +1 -1
  400. package/testing/matchers/utils/getSerializableProperties.js.map +1 -1
  401. package/testing/react/MockedProvider.d.ts +5 -3
  402. package/testing/react/MockedProvider.js +7 -3
  403. package/testing/react/MockedProvider.js.map +1 -1
  404. package/utilities/common/mergeOptions.d.ts +1 -1
  405. package/utilities/common/mergeOptions.js.map +1 -1
  406. package/utilities/graphql/operations.d.ts +1 -1
  407. package/utilities/graphql/operations.js.map +1 -1
  408. package/utilities/index.d.ts +1 -1
  409. package/utilities/index.js.map +1 -1
  410. package/utilities/internal/getMemoryInternals.js.map +1 -1
  411. package/utilities/internal/toQueryResult.d.ts +1 -1
  412. package/utilities/internal/toQueryResult.js.map +1 -1
  413. package/utilities/subscriptions/relay/index.d.ts +1 -1
  414. package/utilities/subscriptions/relay/index.js +1 -1
  415. package/utilities/subscriptions/relay/index.js.map +1 -1
  416. package/version.d.ts +1 -1
  417. package/version.js +1 -1
  418. package/version.js.map +1 -1
  419. package/__cjs/index.cjs +0 -9
  420. package/__cjs/index.cjs.map +0 -1
  421. package/__cjs/index.d.cts +0 -3
  422. package/index.d.ts +0 -3
  423. package/index.js +0 -4
  424. package/index.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import { equal } from "@wry/equality";
2
+ import { Slot } from "optimism";
2
3
  import { BehaviorSubject, filter, lastValueFrom, tap } from "rxjs";
3
4
  import { cloneDeep, compact, getOperationDefinition, getQueryDefinition, preventUnhandledRejection, } from "@apollo/client/utilities";
4
5
  import { __DEV__ } from "@apollo/client/utilities/environment";
@@ -8,7 +9,16 @@ import { equalByQuery } from "./equalByQuery.js";
8
9
  import { isNetworkRequestInFlight, NetworkStatus } from "./networkStatus.js";
9
10
  const { assign, hasOwnProperty } = Object;
10
11
  const newNetworkStatusSymbol = Symbol();
12
+ const uninitialized = {};
11
13
  export class ObservableQuery {
14
+ /**
15
+ * @internal
16
+ * A slot used by the `useQuery` hook to indicate that `client.watchQuery`
17
+ * should not register the query immediately, but instead wait for the query to
18
+ * be started registered with the `QueryManager` when `useSyncExternalStore`
19
+ * actively subscribes to it.
20
+ */
21
+ static inactiveOnCreation = new Slot();
12
22
  options;
13
23
  queryId;
14
24
  queryName;
@@ -29,7 +39,6 @@ export class ObservableQuery {
29
39
  }
30
40
  subject;
31
41
  observable;
32
- initialResult;
33
42
  isTornDown;
34
43
  queryManager;
35
44
  subscriptions = new Set();
@@ -43,16 +52,31 @@ export class ObservableQuery {
43
52
  networkStatus;
44
53
  constructor({ queryManager, queryInfo, options, }) {
45
54
  this.networkStatus = NetworkStatus.loading;
46
- this.initialResult = {
47
- data: undefined,
48
- loading: true,
49
- networkStatus: this.networkStatus,
50
- partial: true,
51
- };
52
- this.subject = new BehaviorSubject(this.initialResult);
55
+ let startedInactive = ObservableQuery.inactiveOnCreation.getValue();
56
+ this.subject = new BehaviorSubject(uninitialized);
53
57
  this.observable = this.subject.pipe(tap({
54
58
  subscribe: () => {
59
+ if (startedInactive) {
60
+ queryManager["queries"].set(this.queryId, queryInfo);
61
+ startedInactive = false;
62
+ }
55
63
  if (!this.subject.observed) {
64
+ if (this.subject.value === uninitialized) {
65
+ // Emitting a value in the `subscribe` callback of `tap` gives
66
+ // the subject a chance to save this initial result without
67
+ // emitting the placeholder value since this callback is executed
68
+ // before `tap` subscribes to the source observable (the subject).
69
+ // `reobserve` also has the chance to update this value if it
70
+ // synchronously emits one (usually due to reporting a cache
71
+ // value).
72
+ //
73
+ // We don't initialize the `BehaviorSubject` with
74
+ // `getInitialResult` because its possible the cache might have
75
+ // updated between when the `ObservableQuery` was instantiated and
76
+ // when it is subscribed to. Updating the value here ensures we
77
+ // report the most up-to-date result from the cache.
78
+ this.subject.next(this.getInitialResult());
79
+ }
56
80
  this.reobserve();
57
81
  // TODO: See if we can rework updatePolling to better handle this.
58
82
  // reobserve calls updatePolling but this `subscribe` callback is
@@ -67,19 +91,14 @@ export class ObservableQuery {
67
91
  this.tearDownQuery();
68
92
  }
69
93
  },
70
- }),
71
- // TODO: Conditionally filter when notifyOnNetworkStatusChange is true or
72
- // not. We want to emit the loading result if notifyOnNetworkStatusChange
73
- // is true.
74
- filter((result) =>
75
- // TODO: Remove this behavior when unifying loading state for notifyOnNetworkStatusChange
76
- (this.options.fetchPolicy === "no-cache" &&
77
- this.options.notifyOnNetworkStatusChange) ||
78
- // TODO: Remove this behavior when unifying loading state for notifyOnNetworkStatusChange
79
- (this.options.fetchPolicy === "network-only" &&
80
- !this.queryManager.prioritizeCacheValues &&
81
- this.queryInfo.getDiff().complete) ||
82
- result !== this.initialResult));
94
+ }), filter((result) => {
95
+ return (this.options.fetchPolicy !== "standby" &&
96
+ (this.options.notifyOnNetworkStatusChange ||
97
+ !result.loading ||
98
+ // data could be defined for cache-and-network fetch policies
99
+ // when emitting the cache result while loading the network result
100
+ !!result.data));
101
+ }));
83
102
  this["@@observable"] = () => this;
84
103
  if (Symbol.observable) {
85
104
  this[Symbol.observable] = () => this;
@@ -124,6 +143,50 @@ export class ObservableQuery {
124
143
  resetDiff() {
125
144
  this.queryInfo.resetDiff();
126
145
  }
146
+ getInitialResult() {
147
+ const fetchPolicy = this.queryManager.prioritizeCacheValues ?
148
+ "cache-first"
149
+ : this.options.fetchPolicy;
150
+ const defaultResult = {
151
+ data: undefined,
152
+ loading: true,
153
+ networkStatus: NetworkStatus.loading,
154
+ partial: true,
155
+ };
156
+ const cacheResult = () => {
157
+ const diff = this.queryInfo.getDiff();
158
+ return this.maskResult({
159
+ data:
160
+ // TODO: queryInfo.getDiff should handle this since cache.diff returns a
161
+ // null when returnPartialData is false
162
+ this.options.returnPartialData || diff.complete ?
163
+ diff.result ?? undefined
164
+ : undefined,
165
+ loading: !diff.complete,
166
+ networkStatus: diff.complete ? NetworkStatus.ready : NetworkStatus.loading,
167
+ partial: !diff.complete,
168
+ });
169
+ };
170
+ switch (fetchPolicy) {
171
+ case "cache-only":
172
+ case "cache-first":
173
+ return cacheResult();
174
+ case "cache-and-network":
175
+ return {
176
+ ...cacheResult(),
177
+ loading: true,
178
+ networkStatus: NetworkStatus.loading,
179
+ };
180
+ case "standby":
181
+ return {
182
+ ...defaultResult,
183
+ loading: false,
184
+ networkStatus: NetworkStatus.ready,
185
+ };
186
+ default:
187
+ return defaultResult;
188
+ }
189
+ }
127
190
  getCurrentFullResult(saveAsLastResult = true) {
128
191
  // Use the last result as long as the variables match this.variables.
129
192
  const lastResult = this.getLastResult(true);
@@ -263,7 +326,7 @@ export class ObservableQuery {
263
326
  const queryDef = getQueryDefinition(this.query);
264
327
  const vars = queryDef.variableDefinitions;
265
328
  if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
266
- __DEV__ && invariant.warn(65, variables, queryDef.name?.value || queryDef);
329
+ __DEV__ && invariant.warn(67, variables, queryDef.name?.value || queryDef);
267
330
  }
268
331
  }
269
332
  if (variables && !equal(this.options.variables, variables)) {
@@ -299,6 +362,7 @@ export class ObservableQuery {
299
362
  // fetchMore to provide an updateQuery callback that determines how
300
363
  // the data gets written to the cache.
301
364
  fetchPolicy: "no-cache",
365
+ notifyOnNetworkStatusChange: this.options.notifyOnNetworkStatusChange,
302
366
  };
303
367
  combinedOptions.query = this.transformDocument(combinedOptions.query);
304
368
  const qid = this.queryManager.generateQueryId();
@@ -322,7 +386,7 @@ export class ObservableQuery {
322
386
  const updateQuery = fetchMoreOptions?.updateQuery;
323
387
  const isCached = this.options.fetchPolicy !== "no-cache";
324
388
  if (!isCached) {
325
- invariant(updateQuery, 66);
389
+ invariant(updateQuery, 68);
326
390
  }
327
391
  return this.queryManager
328
392
  .fetchQuery(qid, combinedOptions, NetworkStatus.fetchMore)
@@ -407,7 +471,7 @@ export class ObservableQuery {
407
471
  // the cache, we still want fetchMore to deliver its final loading:false
408
472
  // result with the unchanged data.
409
473
  if (isCached && !updatedQuerySet.has(this.query)) {
410
- reobserveCacheFirst(this);
474
+ this.reobserveCacheFirst();
411
475
  }
412
476
  });
413
477
  }
@@ -435,7 +499,7 @@ export class ObservableQuery {
435
499
  onError(error);
436
500
  }
437
501
  else {
438
- __DEV__ && invariant.error(67, error);
502
+ __DEV__ && invariant.error(69, error);
439
503
  }
440
504
  return;
441
505
  }
@@ -579,8 +643,9 @@ export class ObservableQuery {
579
643
  fetch(options, newNetworkStatus, emitLoadingState, query) {
580
644
  // TODO Make sure we update the networkStatus (and infer fetchVariables)
581
645
  // before actually committing to the fetch.
582
- this.queryManager.setObservableQuery(this);
583
- return this.queryManager.fetchObservableWithInfo(this.queryId, options, newNetworkStatus, query, emitLoadingState);
646
+ const queryInfo = this.queryManager.getOrCreateQuery(this.queryId);
647
+ queryInfo.setObservableQuery(this);
648
+ return this.queryManager.fetchObservableWithInfo(queryInfo, options, newNetworkStatus, query, emitLoadingState);
584
649
  }
585
650
  // Turns polling on or off based on this.options.pollInterval.
586
651
  updatePolling() {
@@ -590,16 +655,13 @@ export class ObservableQuery {
590
655
  }
591
656
  const { pollingInfo, options: { pollInterval }, } = this;
592
657
  if (!pollInterval || !this.hasObservers()) {
593
- if (pollingInfo) {
594
- clearTimeout(pollingInfo.timeout);
595
- delete this.pollingInfo;
596
- }
658
+ this.cancelPolling();
597
659
  return;
598
660
  }
599
661
  if (pollingInfo && pollingInfo.interval === pollInterval) {
600
662
  return;
601
663
  }
602
- invariant(pollInterval, 68);
664
+ invariant(pollInterval, 70);
603
665
  const info = pollingInfo || (this.pollingInfo = {});
604
666
  info.interval = pollInterval;
605
667
  const maybeFetch = () => {
@@ -631,6 +693,13 @@ export class ObservableQuery {
631
693
  };
632
694
  poll();
633
695
  }
696
+ // This differs from stopPolling in that it does not set pollInterval to 0
697
+ cancelPolling() {
698
+ if (this.pollingInfo) {
699
+ clearTimeout(this.pollingInfo.timeout);
700
+ delete this.pollingInfo;
701
+ }
702
+ }
634
703
  updateLastResult(newResult, variables = this.variables) {
635
704
  let error = this.getLastError();
636
705
  // Preserve this.last.error unless the variables have changed.
@@ -682,6 +751,7 @@ export class ObservableQuery {
682
751
  // We want to ensure we can re-run the custom document transforms the next
683
752
  // time a request is made against the original query.
684
753
  const query = this.transformDocument(options.query);
754
+ const { fetchPolicy } = options;
685
755
  this.lastQuery = query;
686
756
  if (!useDisposableObservable) {
687
757
  // We can skip calling updatePolling if we're not changing this.options.
@@ -692,10 +762,10 @@ export class ObservableQuery {
692
762
  newOptions.variables &&
693
763
  !equal(newOptions.variables, oldVariables) &&
694
764
  // Don't mess with the fetchPolicy if it's currently "standby".
695
- options.fetchPolicy !== "standby" &&
765
+ fetchPolicy !== "standby" &&
696
766
  // If we're changing the fetchPolicy anyway, don't try to change it here
697
767
  // using applyNextFetchPolicy. The explicit options.fetchPolicy wins.
698
- (options.fetchPolicy === oldFetchPolicy ||
768
+ (fetchPolicy === oldFetchPolicy ||
699
769
  // A `nextFetchPolicy` function has even higher priority, though,
700
770
  // so in that case `applyNextFetchPolicy` must be called.
701
771
  typeof options.nextFetchPolicy === "function")) {
@@ -713,6 +783,14 @@ export class ObservableQuery {
713
783
  !equal(newOptions.variables, oldVariables)) {
714
784
  newNetworkStatus = NetworkStatus.setVariables;
715
785
  }
786
+ // QueryManager does not emit any values for standby fetch policies so we
787
+ // want ensure that the networkStatus remains ready.
788
+ if (fetchPolicy === "standby") {
789
+ newNetworkStatus = NetworkStatus.ready;
790
+ }
791
+ }
792
+ if (fetchPolicy === "standby") {
793
+ this.cancelPolling();
716
794
  }
717
795
  this.networkStatus = newNetworkStatus;
718
796
  this.waitForOwnResult &&= skipCacheDataFor(options.fetchPolicy);
@@ -722,7 +800,7 @@ export class ObservableQuery {
722
800
  }
723
801
  };
724
802
  const variables = options.variables && { ...options.variables };
725
- const { notifyOnNetworkStatusChange = false } = options;
803
+ const { notifyOnNetworkStatusChange = true } = options;
726
804
  const { observable, fromLink } = this.fetch(options, newNetworkStatus, notifyOnNetworkStatusChange &&
727
805
  oldNetworkStatus !== newNetworkStatus &&
728
806
  isNetworkRequestInFlight(newNetworkStatus), query);
@@ -835,40 +913,93 @@ export class ObservableQuery {
835
913
  }
836
914
  : result;
837
915
  }
838
- }
839
- // Reobserve with fetchPolicy effectively set to "cache-first", triggering
840
- // delivery of any new data from the cache, possibly falling back to the network
841
- // if any cache data are missing. This allows _complete_ cache results to be
842
- // delivered without also kicking off unnecessary network requests when
843
- // this.options.fetchPolicy is "cache-and-network" or "network-only". When
844
- // this.options.fetchPolicy is any other policy ("cache-first", "cache-only",
845
- // "standby", or "no-cache"), we call this.reobserve() as usual.
846
- export function reobserveCacheFirst(obsQuery) {
847
- const { fetchPolicy, nextFetchPolicy } = obsQuery.options;
848
- if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
849
- return obsQuery.reobserve({
850
- fetchPolicy: "cache-first",
851
- // Use a temporary nextFetchPolicy function that replaces itself with the
852
- // previous nextFetchPolicy value and returns the original fetchPolicy.
853
- nextFetchPolicy(currentFetchPolicy, context) {
854
- // Replace this nextFetchPolicy function in the options object with the
855
- // original this.options.nextFetchPolicy value.
856
- this.nextFetchPolicy = nextFetchPolicy;
857
- // If the original nextFetchPolicy value was a function, give it a
858
- // chance to decide what happens here.
859
- if (typeof this.nextFetchPolicy === "function") {
860
- return this.nextFetchPolicy(currentFetchPolicy, context);
916
+ dirty = false;
917
+ notifyTimeout;
918
+ /** @internal */
919
+ resetNotifications() {
920
+ this.cancelNotifyTimeout();
921
+ this.dirty = false;
922
+ }
923
+ cancelNotifyTimeout() {
924
+ if (this.notifyTimeout) {
925
+ clearTimeout(this.notifyTimeout);
926
+ this.notifyTimeout = void 0;
927
+ }
928
+ }
929
+ /** @internal */
930
+ scheduleNotify() {
931
+ if (this.dirty)
932
+ return;
933
+ this.dirty = true;
934
+ if (!this.notifyTimeout) {
935
+ this.notifyTimeout = setTimeout(() => this.notify(), 0);
936
+ }
937
+ }
938
+ /** @internal */
939
+ notify() {
940
+ this.cancelNotifyTimeout();
941
+ if (this.dirty) {
942
+ if (this.options.fetchPolicy == "cache-only" ||
943
+ this.options.fetchPolicy == "cache-and-network" ||
944
+ !isNetworkRequestInFlight(this.networkStatus)) {
945
+ const diff = this.queryInfo.getDiff();
946
+ if (diff.fromOptimisticTransaction) {
947
+ // If this diff came from an optimistic transaction, deliver the
948
+ // current cache data to the ObservableQuery, but don't perform a
949
+ // reobservation, since oq.reobserveCacheFirst might make a network
950
+ // request, and we never want to trigger network requests in the
951
+ // middle of optimistic updates.
952
+ this.observe();
861
953
  }
862
- // Otherwise go back to the original this.options.fetchPolicy.
863
- return fetchPolicy;
864
- },
865
- });
954
+ else {
955
+ // Otherwise, make the ObservableQuery "reobserve" the latest data
956
+ // using a temporary fetch policy of "cache-first", so complete cache
957
+ // results have a chance to be delivered without triggering additional
958
+ // network requests, even when options.fetchPolicy is "network-only"
959
+ // or "cache-and-network". All other fetch policies are preserved by
960
+ // this method, and are handled by calling oq.reobserve(). If this
961
+ // reobservation is spurious, isDifferentFromLastResult still has a
962
+ // chance to catch it before delivery to ObservableQuery subscribers.
963
+ this.reobserveCacheFirst();
964
+ }
965
+ }
966
+ }
967
+ this.dirty = false;
968
+ }
969
+ // Reobserve with fetchPolicy effectively set to "cache-first", triggering
970
+ // delivery of any new data from the cache, possibly falling back to the network
971
+ // if any cache data are missing. This allows _complete_ cache results to be
972
+ // delivered without also kicking off unnecessary network requests when
973
+ // this.options.fetchPolicy is "cache-and-network" or "network-only". When
974
+ // this.options.fetchPolicy is any other policy ("cache-first", "cache-only",
975
+ // "standby", or "no-cache"), we call this.reobserve() as usual.
976
+ reobserveCacheFirst() {
977
+ const { fetchPolicy, nextFetchPolicy } = this.options;
978
+ if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
979
+ return this.reobserve({
980
+ fetchPolicy: "cache-first",
981
+ // Use a temporary nextFetchPolicy function that replaces itself with the
982
+ // previous nextFetchPolicy value and returns the original fetchPolicy.
983
+ nextFetchPolicy(currentFetchPolicy, context) {
984
+ // Replace this nextFetchPolicy function in the options object with the
985
+ // original this.options.nextFetchPolicy value.
986
+ this.nextFetchPolicy = nextFetchPolicy;
987
+ // If the original nextFetchPolicy value was a function, give it a
988
+ // chance to decide what happens here.
989
+ if (typeof this.nextFetchPolicy === "function") {
990
+ return this.nextFetchPolicy(currentFetchPolicy, context);
991
+ }
992
+ // Otherwise go back to the original this.options.fetchPolicy.
993
+ return fetchPolicy;
994
+ },
995
+ });
996
+ }
997
+ return this.reobserve();
866
998
  }
867
- return obsQuery.reobserve();
868
999
  }
869
1000
  export function logMissingFieldErrors(missing) {
870
1001
  if (__DEV__ && missing) {
871
- __DEV__ && invariant.debug(69, missing);
1002
+ __DEV__ && invariant.debug(71, missing);
872
1003
  }
873
1004
  }
874
1005
  function skipCacheDataFor(fetchPolicy /* `undefined` would mean `"cache-first"` */) {