@apollo/client 3.9.0-alpha.4 → 3.9.0-alpha.5

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 (687) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/beige-geese-wink.md +5 -0
  3. package/.changeset/breezy-spiders-tap.md +38 -0
  4. package/.changeset/clean-items-smash.md +5 -0
  5. package/.changeset/cold-llamas-turn.md +8 -0
  6. package/.changeset/config.json +14 -0
  7. package/.changeset/dirty-kids-crash.md +5 -0
  8. package/.changeset/forty-cups-shop.md +5 -0
  9. package/.changeset/friendly-clouds-laugh.md +7 -0
  10. package/.changeset/hot-ducks-burn.md +5 -0
  11. package/.changeset/polite-avocados-warn.md +5 -0
  12. package/.changeset/pre.json +29 -0
  13. package/.changeset/quick-hats-marry.md +5 -0
  14. package/.changeset/shaggy-ears-scream.md +5 -0
  15. package/.changeset/shaggy-sheep-pull.md +5 -0
  16. package/.changeset/sixty-boxes-rest.md +8 -0
  17. package/.changeset/sour-sheep-walk.md +7 -0
  18. package/.changeset/strong-terms-perform.md +46 -0
  19. package/.changeset/thick-mice-collect.md +5 -0
  20. package/.changeset/thirty-ties-arrive.md +26 -0
  21. package/.changeset/violet-lions-draw.md +5 -0
  22. package/.changeset/wild-dolphins-jog.md +5 -0
  23. package/.changeset/yellow-flies-repeat.md +5 -0
  24. package/CHANGELOG.md +3535 -0
  25. package/apollo-client.cjs +475 -398
  26. package/apollo-client.cjs.map +1 -1
  27. package/apollo-client.min.cjs +1 -1
  28. package/cache/cache.cjs +135 -153
  29. package/cache/cache.cjs.map +1 -1
  30. package/cache/cache.cjs.native.js +135 -153
  31. package/cache/core/cache.d.ts +10 -0
  32. package/cache/core/cache.js +17 -5
  33. package/cache/core/cache.js.map +1 -1
  34. package/cache/core/types/Cache.d.ts +1 -1
  35. package/cache/core/types/Cache.js.map +1 -1
  36. package/cache/core/types/DataProxy.d.ts +92 -0
  37. package/cache/core/types/common.d.ts +1 -1
  38. package/cache/core/types/common.js +4 -1
  39. package/cache/core/types/common.js.map +1 -1
  40. package/cache/inmemory/entityStore.d.ts +10 -1
  41. package/cache/inmemory/entityStore.js +190 -29
  42. package/cache/inmemory/entityStore.js.map +1 -1
  43. package/cache/inmemory/fixPolyfills.js +9 -0
  44. package/cache/inmemory/fixPolyfills.js.map +1 -1
  45. package/cache/inmemory/fixPolyfills.native.js +12 -0
  46. package/cache/inmemory/fixPolyfills.native.js.map +1 -1
  47. package/cache/inmemory/fragmentRegistry.d.ts +1 -0
  48. package/cache/inmemory/fragmentRegistry.js +23 -14
  49. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  50. package/cache/inmemory/helpers.js +20 -11
  51. package/cache/inmemory/helpers.js.map +1 -1
  52. package/cache/inmemory/inMemoryCache.js +164 -8
  53. package/cache/inmemory/inMemoryCache.js.map +1 -1
  54. package/cache/inmemory/key-extractor.js +72 -4
  55. package/cache/inmemory/key-extractor.js.map +1 -1
  56. package/cache/inmemory/object-canon.js +87 -3
  57. package/cache/inmemory/object-canon.js.map +1 -1
  58. package/cache/inmemory/policies.js +190 -43
  59. package/cache/inmemory/policies.js.map +1 -1
  60. package/cache/inmemory/reactiveVars.js +20 -2
  61. package/cache/inmemory/reactiveVars.js.map +1 -1
  62. package/cache/inmemory/readFromStore.d.ts +4 -0
  63. package/cache/inmemory/readFromStore.js +58 -9
  64. package/cache/inmemory/readFromStore.js.map +1 -1
  65. package/cache/inmemory/types.d.ts +28 -0
  66. package/cache/inmemory/types.js.map +1 -1
  67. package/cache/inmemory/writeToStore.js +152 -25
  68. package/cache/inmemory/writeToStore.js.map +1 -1
  69. package/config/jest/setup.js +2 -0
  70. package/config/jest/setup.js.map +1 -1
  71. package/core/ApolloClient.d.ts +264 -3
  72. package/core/ApolloClient.js +235 -7
  73. package/core/ApolloClient.js.map +1 -1
  74. package/core/LocalState.d.ts +4 -6
  75. package/core/LocalState.js +56 -18
  76. package/core/LocalState.js.map +1 -1
  77. package/core/ObservableQuery.d.ts +25 -0
  78. package/core/ObservableQuery.js +239 -30
  79. package/core/ObservableQuery.js.map +1 -1
  80. package/core/QueryInfo.d.ts +3 -3
  81. package/core/QueryInfo.js +118 -13
  82. package/core/QueryInfo.js.map +1 -1
  83. package/core/QueryManager.d.ts +8 -1
  84. package/core/QueryManager.js +247 -46
  85. package/core/QueryManager.js.map +1 -1
  86. package/core/core.cjs +127 -114
  87. package/core/core.cjs.map +1 -1
  88. package/core/core.cjs.native.js +127 -114
  89. package/core/equalByQuery.js +20 -1
  90. package/core/equalByQuery.js.map +1 -1
  91. package/core/index.d.ts +1 -1
  92. package/core/index.js +19 -0
  93. package/core/index.js.map +1 -1
  94. package/core/networkStatus.d.ts +39 -0
  95. package/core/networkStatus.js +39 -0
  96. package/core/networkStatus.js.map +1 -1
  97. package/core/types.d.ts +9 -0
  98. package/core/types.js.map +1 -1
  99. package/core/watchQueryOptions.d.ts +225 -1
  100. package/core/watchQueryOptions.js.map +1 -1
  101. package/dev/dev.cjs +10 -119
  102. package/dev/dev.cjs.map +1 -1
  103. package/dev/dev.cjs.native.js +10 -119
  104. package/dev/loadErrorMessageHandler.js.map +1 -1
  105. package/errors/errors.cjs +1 -1
  106. package/errors/errors.cjs.map +1 -1
  107. package/errors/errors.cjs.native.js +1 -1
  108. package/errors/index.js +14 -1
  109. package/errors/index.js.map +1 -1
  110. package/invariantErrorCodes.js +6 -8
  111. package/link/batch/batch.cjs +2 -2
  112. package/link/batch/batch.cjs.map +1 -1
  113. package/link/batch/batch.cjs.native.js +2 -2
  114. package/link/batch/batchLink.d.ts +21 -0
  115. package/link/batch/batchLink.js +2 -1
  116. package/link/batch/batchLink.js.map +1 -1
  117. package/link/batch/batching.js +24 -1
  118. package/link/batch/batching.js.map +1 -1
  119. package/link/batch-http/batch-http.cjs +3 -2
  120. package/link/batch-http/batch-http.cjs.map +1 -1
  121. package/link/batch-http/batch-http.cjs.native.js +3 -2
  122. package/link/batch-http/batchHttpLink.d.ts +4 -0
  123. package/link/batch-http/batchHttpLink.js +53 -2
  124. package/link/batch-http/batchHttpLink.js.map +1 -1
  125. package/link/context/context.cjs.map +1 -1
  126. package/link/context/index.js +1 -0
  127. package/link/context/index.js.map +1 -1
  128. package/link/core/ApolloLink.js +12 -5
  129. package/link/core/ApolloLink.js.map +1 -1
  130. package/link/core/core.cjs +5 -5
  131. package/link/core/core.cjs.map +1 -1
  132. package/link/core/core.cjs.native.js +5 -5
  133. package/link/error/error.cjs +1 -1
  134. package/link/error/error.cjs.map +1 -1
  135. package/link/error/error.cjs.native.js +1 -1
  136. package/link/error/index.d.ts +3 -0
  137. package/link/error/index.js +4 -1
  138. package/link/error/index.js.map +1 -1
  139. package/link/http/HttpLink.d.ts +0 -2
  140. package/link/http/HttpLink.js +1 -1
  141. package/link/http/HttpLink.js.map +1 -1
  142. package/link/http/checkFetcher.js.map +1 -1
  143. package/link/http/createHttpLink.js +23 -1
  144. package/link/http/createHttpLink.js.map +1 -1
  145. package/link/http/createSignalIfSupported.d.ts +5 -0
  146. package/link/http/createSignalIfSupported.js +5 -0
  147. package/link/http/createSignalIfSupported.js.map +1 -1
  148. package/link/http/http.cjs +14 -12
  149. package/link/http/http.cjs.map +1 -1
  150. package/link/http/http.cjs.native.js +14 -12
  151. package/link/http/index.js +2 -1
  152. package/link/http/index.js.map +1 -1
  153. package/link/http/iterators/async.d.ts +4 -0
  154. package/link/http/iterators/async.js +4 -0
  155. package/link/http/iterators/async.js.map +1 -1
  156. package/link/http/iterators/nodeStream.d.ts +4 -0
  157. package/link/http/iterators/nodeStream.js +4 -0
  158. package/link/http/iterators/nodeStream.js.map +1 -1
  159. package/link/http/iterators/promise.d.ts +4 -0
  160. package/link/http/iterators/promise.js +4 -0
  161. package/link/http/iterators/promise.js.map +1 -1
  162. package/link/http/iterators/reader.d.ts +4 -0
  163. package/link/http/iterators/reader.js +4 -0
  164. package/link/http/iterators/reader.js.map +1 -1
  165. package/link/http/parseAndCheckHttpResponse.js +51 -10
  166. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  167. package/link/http/responseIterator.d.ts +4 -0
  168. package/link/http/responseIterator.js +6 -0
  169. package/link/http/responseIterator.js.map +1 -1
  170. package/link/http/rewriteURIForGET.d.ts +1 -1
  171. package/link/http/rewriteURIForGET.js +10 -0
  172. package/link/http/rewriteURIForGET.js.map +1 -1
  173. package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
  174. package/link/http/selectHttpOptionsAndBody.js +23 -0
  175. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  176. package/link/http/selectURI.js.map +1 -1
  177. package/link/http/serializeFetchParameter.js.map +1 -1
  178. package/link/persisted-queries/index.js +34 -4
  179. package/link/persisted-queries/index.js.map +1 -1
  180. package/link/persisted-queries/persisted-queries.cjs +4 -4
  181. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  182. package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
  183. package/link/remove-typename/remove-typename.cjs +12 -9
  184. package/link/remove-typename/remove-typename.cjs.map +1 -1
  185. package/link/remove-typename/remove-typename.cjs.native.js +12 -9
  186. package/link/remove-typename/removeTypenameFromVariables.js +12 -9
  187. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  188. package/link/retry/delayFunction.d.ts +29 -0
  189. package/link/retry/delayFunction.js +6 -0
  190. package/link/retry/delayFunction.js.map +1 -1
  191. package/link/retry/retry.cjs +5 -5
  192. package/link/retry/retry.cjs.map +1 -1
  193. package/link/retry/retry.cjs.native.js +5 -5
  194. package/link/retry/retryFunction.d.ts +20 -0
  195. package/link/retry/retryLink.d.ts +6 -0
  196. package/link/retry/retryLink.js +31 -6
  197. package/link/retry/retryLink.js.map +1 -1
  198. package/link/schema/index.d.ts +13 -0
  199. package/link/schema/index.js +3 -3
  200. package/link/schema/index.js.map +1 -1
  201. package/link/schema/schema.cjs +3 -3
  202. package/link/schema/schema.cjs.map +1 -1
  203. package/link/schema/schema.cjs.native.js +3 -3
  204. package/link/subscriptions/index.js +35 -2
  205. package/link/subscriptions/index.js.map +1 -1
  206. package/link/subscriptions/subscriptions.cjs +3 -2
  207. package/link/subscriptions/subscriptions.cjs.map +1 -1
  208. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  209. package/link/utils/createOperation.js.map +1 -1
  210. package/link/utils/filterOperationVariables.js +4 -0
  211. package/link/utils/filterOperationVariables.js.map +1 -1
  212. package/link/utils/toPromise.js.map +1 -1
  213. package/link/utils/transformOperation.js +3 -2
  214. package/link/utils/transformOperation.js.map +1 -1
  215. package/link/utils/utils.cjs +2 -2
  216. package/link/utils/utils.cjs.map +1 -1
  217. package/link/utils/utils.cjs.native.js +2 -2
  218. package/link/utils/validateOperation.js.map +1 -1
  219. package/link/ws/index.d.ts +12 -0
  220. package/link/ws/index.js +1 -1
  221. package/link/ws/index.js.map +1 -1
  222. package/link/ws/ws.cjs +1 -1
  223. package/link/ws/ws.cjs.map +1 -1
  224. package/link/ws/ws.cjs.native.js +1 -1
  225. package/package.json +50 -38
  226. package/react/cache/QueryReference.d.ts +18 -10
  227. package/react/cache/QueryReference.js +52 -8
  228. package/react/cache/QueryReference.js.map +1 -1
  229. package/react/cache/SuspenseCache.d.ts +10 -0
  230. package/react/cache/SuspenseCache.js +1 -2
  231. package/react/cache/SuspenseCache.js.map +1 -1
  232. package/react/cache/getSuspenseCache.js.map +1 -1
  233. package/react/cache/types.d.ts +3 -0
  234. package/react/cache/types.js.map +1 -1
  235. package/react/context/ApolloContext.d.ts +5 -0
  236. package/react/context/ApolloContext.js +10 -3
  237. package/react/context/ApolloContext.js.map +1 -1
  238. package/react/context/context.cjs +1 -3
  239. package/react/context/context.cjs.map +1 -1
  240. package/react/context/context.cjs.native.js +1 -3
  241. package/react/hoc/graphql.js.map +1 -1
  242. package/react/hoc/hoc-utils.js +3 -1
  243. package/react/hoc/hoc-utils.js.map +1 -1
  244. package/react/hoc/hoc.cjs +9 -17
  245. package/react/hoc/hoc.cjs.map +1 -1
  246. package/react/hoc/hoc.cjs.native.js +9 -17
  247. package/react/hoc/mutation-hoc.js +9 -4
  248. package/react/hoc/mutation-hoc.js.map +1 -1
  249. package/react/hoc/query-hoc.js +10 -4
  250. package/react/hoc/query-hoc.js.map +1 -1
  251. package/react/hoc/subscription-hoc.js +10 -4
  252. package/react/hoc/subscription-hoc.js.map +1 -1
  253. package/react/hoc/withApollo.js +3 -4
  254. package/react/hoc/withApollo.js.map +1 -1
  255. package/react/hooks/hooks.cjs +138 -66
  256. package/react/hooks/hooks.cjs.map +1 -1
  257. package/react/hooks/hooks.cjs.native.js +138 -66
  258. package/react/hooks/index.d.ts +2 -0
  259. package/react/hooks/index.js +1 -0
  260. package/react/hooks/index.js.map +1 -1
  261. package/react/hooks/internal/__use.js +5 -0
  262. package/react/hooks/internal/__use.js.map +1 -1
  263. package/react/hooks/internal/index.d.ts +1 -0
  264. package/react/hooks/internal/index.js +2 -0
  265. package/react/hooks/internal/index.js.map +1 -1
  266. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  267. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  268. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  269. package/react/hooks/internal/useRenderGuard.d.ts +2 -0
  270. package/react/hooks/internal/useRenderGuard.js +17 -0
  271. package/react/hooks/internal/useRenderGuard.js.map +1 -0
  272. package/react/hooks/useBackgroundQuery.js +14 -11
  273. package/react/hooks/useBackgroundQuery.js.map +1 -1
  274. package/react/hooks/useFragment.js +4 -3
  275. package/react/hooks/useFragment.js.map +1 -1
  276. package/react/hooks/useLazyQuery.js +13 -4
  277. package/react/hooks/useLazyQuery.js.map +1 -1
  278. package/react/hooks/useLoadableQuery.d.ts +30 -0
  279. package/react/hooks/useLoadableQuery.js +61 -0
  280. package/react/hooks/useLoadableQuery.js.map +1 -0
  281. package/react/hooks/useMutation.js +8 -3
  282. package/react/hooks/useMutation.js.map +1 -1
  283. package/react/hooks/useQuery.d.ts +11 -0
  284. package/react/hooks/useQuery.js +138 -6
  285. package/react/hooks/useQuery.js.map +1 -1
  286. package/react/hooks/useReactiveVar.js +5 -0
  287. package/react/hooks/useReactiveVar.js.map +1 -1
  288. package/react/hooks/useReadQuery.d.ts +19 -0
  289. package/react/hooks/useReadQuery.js +4 -10
  290. package/react/hooks/useReadQuery.js.map +1 -1
  291. package/react/hooks/useSubscription.js +5 -0
  292. package/react/hooks/useSubscription.js.map +1 -1
  293. package/react/hooks/useSuspenseQuery.js +22 -22
  294. package/react/hooks/useSuspenseQuery.js.map +1 -1
  295. package/react/hooks/useSyncExternalStore.js +53 -1
  296. package/react/hooks/useSyncExternalStore.js.map +1 -1
  297. package/react/parser/index.d.ts +3 -0
  298. package/react/parser/index.js +13 -6
  299. package/react/parser/index.js.map +1 -1
  300. package/react/parser/parser.cjs +11 -5
  301. package/react/parser/parser.cjs.map +1 -1
  302. package/react/parser/parser.cjs.native.js +11 -5
  303. package/react/ssr/RenderPromises.js +21 -1
  304. package/react/ssr/RenderPromises.js.map +1 -1
  305. package/react/ssr/getDataFromTree.js +18 -3
  306. package/react/ssr/getDataFromTree.js.map +1 -1
  307. package/react/ssr/ssr.cjs +6 -4
  308. package/react/ssr/ssr.cjs.map +1 -1
  309. package/react/ssr/ssr.cjs.native.js +6 -4
  310. package/react/types/types.d.ts +123 -1
  311. package/react/types/types.js.map +1 -1
  312. package/testing/core/core.cjs +14 -11
  313. package/testing/core/core.cjs.map +1 -1
  314. package/testing/core/core.cjs.native.js +14 -11
  315. package/testing/core/itAsync.d.ts +1 -1
  316. package/testing/core/itAsync.js.map +1 -1
  317. package/testing/core/mocking/mockFetch.d.ts +2 -2
  318. package/testing/core/mocking/mockFetch.js +8 -4
  319. package/testing/core/mocking/mockFetch.js.map +1 -1
  320. package/testing/core/mocking/mockLink.d.ts +1 -1
  321. package/testing/core/mocking/mockLink.js +17 -7
  322. package/testing/core/mocking/mockLink.js.map +1 -1
  323. package/testing/core/mocking/mockQueryManager.js +2 -0
  324. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  325. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  326. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  327. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  328. package/testing/core/mocking/mockWatchQuery.js +1 -1
  329. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  330. package/testing/core/observableToPromise.d.ts +17 -3
  331. package/testing/core/observableToPromise.js +5 -0
  332. package/testing/core/observableToPromise.js.map +1 -1
  333. package/testing/core/subscribeAndCount.js +3 -0
  334. package/testing/core/subscribeAndCount.js.map +1 -1
  335. package/testing/core/wait.js +2 -2
  336. package/testing/core/wait.js.map +1 -1
  337. package/testing/core/withConsoleSpy.d.ts +3 -0
  338. package/testing/core/withConsoleSpy.js +7 -1
  339. package/testing/core/withConsoleSpy.js.map +1 -1
  340. package/testing/core/wrap.js +2 -0
  341. package/testing/core/wrap.js.map +1 -1
  342. package/testing/internal/ObservableStream.js +14 -14
  343. package/testing/internal/ObservableStream.js.map +1 -1
  344. package/testing/internal/disposables/disableActWarnings.d.ts +10 -0
  345. package/testing/internal/disposables/disableActWarnings.js +15 -0
  346. package/testing/internal/disposables/disableActWarnings.js.map +1 -0
  347. package/testing/internal/disposables/index.d.ts +1 -0
  348. package/testing/internal/disposables/index.js +1 -0
  349. package/testing/internal/disposables/index.js.map +1 -1
  350. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  351. package/testing/internal/disposables/spyOnConsole.js +2 -0
  352. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  353. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  354. package/testing/internal/disposables/withCleanup.js +3 -0
  355. package/testing/internal/disposables/withCleanup.js.map +1 -1
  356. package/testing/internal/profile/Render.d.ts +32 -1
  357. package/testing/internal/profile/Render.js +14 -2
  358. package/testing/internal/profile/Render.js.map +1 -1
  359. package/testing/internal/profile/context.d.ts +10 -0
  360. package/testing/internal/profile/context.js +14 -0
  361. package/testing/internal/profile/context.js.map +1 -0
  362. package/testing/internal/profile/index.d.ts +2 -2
  363. package/testing/internal/profile/index.js +1 -1
  364. package/testing/internal/profile/index.js.map +1 -1
  365. package/testing/internal/profile/profile.d.ts +67 -13
  366. package/testing/internal/profile/profile.js +153 -79
  367. package/testing/internal/profile/profile.js.map +1 -1
  368. package/testing/internal/profile/traces.d.ts +4 -0
  369. package/testing/internal/profile/traces.js +9 -5
  370. package/testing/internal/profile/traces.js.map +1 -1
  371. package/testing/matchers/ProfiledComponent.js +29 -26
  372. package/testing/matchers/ProfiledComponent.js.map +1 -1
  373. package/testing/matchers/index.js +2 -0
  374. package/testing/matchers/index.js.map +1 -1
  375. package/testing/matchers/toBeGarbageCollected.d.ts +8 -0
  376. package/testing/matchers/toBeGarbageCollected.js +48 -0
  377. package/testing/matchers/toBeGarbageCollected.js.map +1 -0
  378. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  379. package/testing/matchers/toMatchDocument.js.map +1 -1
  380. package/testing/react/MockedProvider.d.ts +5 -1
  381. package/testing/react/MockedProvider.js +6 -2
  382. package/testing/react/MockedProvider.js.map +1 -1
  383. package/testing/testing.cjs +4 -2
  384. package/testing/testing.cjs.map +1 -1
  385. package/testing/testing.cjs.native.js +4 -2
  386. package/utilities/common/arrays.js +1 -0
  387. package/utilities/common/arrays.js.map +1 -1
  388. package/utilities/common/canUse.js +16 -1
  389. package/utilities/common/canUse.js.map +1 -1
  390. package/utilities/common/canonicalStringify.d.ts +17 -0
  391. package/utilities/common/canonicalStringify.js +41 -0
  392. package/utilities/common/canonicalStringify.js.map +1 -1
  393. package/utilities/common/cloneDeep.d.ts +3 -0
  394. package/utilities/common/cloneDeep.js +5 -0
  395. package/utilities/common/cloneDeep.js.map +1 -1
  396. package/utilities/common/compact.d.ts +4 -0
  397. package/utilities/common/compact.js +4 -0
  398. package/utilities/common/compact.js.map +1 -1
  399. package/utilities/common/errorHandling.js +1 -3
  400. package/utilities/common/errorHandling.js.map +1 -1
  401. package/utilities/common/incrementalResult.js +3 -0
  402. package/utilities/common/incrementalResult.js.map +1 -1
  403. package/utilities/common/makeUniqueId.js +2 -0
  404. package/utilities/common/makeUniqueId.js.map +1 -1
  405. package/utilities/common/maybeDeepFreeze.js +3 -0
  406. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  407. package/utilities/common/mergeDeep.js +12 -1
  408. package/utilities/common/mergeDeep.js.map +1 -1
  409. package/utilities/common/mergeOptions.d.ts +1 -1
  410. package/utilities/common/mergeOptions.js.map +1 -1
  411. package/utilities/common/omitDeep.js.map +1 -1
  412. package/utilities/globals/global.js +7 -1
  413. package/utilities/globals/global.js.map +1 -1
  414. package/utilities/globals/globals.cjs +4 -5
  415. package/utilities/globals/globals.cjs.map +1 -1
  416. package/utilities/globals/globals.cjs.native.js +4 -5
  417. package/utilities/globals/index.d.ts +4 -0
  418. package/utilities/globals/index.js +7 -0
  419. package/utilities/globals/index.js.map +1 -1
  420. package/utilities/globals/invariantWrappers.d.ts +40 -0
  421. package/utilities/globals/invariantWrappers.js +11 -3
  422. package/utilities/globals/invariantWrappers.js.map +1 -1
  423. package/utilities/globals/maybe.js.map +1 -1
  424. package/utilities/graphql/DocumentTransform.d.ts +6 -5
  425. package/utilities/graphql/DocumentTransform.js +48 -27
  426. package/utilities/graphql/DocumentTransform.js.map +1 -1
  427. package/utilities/graphql/directives.js +3 -0
  428. package/utilities/graphql/directives.js.map +1 -1
  429. package/utilities/graphql/fragments.d.ts +25 -0
  430. package/utilities/graphql/fragments.js +36 -0
  431. package/utilities/graphql/fragments.js.map +1 -1
  432. package/utilities/graphql/getFromAST.d.ts +5 -0
  433. package/utilities/graphql/getFromAST.js +9 -0
  434. package/utilities/graphql/getFromAST.js.map +1 -1
  435. package/utilities/graphql/print.js +4 -5
  436. package/utilities/graphql/print.js.map +1 -1
  437. package/utilities/graphql/storeUtils.d.ts +14 -0
  438. package/utilities/graphql/storeUtils.js +8 -2
  439. package/utilities/graphql/storeUtils.js.map +1 -1
  440. package/utilities/graphql/transform.js +106 -7
  441. package/utilities/graphql/transform.js.map +1 -1
  442. package/utilities/index.d.ts +2 -0
  443. package/utilities/index.js.map +1 -1
  444. package/utilities/observables/Concast.d.ts +1 -1
  445. package/utilities/observables/Concast.js +85 -2
  446. package/utilities/observables/Concast.js.map +1 -1
  447. package/utilities/observables/Observable.js +6 -0
  448. package/utilities/observables/Observable.js.map +1 -1
  449. package/utilities/observables/asyncMap.js +12 -3
  450. package/utilities/observables/asyncMap.js.map +1 -1
  451. package/utilities/observables/iteration.js +3 -0
  452. package/utilities/observables/iteration.js.map +1 -1
  453. package/utilities/observables/subclassing.js +14 -0
  454. package/utilities/observables/subclassing.js.map +1 -1
  455. package/utilities/policies/pagination.js +47 -3
  456. package/utilities/policies/pagination.js.map +1 -1
  457. package/utilities/promises/decoration.js +1 -0
  458. package/utilities/promises/decoration.js.map +1 -1
  459. package/utilities/subscriptions/relay/index.js.map +1 -1
  460. package/utilities/subscriptions/relay/relay.cjs +9 -8
  461. package/utilities/subscriptions/relay/relay.cjs.map +1 -1
  462. package/utilities/subscriptions/relay/relay.cjs.native.js +9 -8
  463. package/utilities/subscriptions/urql/index.js.map +1 -1
  464. package/utilities/subscriptions/urql/urql.cjs +9 -8
  465. package/utilities/subscriptions/urql/urql.cjs.map +1 -1
  466. package/utilities/subscriptions/urql/urql.cjs.native.js +9 -8
  467. package/utilities/types/DeepOmit.js.map +1 -1
  468. package/utilities/types/DeepPartial.d.ts +1 -1
  469. package/utilities/types/DeepPartial.js +4 -0
  470. package/utilities/types/DeepPartial.js.map +1 -1
  471. package/utilities/types/IsStrictlyAny.js.map +1 -1
  472. package/utilities/types/OnlyRequiredProperties.d.ts +7 -0
  473. package/utilities/types/OnlyRequiredProperties.js +2 -0
  474. package/utilities/types/OnlyRequiredProperties.js.map +1 -0
  475. package/utilities/types/TODO.d.ts +3 -0
  476. package/utilities/types/TODO.js +2 -0
  477. package/utilities/types/TODO.js.map +1 -0
  478. package/utilities/utilities.cjs +61 -53
  479. package/utilities/utilities.cjs.map +1 -1
  480. package/utilities/utilities.cjs.native.js +61 -53
  481. package/version.js +1 -1
  482. package/cache/core/cache.d.ts.map +0 -1
  483. package/cache/core/types/Cache.d.ts.map +0 -1
  484. package/cache/core/types/DataProxy.d.ts.map +0 -1
  485. package/cache/core/types/common.d.ts.map +0 -1
  486. package/cache/index.d.ts.map +0 -1
  487. package/cache/inmemory/entityStore.d.ts.map +0 -1
  488. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  489. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  490. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  491. package/cache/inmemory/helpers.d.ts.map +0 -1
  492. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  493. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  494. package/cache/inmemory/object-canon.d.ts.map +0 -1
  495. package/cache/inmemory/policies.d.ts.map +0 -1
  496. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  497. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  498. package/cache/inmemory/types.d.ts.map +0 -1
  499. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  500. package/config/jest/setup.d.ts.map +0 -1
  501. package/core/ApolloClient.d.ts.map +0 -1
  502. package/core/LocalState.d.ts.map +0 -1
  503. package/core/ObservableQuery.d.ts.map +0 -1
  504. package/core/QueryInfo.d.ts.map +0 -1
  505. package/core/QueryManager.d.ts.map +0 -1
  506. package/core/equalByQuery.d.ts.map +0 -1
  507. package/core/index.d.ts.map +0 -1
  508. package/core/networkStatus.d.ts.map +0 -1
  509. package/core/types.d.ts.map +0 -1
  510. package/core/watchQueryOptions.d.ts.map +0 -1
  511. package/dev/index.d.ts.map +0 -1
  512. package/dev/loadDevMessages.d.ts.map +0 -1
  513. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  514. package/dev/loadErrorMessages.d.ts.map +0 -1
  515. package/errors/index.d.ts.map +0 -1
  516. package/index.d.ts.map +0 -1
  517. package/invariantErrorCodes.d.ts.map +0 -1
  518. package/link/batch/batchLink.d.ts.map +0 -1
  519. package/link/batch/batching.d.ts.map +0 -1
  520. package/link/batch/index.d.ts.map +0 -1
  521. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  522. package/link/batch-http/index.d.ts.map +0 -1
  523. package/link/context/index.d.ts.map +0 -1
  524. package/link/core/ApolloLink.d.ts.map +0 -1
  525. package/link/core/concat.d.ts.map +0 -1
  526. package/link/core/empty.d.ts.map +0 -1
  527. package/link/core/execute.d.ts.map +0 -1
  528. package/link/core/from.d.ts.map +0 -1
  529. package/link/core/index.d.ts.map +0 -1
  530. package/link/core/split.d.ts.map +0 -1
  531. package/link/core/types.d.ts.map +0 -1
  532. package/link/error/index.d.ts.map +0 -1
  533. package/link/http/HttpLink.d.ts.map +0 -1
  534. package/link/http/checkFetcher.d.ts.map +0 -1
  535. package/link/http/createHttpLink.d.ts.map +0 -1
  536. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  537. package/link/http/index.d.ts.map +0 -1
  538. package/link/http/iterators/async.d.ts.map +0 -1
  539. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  540. package/link/http/iterators/promise.d.ts.map +0 -1
  541. package/link/http/iterators/reader.d.ts.map +0 -1
  542. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  543. package/link/http/responseIterator.d.ts.map +0 -1
  544. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  545. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  546. package/link/http/selectURI.d.ts.map +0 -1
  547. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  548. package/link/persisted-queries/index.d.ts.map +0 -1
  549. package/link/remove-typename/index.d.ts.map +0 -1
  550. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  551. package/link/retry/delayFunction.d.ts.map +0 -1
  552. package/link/retry/index.d.ts.map +0 -1
  553. package/link/retry/retryFunction.d.ts.map +0 -1
  554. package/link/retry/retryLink.d.ts.map +0 -1
  555. package/link/schema/index.d.ts.map +0 -1
  556. package/link/subscriptions/index.d.ts.map +0 -1
  557. package/link/utils/createOperation.d.ts.map +0 -1
  558. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  559. package/link/utils/fromError.d.ts.map +0 -1
  560. package/link/utils/fromPromise.d.ts.map +0 -1
  561. package/link/utils/index.d.ts.map +0 -1
  562. package/link/utils/throwServerError.d.ts.map +0 -1
  563. package/link/utils/toPromise.d.ts.map +0 -1
  564. package/link/utils/transformOperation.d.ts.map +0 -1
  565. package/link/utils/validateOperation.d.ts.map +0 -1
  566. package/link/ws/index.d.ts.map +0 -1
  567. package/react/cache/QueryReference.d.ts.map +0 -1
  568. package/react/cache/SuspenseCache.d.ts.map +0 -1
  569. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  570. package/react/cache/index.d.ts.map +0 -1
  571. package/react/cache/types.d.ts.map +0 -1
  572. package/react/components/Mutation.d.ts.map +0 -1
  573. package/react/components/Query.d.ts.map +0 -1
  574. package/react/components/Subscription.d.ts.map +0 -1
  575. package/react/components/index.d.ts.map +0 -1
  576. package/react/components/types.d.ts.map +0 -1
  577. package/react/context/ApolloConsumer.d.ts.map +0 -1
  578. package/react/context/ApolloContext.d.ts.map +0 -1
  579. package/react/context/ApolloProvider.d.ts.map +0 -1
  580. package/react/context/index.d.ts.map +0 -1
  581. package/react/hoc/graphql.d.ts.map +0 -1
  582. package/react/hoc/hoc-utils.d.ts.map +0 -1
  583. package/react/hoc/index.d.ts.map +0 -1
  584. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  585. package/react/hoc/query-hoc.d.ts.map +0 -1
  586. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  587. package/react/hoc/types.d.ts.map +0 -1
  588. package/react/hoc/withApollo.d.ts.map +0 -1
  589. package/react/hooks/constants.d.ts.map +0 -1
  590. package/react/hooks/index.d.ts.map +0 -1
  591. package/react/hooks/internal/__use.d.ts.map +0 -1
  592. package/react/hooks/internal/index.d.ts.map +0 -1
  593. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  594. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  595. package/react/hooks/useApolloClient.d.ts.map +0 -1
  596. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  597. package/react/hooks/useFragment.d.ts.map +0 -1
  598. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  599. package/react/hooks/useMutation.d.ts.map +0 -1
  600. package/react/hooks/useQuery.d.ts.map +0 -1
  601. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  602. package/react/hooks/useReadQuery.d.ts.map +0 -1
  603. package/react/hooks/useSubscription.d.ts.map +0 -1
  604. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  605. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  606. package/react/index.d.ts.map +0 -1
  607. package/react/parser/index.d.ts.map +0 -1
  608. package/react/ssr/RenderPromises.d.ts.map +0 -1
  609. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  610. package/react/ssr/index.d.ts.map +0 -1
  611. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  612. package/react/types/types.d.ts.map +0 -1
  613. package/testing/core/index.d.ts.map +0 -1
  614. package/testing/core/itAsync.d.ts.map +0 -1
  615. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  616. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  617. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  618. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  619. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  620. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  621. package/testing/core/observableToPromise.d.ts.map +0 -1
  622. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  623. package/testing/core/wait.d.ts.map +0 -1
  624. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  625. package/testing/core/wrap.d.ts.map +0 -1
  626. package/testing/index.d.ts.map +0 -1
  627. package/testing/internal/ObservableStream.d.ts.map +0 -1
  628. package/testing/internal/disposables/index.d.ts.map +0 -1
  629. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  630. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  631. package/testing/internal/index.d.ts.map +0 -1
  632. package/testing/internal/profile/Render.d.ts.map +0 -1
  633. package/testing/internal/profile/index.d.ts.map +0 -1
  634. package/testing/internal/profile/profile.d.ts.map +0 -1
  635. package/testing/internal/profile/traces.d.ts.map +0 -1
  636. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  637. package/testing/matchers/index.d.ts.map +0 -1
  638. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  639. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  640. package/testing/react/MockedProvider.d.ts.map +0 -1
  641. package/utilities/common/arrays.d.ts.map +0 -1
  642. package/utilities/common/canUse.d.ts.map +0 -1
  643. package/utilities/common/canonicalStringify.d.ts.map +0 -1
  644. package/utilities/common/cloneDeep.d.ts.map +0 -1
  645. package/utilities/common/compact.d.ts.map +0 -1
  646. package/utilities/common/errorHandling.d.ts.map +0 -1
  647. package/utilities/common/filterInPlace.d.ts +0 -2
  648. package/utilities/common/filterInPlace.d.ts.map +0 -1
  649. package/utilities/common/filterInPlace.js +0 -11
  650. package/utilities/common/filterInPlace.js.map +0 -1
  651. package/utilities/common/incrementalResult.d.ts.map +0 -1
  652. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  653. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  654. package/utilities/common/mergeDeep.d.ts.map +0 -1
  655. package/utilities/common/mergeOptions.d.ts.map +0 -1
  656. package/utilities/common/objects.d.ts.map +0 -1
  657. package/utilities/common/omitDeep.d.ts.map +0 -1
  658. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  659. package/utilities/common/stripTypename.d.ts.map +0 -1
  660. package/utilities/globals/global.d.ts.map +0 -1
  661. package/utilities/globals/index.d.ts.map +0 -1
  662. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  663. package/utilities/globals/maybe.d.ts.map +0 -1
  664. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  665. package/utilities/graphql/directives.d.ts.map +0 -1
  666. package/utilities/graphql/fragments.d.ts.map +0 -1
  667. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  668. package/utilities/graphql/operations.d.ts.map +0 -1
  669. package/utilities/graphql/print.d.ts.map +0 -1
  670. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  671. package/utilities/graphql/transform.d.ts.map +0 -1
  672. package/utilities/index.d.ts.map +0 -1
  673. package/utilities/observables/Concast.d.ts.map +0 -1
  674. package/utilities/observables/Observable.d.ts.map +0 -1
  675. package/utilities/observables/asyncMap.d.ts.map +0 -1
  676. package/utilities/observables/iteration.d.ts.map +0 -1
  677. package/utilities/observables/subclassing.d.ts.map +0 -1
  678. package/utilities/policies/pagination.d.ts.map +0 -1
  679. package/utilities/promises/decoration.d.ts.map +0 -1
  680. package/utilities/subscriptions/relay/index.d.ts.map +0 -1
  681. package/utilities/subscriptions/shared.d.ts.map +0 -1
  682. package/utilities/subscriptions/urql/index.d.ts.map +0 -1
  683. package/utilities/types/DeepOmit.d.ts.map +0 -1
  684. package/utilities/types/DeepPartial.d.ts.map +0 -1
  685. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  686. package/utilities/types/Primitive.d.ts.map +0 -1
  687. package/version.d.ts.map +0 -1
