@apollo/client 3.8.7 → 3.8.8

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