@@ -1,10 +1,11 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
2
  import { invariant, newInvariantError } from "../utilities/globals/index.js";
3
3
  import { equal } from "@wry/equality";
4
+ import { WeakCache } from "@wry/caches";
4
5
  import { execute } from "../link/core/index.js";
5
- import { compact, hasDirectives, isExecutionPatchIncrementalResult, isExecutionPatchResult, removeDirectivesFromDocument, } from "../utilities/index.js";
6
+ import { hasDirectives, isExecutionPatchIncrementalResult, isExecutionPatchResult, removeDirectivesFromDocument, } from "../utilities/index.js";
6
7
  import { canonicalStringify } from "../cache/index.js";
7
- import { getDefaultValues, getOperationDefinition, getOperationName, hasClientExports, graphQLResultHasError, getGraphQLErrorsFromResult, canUseWeakMap, Observable, asyncMap, isNonEmptyArray, Concast, makeUniqueId, isDocumentNode, isNonNullObject, DocumentTransform, } from "../utilities/index.js";
8
+ import { getDefaultValues, getOperationDefinition, getOperationName, hasClientExports, graphQLResultHasError, getGraphQLErrorsFromResult, Observable, asyncMap, isNonEmptyArray, Concast, makeUniqueId, isDocumentNode, isNonNullObject, DocumentTransform, } from "../utilities/index.js";
8
9
  import { mergeIncrementalData } from "../utilities/common/incrementalResult.js";
9
10
  import { ApolloError, isApolloError, graphQLResultHasProtocolErrors, } from "../errors/index.js";
10
11
  import { ObservableQuery, logMissingFieldErrors } from "./ObservableQuery.js";
@@ -14,19 +15,30 @@ import { QueryInfo, shouldWriteResult, } from "./QueryInfo.js";
14
15
  import { PROTOCOL_ERRORS_SYMBOL } from "../errors/index.js";
15
16
  import { print } from "../utilities/index.js";
16
17
  var hasOwnProperty = Object.prototype.hasOwnProperty;
17
- var QueryManager = (function () {
18
+ import { Trie } from "@wry/trie";
19
+ var QueryManager = /** @class */ (function () {
18
20
  function QueryManager(_a) {
19
- var _this = this;
20
21
  var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, documentTransform = _a.documentTransform, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e, defaultContext = _a.defaultContext;
22
+ var _this = this;
21
23
  this.clientAwareness = {};
24
+ // All the queries that the QueryManager is currently managing (not
25
+ // including mutations and subscriptions).
22
26
  this.queries = new Map();
27
+ // Maps from queryId strings to Promise rejection functions for
28
+ // currently active queries and fetches.
29
+ // Use protected instead of private field so
30
+ // @apollo/experimental-nextjs-app-support can access type info.
23
31
  this.fetchCancelFns = new Map();
24
- this.transformCache = new (canUseWeakMap ? WeakMap : Map)();
32
+ this.transformCache = new WeakCache( /** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */);
25
33
  this.queryIdCounter = 1;
26
34
  this.requestIdCounter = 1;
27
35
  this.mutationIdCounter = 1;
28
- this.inFlightLinkObservables = new Map();
29
- var defaultDocumentTransform = new DocumentTransform(function (document) { return _this.cache.transformDocument(document); }, { cache: false });
36
+ // Use protected instead of private field so
37
+ // @apollo/experimental-nextjs-app-support can access type info.
38
+ this.inFlightLinkObservables = new Trie(false);
39
+ var defaultDocumentTransform = new DocumentTransform(function (document) { return _this.cache.transformDocument(document); },
40
+ // Allow the apollo cache to manage its own transform caches
41
+ { cache: false });
30
42
  this.cache = cache;
31
43
  this.link = link;
32
44
  this.defaultOptions = defaultOptions || Object.create(null);
@@ -35,16 +47,31 @@ var QueryManager = (function () {
35
47
  this.localState = localState || new LocalState({ cache: cache });
36
48
  this.ssrMode = ssrMode;
37
49
  this.assumeImmutableResults = assumeImmutableResults;
38
- this.documentTransform = documentTransform
39
- ? defaultDocumentTransform
40
- .concat(documentTransform)
41
- .concat(defaultDocumentTransform)
42
- : defaultDocumentTransform;
50
+ this.documentTransform =
51
+ documentTransform ?
52
+ defaultDocumentTransform
53
+ .concat(documentTransform)
54
+ // The custom document transform may add new fragment spreads or new
55
+ // field selections, so we want to give the cache a chance to run
56
+ // again. For example, the InMemoryCache adds __typename to field
57
+ // selections and fragments from the fragment registry.
58
+ .concat(defaultDocumentTransform)
59
+ : defaultDocumentTransform;
43
60
  this.defaultContext = defaultContext || Object.create(null);
44
61
  if ((this.onBroadcast = onBroadcast)) {
45
62
  this.mutationStore = Object.create(null);
46
63
  }
64
+ // TODO: remove before we release 3.9
65
+ Object.defineProperty(this.inFlightLinkObservables, "get", {
66
+ value: function () {
67
+ throw new Error("This version of Apollo Client requires at least @apollo/experimental-nextjs-app-support version 0.5.2.");
68
+ },
69
+ });
47
70
  }
71
+ /**
72
+ * Call this method to terminate any active query processes, making it safe
73
+ * to dispose of this QueryManager instance.
74
+ */
48
75
  QueryManager.prototype.stop = function () {
49
76
  var _this = this;
50
77
  this.queries.forEach(function (_info, queryId) {
@@ -70,8 +97,8 @@ var QueryManager = (function () {
70
97
  mutation = this.cache.transformForLink(this.transform(mutation));
71
98
  hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
72
99
  variables = this.getVariables(mutation, variables);
73
- if (!hasClientExports) return [3, 2];
74
- return [4, this.localState.addExportedVariables(mutation, variables, context)];
100
+ if (!hasClientExports) return [3 /*break*/, 2];
101
+ return [4 /*yield*/, this.localState.addExportedVariables(mutation, variables, context)];
75
102
  case 1:
76
103
  variables = (_h.sent());
77
104
  _h.label = 2;
@@ -98,7 +125,7 @@ var QueryManager = (function () {
98
125
  }
99
126
  this.broadcastQueries();
100
127
  self = this;
101
- return [2, new Promise(function (resolve, reject) {
128
+ return [2 /*return*/, new Promise(function (resolve, reject) {
102
129
  return asyncMap(self.getObservableFromLink(mutation, __assign(__assign({}, context), { optimisticResponse: optimisticResponse }), variables, false), function (result) {
103
130
  if (graphQLResultHasError(result) && errorPolicy === "none") {
104
131
  throw new ApolloError({
@@ -135,6 +162,11 @@ var QueryManager = (function () {
135
162
  }).subscribe({
136
163
  next: function (storeResult) {
137
164
  self.broadcastQueries();
165
+ // Since mutations might receive multiple payloads from the
166
+ // ApolloLink chain (e.g. when used with @defer),
167
+ // we resolve with a SingleExecutionResult or after the final
168
+ // ExecutionPatchResult has arrived and we have assembled the
169
+ // multipart response into a single result.
138
170
  if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
139
171
  resolve(storeResult);
140
172
  }
@@ -148,11 +180,9 @@ var QueryManager = (function () {
148
180
  self.cache.removeOptimistic(mutationId);
149
181
  }
150
182
  self.broadcastQueries();
151
- reject(err instanceof ApolloError
152
- ? err
153
- : new ApolloError({
154
- networkError: err,
155
- }));
183
+ reject(err instanceof ApolloError ? err : (new ApolloError({
184
+ networkError: err,
185
+ })));
156
186
  },
157
187
  });
158
188
  })];
@@ -179,6 +209,9 @@ var QueryManager = (function () {
179
209
  isNonEmptyArray(result.incremental)) {
180
210
  var diff = cache.diff({
181
211
  id: "ROOT_MUTATION",
212
+ // The cache complains if passed a mutation where it expects a
213
+ // query, so we transform mutations and subscriptions to queries
214
+ // (only once, thanks to this.transformCache).
182
215
  query: this.getDocumentInfo(mutation.document).asQuery,
183
216
  variables: mutation.variables,
184
217
  optimistic: false,
@@ -189,6 +222,8 @@ var QueryManager = (function () {
189
222
  mergedData = mergeIncrementalData(diff.result, result);
190
223
  }
191
224
  if (typeof mergedData !== "undefined") {
225
+ // cast the ExecutionPatchResult to FetchResult here since
226
+ // ExecutionPatchResult never has `data` when returned from the server
192
227
  result.data = mergedData;
193
228
  cacheWrites.push({
194
229
  result: mergedData,
@@ -208,6 +243,7 @@ var QueryManager = (function () {
208
243
  }
209
244
  var updater = updateQueries_1[queryName];
210
245
  var _b = _this.queries.get(queryId), document = _b.document, variables = _b.variables;
246
+ // Read the current query result from the store.
211
247
  var _c = cache.diff({
212
248
  query: document,
213
249
  variables: variables,
@@ -215,11 +251,13 @@ var QueryManager = (function () {
215
251
  optimistic: false,
216
252
  }), currentQueryResult = _c.result, complete = _c.complete;
217
253
  if (complete && currentQueryResult) {
254
+ // Run our reducer using the current query result and the mutation result.
218
255
  var nextQueryResult = updater(currentQueryResult, {
219
256
  mutationResult: result,
220
257
  queryName: (document && getOperationName(document)) || void 0,
221
258
  queryVariables: variables,
222
259
  });
260
+ // Write the modified result back into the store if we got a new result.
223
261
  if (nextQueryResult) {
224
262
  cacheWrites.push({
225
263
  result: nextQueryResult,
@@ -243,13 +281,25 @@ var QueryManager = (function () {
243
281
  if (!skipCache) {
244
282
  cacheWrites.forEach(function (write) { return cache.write(write); });
245
283
  }
284
+ // If the mutation has some writes associated with it then we need to
285
+ // apply those writes to the store by running this reducer again with
286
+ // a write action.
246
287
  var update = mutation.update;
288
+ // Determine whether result is a SingleExecutionResult,
289
+ // or the final ExecutionPatchResult.
247
290
  var isFinalResult = !isExecutionPatchResult(result) ||
248
291
  (isExecutionPatchIncrementalResult(result) && !result.hasNext);
249
292
  if (update) {
250
293
  if (!skipCache) {
294
+ // Re-read the ROOT_MUTATION data we just wrote into the cache
295
+ // (the first cache.write call in the cacheWrites.forEach loop
296
+ // above), so field read functions have a chance to run for
297
+ // fields within mutation result objects.
251
298
  var diff = cache.diff({
252
299
  id: "ROOT_MUTATION",
300
+ // The cache complains if passed a mutation where it expects a
301
+ // query, so we transform mutations and subscriptions to queries
302
+ // (only once, thanks to this.transformCache).
253
303
  query: _this.getDocumentInfo(mutation.document).asQuery,
254
304
  variables: mutation.variables,
255
305
  optimistic: false,
@@ -265,6 +315,9 @@ var QueryManager = (function () {
265
315
  }
266
316
  }
267
317
  }
318
+ // If we've received the whole response,
319
+ // either a SingleExecutionResult or the final ExecutionPatchResult,
320
+ // call the update function.
268
321
  if (isFinalResult) {
269
322
  update(cache, result, {
270
323
  context: mutation.context,
@@ -272,6 +325,8 @@ var QueryManager = (function () {
272
325
  });
273
326
  }
274
327
  }
328
+ // TODO Do this with cache.evict({ id: 'ROOT_MUTATION' }) but make it
329
+ // shallow to allow rolling back optimistic evictions.
275
330
  if (!skipCache && !mutation.keepRootFields && isFinalResult) {
276
331
  cache.modify({
277
332
  id: "ROOT_MUTATION",
@@ -283,11 +338,21 @@ var QueryManager = (function () {
283
338
  }
284
339
  },
285
340
  include: mutation.refetchQueries,
341
+ // Write the final mutation.result to the root layer of the cache.
286
342
  optimistic: false,
343
+ // Remove the corresponding optimistic layer at the same time as we
344
+ // write the final non-optimistic result.
287
345
  removeOptimistic: mutation.removeOptimistic,
346
+ // Let the caller of client.mutate optionally determine the refetching
347
+ // behavior for watched queries after the mutation.update function runs.
348
+ // If no onQueryUpdated function was provided for this mutation, pass
349
+ // null instead of undefined to disable the default refetching behavior.
288
350
  onQueryUpdated: mutation.onQueryUpdated || null,
289
351
  }).forEach(function (result) { return results_1.push(result); });
290
352
  if (mutation.awaitRefetchQueries || mutation.onQueryUpdated) {
353
+ // Returning a promise here makes the mutation await that promise, so we
354
+ // include results in that promise's work if awaitRefetchQueries or an
355
+ // onQueryUpdated function was specified.
291
356
  return Promise.all(results_1).then(function () { return result; });
292
357
  }
293
358
  }
@@ -295,8 +360,8 @@ var QueryManager = (function () {
295
360
  };
296
361
  QueryManager.prototype.markMutationOptimistic = function (optimisticResponse, mutation) {
297
362
  var _this = this;
298
- var data = typeof optimisticResponse === "function"
299
- ? optimisticResponse(mutation.variables)
363
+ var data = typeof optimisticResponse === "function" ?
364
+ optimisticResponse(mutation.variables)
300
365
  : optimisticResponse;
301
366
  return this.cache.recordOptimisticTransaction(function (cache) {
302
367
  try {
@@ -337,6 +402,11 @@ var QueryManager = (function () {
337
402
  var transformCache = this.transformCache;
338
403
  if (!transformCache.has(document)) {
339
404
  var cacheEntry = {
405
+ // TODO These three calls (hasClientExports, shouldForceResolvers, and
406
+ // usesNonreactiveDirective) are performing independent full traversals
407
+ // of the transformed document. We should consider merging these
408
+ // traversals into a single pass in the future, though the work is
409
+ // cached after the first time.
340
410
  hasClientExports: hasClientExports(document),
341
411
  hasForcedResolvers: this.localState.shouldForceResolvers(document),
342
412
  hasNonreactiveDirective: hasDirectives(["nonreactive"], document),
@@ -347,6 +417,8 @@ var QueryManager = (function () {
347
417
  { name: "nonreactive" },
348
418
  ], document),
349
419
  defaultVars: getDefaultValues(getOperationDefinition(document)),
420
+ // Transform any mutation or subscription operations to query operations
421
+ // so we can read/write them from/to the cache.
350
422
  asQuery: __assign(__assign({}, document), { definitions: document.definitions.map(function (def) {
351
423
  if (def.kind === "OperationDefinition" &&
352
424
  def.operation !== "query") {
@@ -364,6 +436,9 @@ var QueryManager = (function () {
364
436
  };
365
437
  QueryManager.prototype.watchQuery = function (options) {
366
438
  var query = this.transform(options.query);
439
+ // assign variable default values if supplied
440
+ // NOTE: We don't modify options.query here with the transformed query to
441
+ // ensure observable.options.query is set to the raw untransformed query.
367
442
  options = __assign(__assign({}, options), { variables: this.getVariables(query, options.variables) });
368
443
  if (typeof options.notifyOnNetworkStatusChange === "undefined") {
369
444
  options.notifyOnNetworkStatusChange = false;
@@ -376,6 +451,8 @@ var QueryManager = (function () {
376
451
  });
377
452
  observable["lastQuery"] = query;
378
453
  this.queries.set(observable.queryId, queryInfo);
454
+ // We give queryInfo the transformed query to ensure the first cache diff
455
+ // uses the transformed query instead of the raw query
379
456
  queryInfo.init({
380
457
  document: query,
381
458
  observableQuery: observable,
@@ -414,9 +491,16 @@ var QueryManager = (function () {
414
491
  if (options === void 0) { options = {
415
492
  discardWatches: true,
416
493
  }; }
494
+ // Before we have sent the reset action to the store, we can no longer
495
+ // rely on the results returned by in-flight requests since these may
496
+ // depend on values that previously existed in the data portion of the
497
+ // store. So, we cancel the promises and observers that we have issued
498
+ // so far and not yet resolved (in the case of queries).
417
499
  this.cancelPendingFetches(newInvariantError(32));
418
500
  this.queries.forEach(function (queryInfo) {
419
501
  if (queryInfo.observableQuery) {
502
+ // Set loading to true so listeners don't trigger unless they want
503
+ // results with partial data.
420
504
  queryInfo.networkStatus = NetworkStatus.loading;
421
505
  }
422
506
  else {
@@ -426,6 +510,7 @@ var QueryManager = (function () {
426
510
  if (this.mutationStore) {
427
511
  this.mutationStore = Object.create(null);
428
512
  }
513
+ // begin removing data from the store
429
514
  return this.cache.reset(options);
430
515
  };
431
516
  QueryManager.prototype.getObservableQueries = function (include) {
@@ -472,6 +557,9 @@ var QueryManager = (function () {
472
557
  });
473
558
  if (legacyQueryOptions.size) {
474
559
  legacyQueryOptions.forEach(function (options) {
560
+ // We will be issuing a fresh network request for this query, so we
561
+ // pre-allocate a new query ID here, using a special prefix to enable
562
+ // cleaning up these temporary queries later, after fetching.
475
563
  var queryId = makeUniqueId("legacyOneTimeQuery");
476
564
  var queryInfo = _this.getQuery(queryId).init({
477
565
  document: options.query,
@@ -523,6 +611,8 @@ var QueryManager = (function () {
523
611
  var makeObservable = function (variables) {
524
612
  return _this.getObservableFromLink(query, context, variables).map(function (result) {
525
613
  if (fetchPolicy !== "no-cache") {
614
+ // the subscription interface should handle not sending us results we no longer subscribe to.
615
+ // XXX I don't think we ever send in an object with errors, but we might in the future...
526
616
  if (shouldWriteResult(result, errorPolicy)) {
527
617
  _this.cache.write({
528
618
  query: query,
@@ -543,6 +633,9 @@ var QueryManager = (function () {
543
633
  if (hasProtocolErrors) {
544
634
  errors.protocolErrors = result.extensions[PROTOCOL_ERRORS_SYMBOL];
545
635
  }
636
+ // `errorPolicy` is a mechanism for handling GraphQL errors, according
637
+ // to our documentation, so we throw protocol errors regardless of the
638
+ // set error policy.
546
639
  if (errorPolicy === "none" || hasProtocolErrors) {
547
640
  throw new ApolloError(errors);
548
641
  }
@@ -574,6 +667,11 @@ var QueryManager = (function () {
574
667
  this.removeQuery(queryId);
575
668
  };
576
669
  QueryManager.prototype.removeQuery = function (queryId) {
670
+ // teardown all links
671
+ // Both `QueryManager.fetchRequest` and `QueryManager.query` create separate promises
672
+ // that each add their reject functions to fetchCancelFns.
673
+ // A query created with `QueryManager.query()` could trigger a `QueryManager.fetchRequest`.
674
+ // The same queryId could have two rejection fns for two promises
577
675
  this.fetchCancelFns.delete(queryId);
578
676
  if (this.queries.has(queryId)) {
579
677
  this.getQuery(queryId).stop();
@@ -588,7 +686,9 @@ var QueryManager = (function () {
588
686
  QueryManager.prototype.getLocalState = function () {
589
687
  return this.localState;
590
688
  };
591
- QueryManager.prototype.getObservableFromLink = function (query, context, variables, deduplication) {
689
+ QueryManager.prototype.getObservableFromLink = function (query, context, variables,
690
+ // Prefer context.queryDeduplication if specified.
691
+ deduplication) {
592
692
  var _this = this;
593
693
  var _a;
594
694
  if (deduplication === void 0) { deduplication = (_a = context === null || context === void 0 ? void 0 : context.queryDeduplication) !== null && _a !== void 0 ? _a : this.queryDeduplication; }
@@ -605,19 +705,16 @@ var QueryManager = (function () {
605
705
  context = operation.context;
606
706
  if (deduplication) {
607
707
  var printedServerQuery_1 = print(serverQuery);
608
- var byVariables_1 = inFlightLinkObservables_1.get(printedServerQuery_1) || new Map();
609
- inFlightLinkObservables_1.set(printedServerQuery_1, byVariables_1);
610
708
  var varJson_1 = canonicalStringify(variables);
611
- observable = byVariables_1.get(varJson_1);
709
+ var entry = inFlightLinkObservables_1.lookup(printedServerQuery_1, varJson_1);
710
+ observable = entry.observable;
612
711
  if (!observable) {
613
712
  var concast = new Concast([
614
713
  execute(link, operation),
615
714
  ]);
616
- byVariables_1.set(varJson_1, (observable = concast));
715
+ observable = entry.observable = concast;
617
716
  concast.beforeNext(function () {
618
- if (byVariables_1.delete(varJson_1) && byVariables_1.size < 1) {
619
- inFlightLinkObservables_1.delete(printedServerQuery_1);
620
- }
717
+ inFlightLinkObservables_1.remove(printedServerQuery_1, varJson_1);
621
718
  });
622
719
  }
623
720
  }
@@ -645,16 +742,25 @@ var QueryManager = (function () {
645
742
  };
646
743
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
647
744
  var requestId = (queryInfo.lastRequestId = this.generateRequestId());
745
+ // Performing transformForLink here gives this.cache a chance to fill in
746
+ // missing fragment definitions (for example) before sending this document
747
+ // through the link chain.
648
748
  var linkDocument = this.cache.transformForLink(options.query);
649
- return asyncMap(this.getObservableFromLink(linkDocument, compact(this.defaultContext, options.context), options.variables), function (result) {
749
+ return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
650
750
  var graphQLErrors = getGraphQLErrorsFromResult(result);
651
751
  var hasErrors = graphQLErrors.length > 0;
752
+ // If we interrupted this request by calling getResultsFromLink again
753
+ // with the same QueryInfo object, we ignore the old results.
652
754
  if (requestId >= queryInfo.lastRequestId) {
653
755
  if (hasErrors && options.errorPolicy === "none") {
756
+ // Throwing here effectively calls observer.error.
654
757
  throw queryInfo.markError(new ApolloError({
655
758
  graphQLErrors: graphQLErrors,
656
759
  }));
657
760
  }
761
+ // Use linkDocument rather than queryInfo.document so the
762
+ // operation/fragments used to write the result are the same as the
763
+ // ones used to obtain it from the link.
658
764
  result = queryInfo.markResult(result, linkDocument, options, cacheWriteBehavior);
659
765
  queryInfo.markReady();
660
766
  }
@@ -669,16 +775,19 @@ var QueryManager = (function () {
669
775
  }
670
776
  return aqr;
671
777
  }, function (networkError) {
672
- var error = isApolloError(networkError)
673
- ? networkError
674
- : new ApolloError({ networkError: networkError });
778
+ var error = isApolloError(networkError) ? networkError : (new ApolloError({ networkError: networkError }));
779
+ // Avoid storing errors from older interrupted queries.
675
780
  if (requestId >= queryInfo.lastRequestId) {
676
781
  queryInfo.markError(error);
677
782
  }
678
783
  throw error;
679
784
  });
680
785
  };
681
- QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus, query) {
786
+ QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
787
+ // The initial networkStatus for this fetch, most often
788
+ // NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
789
+ // or setVariables.
790
+ networkStatus, query) {
682
791
  var _this = this;
683
792
  if (networkStatus === void 0) { networkStatus = NetworkStatus.loading; }
684
793
  if (query === void 0) { query = options.query; }
@@ -696,26 +805,49 @@ var QueryManager = (function () {
696
805
  context: context,
697
806
  });
698
807
  var fromVariables = function (variables) {
808
+ // Since normalized is always a fresh copy of options, it's safe to
809
+ // modify its properties here, rather than creating yet another new
810
+ // WatchQueryOptions object.
699
811
  normalized.variables = variables;
700
812
  var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
701
- if (normalized.fetchPolicy !== "standby" &&
813
+ if (
814
+ // If we're in standby, postpone advancing options.fetchPolicy using
815
+ // applyNextFetchPolicy.
816
+ normalized.fetchPolicy !== "standby" &&
817
+ // The "standby" policy currently returns [] from fetchQueryByPolicy, so
818
+ // this is another way to detect when nothing was done/fetched.
702
819
  sourcesWithInfo.sources.length > 0 &&
703
820
  queryInfo.observableQuery) {
704
821
  queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
705
822
  }
706
823
  return sourcesWithInfo;
707
824
  };
825
+ // This cancel function needs to be set before the concast is created,
826
+ // in case concast creation synchronously cancels the request.
708
827
  var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
709
828
  this.fetchCancelFns.set(queryId, function (reason) {
710
829
  cleanupCancelFn();
830
+ // This delay ensures the concast variable has been initialized.
711
831
  setTimeout(function () { return concast.cancel(reason); });
712
832
  });
713
833
  var concast, containsDataFromLink;
834
+ // If the query has @export(as: ...) directives, then we need to
835
+ // process those directives asynchronously. When there are no
836
+ // @export directives (the common case), we deliberately avoid
837
+ // wrapping the result of this.fetchQueryByPolicy in a Promise,
838
+ // since the timing of result delivery is (unfortunately) important
839
+ // for backwards compatibility. TODO This code could be simpler if
840
+ // we deprecated and removed LocalState.
714
841
  if (this.getDocumentInfo(normalized.query).hasClientExports) {
715
842
  concast = new Concast(this.localState
716
843
  .addExportedVariables(normalized.query, normalized.variables, normalized.context)
717
844
  .then(fromVariables)
718
845
  .then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
846
+ // there is just no way we can synchronously get the *right* value here,
847
+ // so we will assume `true`, which is the behaviour before the bug fix in
848
+ // #10597. This means that bug is not fixed in that case, and is probably
849
+ // un-fixable with reasonable effort for the edge case of @export as
850
+ // directives.
719
851
  containsDataFromLink = true;
720
852
  }
721
853
  else {
@@ -745,23 +877,71 @@ var QueryManager = (function () {
745
877
  if (updateCache) {
746
878
  this.cache.batch({
747
879
  update: updateCache,
880
+ // Since you can perform any combination of cache reads and/or writes in
881
+ // the cache.batch update function, its optimistic option can be either
882
+ // a boolean or a string, representing three distinct modes of
883
+ // operation:
884
+ //
885
+ // * false: read/write only the root layer
886
+ // * true: read/write the topmost layer
887
+ // * string: read/write a fresh optimistic layer with that ID string
888
+ //
889
+ // When typeof optimistic === "string", a new optimistic layer will be
890
+ // temporarily created within cache.batch with that string as its ID. If
891
+ // we then pass that same string as the removeOptimistic option, we can
892
+ // make cache.batch immediately remove the optimistic layer after
893
+ // running the updateCache function, triggering only one broadcast.
894
+ //
895
+ // However, the refetchQueries method accepts only true or false for its
896
+ // optimistic option (not string). We interpret true to mean a temporary
897
+ // optimistic layer should be created, to allow efficiently rolling back
898
+ // the effect of the updateCache function, which involves passing a
899
+ // string instead of true as the optimistic option to cache.batch, when
900
+ // refetchQueries receives optimistic: true.
901
+ //
902
+ // In other words, we are deliberately not supporting the use case of
903
+ // writing to an *existing* optimistic layer (using the refetchQueries
904
+ // updateCache function), since that would potentially interfere with
905
+ // other optimistic updates in progress. Instead, you can read/write
906
+ // only the root layer by passing optimistic: false to refetchQueries,
907
+ // or you can read/write a brand new optimistic layer that will be
908
+ // automatically removed by passing optimistic: true.
748
909
  optimistic: (optimistic && removeOptimistic) || false,
910
+ // The removeOptimistic option can also be provided by itself, even if
911
+ // optimistic === false, to remove some previously-added optimistic
912
+ // layer safely and efficiently, like we do in markMutationResult.
913
+ //
914
+ // If an explicit removeOptimistic string is provided with optimistic:
915
+ // true, the removeOptimistic string will determine the ID of the
916
+ // temporary optimistic layer, in case that ever matters.
749
917
  removeOptimistic: removeOptimistic,
750
918
  onWatchUpdated: function (watch, diff, lastDiff) {
751
919
  var oq = watch.watcher instanceof QueryInfo && watch.watcher.observableQuery;
752
920
  if (oq) {
753
921
  if (onQueryUpdated) {
922
+ // Since we're about to handle this query now, remove it from
923
+ // includedQueriesById, in case it was added earlier because of
924
+ // options.include.
754
925
  includedQueriesById.delete(oq.queryId);
755
926
  var result = onQueryUpdated(oq, diff, lastDiff);
756
927
  if (result === true) {
928
+ // The onQueryUpdated function requested the default refetching
929
+ // behavior by returning true.
757
930
  result = oq.refetch();
758
931
  }
932
+ // Record the result in the results Map, as long as onQueryUpdated
933
+ // did not return false to skip/ignore this result.
759
934
  if (result !== false) {
760
935
  results.set(oq, result);
761
936
  }
937
+ // Allow the default cache broadcast to happen, except when
938
+ // onQueryUpdated returns false.
762
939
  return result;
763
940
  }
764
941
  if (onQueryUpdated !== null) {
942
+ // If we don't have an onQueryUpdated function, and onQueryUpdated
943
+ // was not disabled by passing null, make sure this query is
944
+ // "included" like any other options.include-specified query.
765
945
  includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
766
946
  }
767
947
  }
@@ -772,14 +952,17 @@ var QueryManager = (function () {
772
952
  includedQueriesById.forEach(function (_a, queryId) {
773
953
  var oq = _a.oq, lastDiff = _a.lastDiff, diff = _a.diff;
774
954
  var result;
955
+ // If onQueryUpdated is provided, we want to use it for all included
956
+ // queries, even the QueryOptions ones.
775
957
  if (onQueryUpdated) {
776
958
  if (!diff) {
777
959
  var info = oq["queryInfo"];
778
- info.reset();
960
+ info.reset(); // Force info.getDiff() to read from cache.
779
961
  diff = info.getDiff();
780
962
  }
781
963
  result = onQueryUpdated(oq, diff, lastDiff);
782
964
  }
965
+ // Otherwise, we fall back to refetching.
783
966
  if (!onQueryUpdated || result === true) {
784
967
  result = oq.refetch();
785
968
  }
@@ -792,11 +975,22 @@ var QueryManager = (function () {
792
975
  });
793
976
  }
794
977
  if (removeOptimistic) {
978
+ // In case no updateCache callback was provided (so cache.batch was not
979
+ // called above, and thus did not already remove the optimistic layer),
980
+ // remove it here. Since this is a no-op when the layer has already been
981
+ // removed, we do it even if we called cache.batch above, since it's
982
+ // possible this.cache is an instance of some ApolloCache subclass other
983
+ // than InMemoryCache, and does not fully support the removeOptimistic
984
+ // option for cache.batch.
795
985
  this.cache.removeOptimistic(removeOptimistic);
796
986
  }
797
987
  return results;
798
988
  };
799
- QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a, networkStatus) {
989
+ QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a,
990
+ // The initial networkStatus for this fetch, most often
991
+ // NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
992
+ // or setVariables.
993
+ networkStatus) {
800
994
  var _this = this;
801
995
  var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
802
996
  var oldNetworkStatus = queryInfo.networkStatus;
@@ -826,6 +1020,10 @@ var QueryManager = (function () {
826
1020
  })
827
1021
  .then(function (resolved) { return fromData(resolved.data || void 0); });
828
1022
  }
1023
+ // Resolves https://github.com/apollographql/apollo-client/issues/10317.
1024
+ // If errorPolicy is 'none' and notifyOnNetworkStatusChange is true,
1025
+ // data was incorrectly returned from the cache on refetch:
1026
+ // if diff.missing exists, we should not return cache data.
829
1027
  if (errorPolicy === "none" &&
830
1028
  networkStatus === NetworkStatus.refetch &&
831
1029
  Array.isArray(diff.missing)) {
@@ -833,13 +1031,13 @@ var QueryManager = (function () {
833
1031
  }
834
1032
  return fromData(data);
835
1033
  };
836
- var cacheWriteBehavior = fetchPolicy === "no-cache"
837
- ? 0
838
- :
839
- networkStatus === NetworkStatus.refetch &&
840
- refetchWritePolicy !== "merge"
841
- ? 1
842
- : 2;
1034
+ var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0 /* CacheWriteBehavior.FORBID */
1035
+ // Watched queries must opt into overwriting existing data on refetch,
1036
+ // by passing refetchWritePolicy: "overwrite" in their WatchQueryOptions.
1037
+ : (networkStatus === NetworkStatus.refetch &&
1038
+ refetchWritePolicy !== "merge") ?
1039
+ 1 /* CacheWriteBehavior.OVERWRITE */
1040
+ : 2 /* CacheWriteBehavior.MERGE */;
843
1041
  var resultsFromLink = function () {
844
1042
  return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
845
1043
  query: query,
@@ -898,6 +1096,9 @@ var QueryManager = (function () {
898
1096
  if (shouldNotify) {
899
1097
  return {
900
1098
  fromLink: true,
1099
+ // Note that queryInfo.getDiff() for no-cache queries does not call
1100
+ // cache.diff, but instead returns a { complete: false } stub result
1101
+ // when there is no queryInfo.diff already defined.
901
1102
  sources: [resultsFromCache(queryInfo.getDiff()), resultsFromLink()],
902
1103
  };
903
1104
  }
@@ -915,7 +1116,7 @@ var QueryManager = (function () {
915
1116
  QueryManager.prototype.prepareContext = function (context) {
916
1117
  if (context === void 0) { context = {}; }
917
1118
  var newContext = this.localState.prepareContext(context);
918
- return __assign(__assign({}, newContext), { clientAwareness: this.clientAwareness });
1119
+ return __assign(__assign(__assign({}, this.defaultContext), newContext), { clientAwareness: this.clientAwareness });
919
1120
  };
920
1121
  return QueryManager;
921
1122
  }());