@apollo/client 3.8.7 → 3.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (614) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +14 -0
  3. package/CHANGELOG.md +3369 -0
  4. package/apollo-client.cjs +356 -354
  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.d.ts +1 -1
  120. package/link/http/checkFetcher.js.map +1 -1
  121. package/link/http/createHttpLink.js +23 -1
  122. package/link/http/createHttpLink.js.map +1 -1
  123. package/link/http/createSignalIfSupported.d.ts +5 -0
  124. package/link/http/createSignalIfSupported.js +5 -0
  125. package/link/http/createSignalIfSupported.js.map +1 -1
  126. package/link/http/http.cjs +14 -15
  127. package/link/http/http.cjs.map +1 -1
  128. package/link/http/http.cjs.native.js +14 -15
  129. package/link/http/index.js +2 -1
  130. package/link/http/index.js.map +1 -1
  131. package/link/http/iterators/async.d.ts +4 -0
  132. package/link/http/iterators/async.js +4 -0
  133. package/link/http/iterators/async.js.map +1 -1
  134. package/link/http/iterators/nodeStream.d.ts +4 -0
  135. package/link/http/iterators/nodeStream.js +4 -0
  136. package/link/http/iterators/nodeStream.js.map +1 -1
  137. package/link/http/iterators/promise.d.ts +4 -0
  138. package/link/http/iterators/promise.js +4 -0
  139. package/link/http/iterators/promise.js.map +1 -1
  140. package/link/http/iterators/reader.d.ts +4 -0
  141. package/link/http/iterators/reader.js +4 -0
  142. package/link/http/iterators/reader.js.map +1 -1
  143. package/link/http/parseAndCheckHttpResponse.js +50 -13
  144. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  145. package/link/http/responseIterator.d.ts +4 -0
  146. package/link/http/responseIterator.js +6 -0
  147. package/link/http/responseIterator.js.map +1 -1
  148. package/link/http/rewriteURIForGET.d.ts +1 -1
  149. package/link/http/rewriteURIForGET.js +10 -0
  150. package/link/http/rewriteURIForGET.js.map +1 -1
  151. package/link/http/selectHttpOptionsAndBody.d.ts +46 -1
  152. package/link/http/selectHttpOptionsAndBody.js +23 -0
  153. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  154. package/link/http/selectURI.js.map +1 -1
  155. package/link/http/serializeFetchParameter.js.map +1 -1
  156. package/link/persisted-queries/index.js +34 -4
  157. package/link/persisted-queries/index.js.map +1 -1
  158. package/link/persisted-queries/persisted-queries.cjs +4 -4
  159. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  160. package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
  161. package/link/remove-typename/remove-typename.cjs +12 -9
  162. package/link/remove-typename/remove-typename.cjs.map +1 -1
  163. package/link/remove-typename/remove-typename.cjs.native.js +12 -9
  164. package/link/remove-typename/removeTypenameFromVariables.js +12 -9
  165. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  166. package/link/retry/delayFunction.d.ts +29 -0
  167. package/link/retry/delayFunction.js +6 -0
  168. package/link/retry/delayFunction.js.map +1 -1
  169. package/link/retry/retry.cjs +5 -5
  170. package/link/retry/retry.cjs.map +1 -1
  171. package/link/retry/retry.cjs.native.js +5 -5
  172. package/link/retry/retryFunction.d.ts +20 -0
  173. package/link/retry/retryLink.d.ts +6 -0
  174. package/link/retry/retryLink.js +31 -6
  175. package/link/retry/retryLink.js.map +1 -1
  176. package/link/schema/index.d.ts +13 -0
  177. package/link/schema/index.js +3 -3
  178. package/link/schema/index.js.map +1 -1
  179. package/link/schema/schema.cjs +3 -3
  180. package/link/schema/schema.cjs.map +1 -1
  181. package/link/schema/schema.cjs.native.js +3 -3
  182. package/link/subscriptions/index.js +35 -2
  183. package/link/subscriptions/index.js.map +1 -1
  184. package/link/subscriptions/subscriptions.cjs +3 -2
  185. package/link/subscriptions/subscriptions.cjs.map +1 -1
  186. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  187. package/link/utils/createOperation.js.map +1 -1
  188. package/link/utils/filterOperationVariables.js +4 -0
  189. package/link/utils/filterOperationVariables.js.map +1 -1
  190. package/link/utils/toPromise.js.map +1 -1
  191. package/link/utils/transformOperation.js +3 -2
  192. package/link/utils/transformOperation.js.map +1 -1
  193. package/link/utils/utils.cjs +2 -2
  194. package/link/utils/utils.cjs.map +1 -1
  195. package/link/utils/utils.cjs.native.js +2 -2
  196. package/link/utils/validateOperation.js.map +1 -1
  197. package/link/ws/index.d.ts +12 -0
  198. package/link/ws/index.js +1 -1
  199. package/link/ws/index.js.map +1 -1
  200. package/link/ws/ws.cjs +1 -1
  201. package/link/ws/ws.cjs.map +1 -1
  202. package/link/ws/ws.cjs.native.js +1 -1
  203. package/package.json +56 -45
  204. package/react/cache/QueryReference.d.ts +6 -1
  205. package/react/cache/QueryReference.js +26 -1
  206. package/react/cache/QueryReference.js.map +1 -1
  207. package/react/cache/SuspenseCache.d.ts +10 -0
  208. package/react/cache/SuspenseCache.js +1 -1
  209. package/react/cache/SuspenseCache.js.map +1 -1
  210. package/react/cache/getSuspenseCache.js.map +1 -1
  211. package/react/context/ApolloContext.d.ts +5 -0
  212. package/react/context/ApolloContext.js +10 -3
  213. package/react/context/ApolloContext.js.map +1 -1
  214. package/react/context/context.cjs +1 -3
  215. package/react/context/context.cjs.map +1 -1
  216. package/react/context/context.cjs.native.js +1 -3
  217. package/react/hoc/graphql.js.map +1 -1
  218. package/react/hoc/hoc-utils.js +3 -1
  219. package/react/hoc/hoc-utils.js.map +1 -1
  220. package/react/hoc/hoc.cjs +9 -17
  221. package/react/hoc/hoc.cjs.map +1 -1
  222. package/react/hoc/hoc.cjs.native.js +9 -17
  223. package/react/hoc/mutation-hoc.js +9 -4
  224. package/react/hoc/mutation-hoc.js.map +1 -1
  225. package/react/hoc/query-hoc.js +10 -4
  226. package/react/hoc/query-hoc.js.map +1 -1
  227. package/react/hoc/subscription-hoc.js +10 -4
  228. package/react/hoc/subscription-hoc.js.map +1 -1
  229. package/react/hoc/withApollo.js +3 -4
  230. package/react/hoc/withApollo.js.map +1 -1
  231. package/react/hooks/hooks.cjs +72 -57
  232. package/react/hooks/hooks.cjs.map +1 -1
  233. package/react/hooks/hooks.cjs.native.js +72 -57
  234. package/react/hooks/internal/__use.js +5 -0
  235. package/react/hooks/internal/__use.js.map +1 -1
  236. package/react/hooks/internal/index.d.ts +1 -0
  237. package/react/hooks/internal/index.js +2 -0
  238. package/react/hooks/internal/index.js.map +1 -1
  239. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  240. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  241. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  242. package/react/hooks/internal/useLazyRef.d.ts +3 -0
  243. package/react/hooks/internal/useLazyRef.js +10 -0
  244. package/react/hooks/internal/useLazyRef.js.map +1 -0
  245. package/react/hooks/useBackgroundQuery.js +6 -0
  246. package/react/hooks/useBackgroundQuery.js.map +1 -1
  247. package/react/hooks/useFragment.js +21 -17
  248. package/react/hooks/useFragment.js.map +1 -1
  249. package/react/hooks/useLazyQuery.js +13 -4
  250. package/react/hooks/useLazyQuery.js.map +1 -1
  251. package/react/hooks/useMutation.js +8 -3
  252. package/react/hooks/useMutation.js.map +1 -1
  253. package/react/hooks/useQuery.d.ts +11 -0
  254. package/react/hooks/useQuery.js +137 -5
  255. package/react/hooks/useQuery.js.map +1 -1
  256. package/react/hooks/useReactiveVar.js +5 -0
  257. package/react/hooks/useReactiveVar.js.map +1 -1
  258. package/react/hooks/useReadQuery.d.ts +19 -0
  259. package/react/hooks/useReadQuery.js.map +1 -1
  260. package/react/hooks/useSubscription.js +5 -0
  261. package/react/hooks/useSubscription.js.map +1 -1
  262. package/react/hooks/useSuspenseQuery.js +11 -5
  263. package/react/hooks/useSuspenseQuery.js.map +1 -1
  264. package/react/hooks/useSyncExternalStore.js +53 -1
  265. package/react/hooks/useSyncExternalStore.js.map +1 -1
  266. package/react/parser/index.js +4 -5
  267. package/react/parser/index.js.map +1 -1
  268. package/react/parser/parser.cjs +2 -4
  269. package/react/parser/parser.cjs.map +1 -1
  270. package/react/parser/parser.cjs.native.js +2 -4
  271. package/react/ssr/RenderPromises.js +21 -1
  272. package/react/ssr/RenderPromises.js.map +1 -1
  273. package/react/ssr/getDataFromTree.js +18 -3
  274. package/react/ssr/getDataFromTree.js.map +1 -1
  275. package/react/ssr/ssr.cjs +6 -4
  276. package/react/ssr/ssr.cjs.map +1 -1
  277. package/react/ssr/ssr.cjs.native.js +6 -4
  278. package/react/types/types.d.ts +66 -0
  279. package/testing/core/core.cjs +18 -13
  280. package/testing/core/core.cjs.map +1 -1
  281. package/testing/core/core.cjs.native.js +18 -13
  282. package/testing/core/itAsync.d.ts +1 -1
  283. package/testing/core/itAsync.js.map +1 -1
  284. package/testing/core/mocking/mockFetch.d.ts +2 -2
  285. package/testing/core/mocking/mockFetch.js +8 -4
  286. package/testing/core/mocking/mockFetch.js.map +1 -1
  287. package/testing/core/mocking/mockLink.js +25 -9
  288. package/testing/core/mocking/mockLink.js.map +1 -1
  289. package/testing/core/mocking/mockQueryManager.js +2 -0
  290. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  291. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  292. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  293. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  294. package/testing/core/mocking/mockWatchQuery.js +1 -1
  295. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  296. package/testing/core/observableToPromise.d.ts +17 -3
  297. package/testing/core/observableToPromise.js +5 -0
  298. package/testing/core/observableToPromise.js.map +1 -1
  299. package/testing/core/subscribeAndCount.js +3 -0
  300. package/testing/core/subscribeAndCount.js.map +1 -1
  301. package/testing/core/wait.js +2 -2
  302. package/testing/core/wait.js.map +1 -1
  303. package/testing/core/withConsoleSpy.d.ts +3 -0
  304. package/testing/core/withConsoleSpy.js +7 -1
  305. package/testing/core/withConsoleSpy.js.map +1 -1
  306. package/testing/core/wrap.js +2 -0
  307. package/testing/core/wrap.js.map +1 -1
  308. package/testing/internal/ObservableStream.js +14 -14
  309. package/testing/internal/ObservableStream.js.map +1 -1
  310. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  311. package/testing/internal/disposables/spyOnConsole.js +2 -0
  312. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  313. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  314. package/testing/internal/disposables/withCleanup.js +3 -0
  315. package/testing/internal/disposables/withCleanup.js.map +1 -1
  316. package/testing/internal/profile/Render.d.ts +28 -0
  317. package/testing/internal/profile/Render.js +12 -1
  318. package/testing/internal/profile/Render.js.map +1 -1
  319. package/testing/internal/profile/profile.d.ts +44 -7
  320. package/testing/internal/profile/profile.js +63 -51
  321. package/testing/internal/profile/profile.js.map +1 -1
  322. package/testing/internal/profile/traces.d.ts +4 -0
  323. package/testing/internal/profile/traces.js +9 -5
  324. package/testing/internal/profile/traces.js.map +1 -1
  325. package/testing/matchers/ProfiledComponent.js +27 -22
  326. package/testing/matchers/ProfiledComponent.js.map +1 -1
  327. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  328. package/testing/matchers/toMatchDocument.js.map +1 -1
  329. package/testing/react/MockedProvider.d.ts +4 -0
  330. package/testing/react/MockedProvider.js +6 -2
  331. package/testing/react/MockedProvider.js.map +1 -1
  332. package/testing/testing.cjs +4 -2
  333. package/testing/testing.cjs.map +1 -1
  334. package/testing/testing.cjs.native.js +4 -2
  335. package/utilities/common/arrays.js +1 -0
  336. package/utilities/common/arrays.js.map +1 -1
  337. package/utilities/common/canUse.js +16 -1
  338. package/utilities/common/canUse.js.map +1 -1
  339. package/utilities/common/cloneDeep.d.ts +3 -0
  340. package/utilities/common/cloneDeep.js +5 -0
  341. package/utilities/common/cloneDeep.js.map +1 -1
  342. package/utilities/common/compact.d.ts +4 -0
  343. package/utilities/common/compact.js +4 -0
  344. package/utilities/common/compact.js.map +1 -1
  345. package/utilities/common/errorHandling.js +1 -3
  346. package/utilities/common/errorHandling.js.map +1 -1
  347. package/utilities/common/incrementalResult.js +3 -0
  348. package/utilities/common/incrementalResult.js.map +1 -1
  349. package/utilities/common/makeUniqueId.js +2 -0
  350. package/utilities/common/makeUniqueId.js.map +1 -1
  351. package/utilities/common/maybeDeepFreeze.js +3 -0
  352. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  353. package/utilities/common/mergeDeep.js +12 -1
  354. package/utilities/common/mergeDeep.js.map +1 -1
  355. package/utilities/common/mergeOptions.d.ts +1 -1
  356. package/utilities/common/mergeOptions.js.map +1 -1
  357. package/utilities/common/omitDeep.js.map +1 -1
  358. package/utilities/globals/global.js +7 -1
  359. package/utilities/globals/global.js.map +1 -1
  360. package/utilities/globals/globals.cjs +4 -5
  361. package/utilities/globals/globals.cjs.map +1 -1
  362. package/utilities/globals/globals.cjs.native.js +4 -5
  363. package/utilities/globals/index.d.ts +4 -0
  364. package/utilities/globals/index.js +7 -0
  365. package/utilities/globals/index.js.map +1 -1
  366. package/utilities/globals/invariantWrappers.d.ts +40 -0
  367. package/utilities/globals/invariantWrappers.js +11 -3
  368. package/utilities/globals/invariantWrappers.js.map +1 -1
  369. package/utilities/globals/maybe.js.map +1 -1
  370. package/utilities/graphql/DocumentTransform.js +19 -6
  371. package/utilities/graphql/DocumentTransform.js.map +1 -1
  372. package/utilities/graphql/directives.js +3 -0
  373. package/utilities/graphql/directives.js.map +1 -1
  374. package/utilities/graphql/fragments.d.ts +25 -0
  375. package/utilities/graphql/fragments.js +36 -0
  376. package/utilities/graphql/fragments.js.map +1 -1
  377. package/utilities/graphql/getFromAST.d.ts +5 -0
  378. package/utilities/graphql/getFromAST.js +9 -0
  379. package/utilities/graphql/getFromAST.js.map +1 -1
  380. package/utilities/graphql/print.js.map +1 -1
  381. package/utilities/graphql/storeUtils.d.ts +14 -0
  382. package/utilities/graphql/storeUtils.js +7 -2
  383. package/utilities/graphql/storeUtils.js.map +1 -1
  384. package/utilities/graphql/transform.js +106 -7
  385. package/utilities/graphql/transform.js.map +1 -1
  386. package/utilities/observables/Concast.d.ts +1 -1
  387. package/utilities/observables/Concast.js +84 -1
  388. package/utilities/observables/Concast.js.map +1 -1
  389. package/utilities/observables/Observable.js +6 -0
  390. package/utilities/observables/Observable.js.map +1 -1
  391. package/utilities/observables/asyncMap.js +12 -3
  392. package/utilities/observables/asyncMap.js.map +1 -1
  393. package/utilities/observables/iteration.js +3 -0
  394. package/utilities/observables/iteration.js.map +1 -1
  395. package/utilities/observables/subclassing.js +14 -0
  396. package/utilities/observables/subclassing.js.map +1 -1
  397. package/utilities/policies/pagination.js +47 -3
  398. package/utilities/policies/pagination.js.map +1 -1
  399. package/utilities/promises/decoration.js +1 -0
  400. package/utilities/promises/decoration.js.map +1 -1
  401. package/utilities/types/DeepOmit.js.map +1 -1
  402. package/utilities/types/DeepPartial.d.ts +1 -1
  403. package/utilities/types/DeepPartial.js +4 -0
  404. package/utilities/types/DeepPartial.js.map +1 -1
  405. package/utilities/types/IsStrictlyAny.js.map +1 -1
  406. package/utilities/types/TODO.d.ts +3 -0
  407. package/utilities/types/TODO.js +2 -0
  408. package/utilities/types/TODO.js.map +1 -0
  409. package/utilities/utilities.cjs +31 -27
  410. package/utilities/utilities.cjs.map +1 -1
  411. package/utilities/utilities.cjs.native.js +31 -27
  412. package/version.js +1 -1
  413. package/cache/core/cache.d.ts.map +0 -1
  414. package/cache/core/types/Cache.d.ts.map +0 -1
  415. package/cache/core/types/DataProxy.d.ts.map +0 -1
  416. package/cache/core/types/common.d.ts.map +0 -1
  417. package/cache/index.d.ts.map +0 -1
  418. package/cache/inmemory/entityStore.d.ts.map +0 -1
  419. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  420. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  421. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  422. package/cache/inmemory/helpers.d.ts.map +0 -1
  423. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  424. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  425. package/cache/inmemory/object-canon.d.ts.map +0 -1
  426. package/cache/inmemory/policies.d.ts.map +0 -1
  427. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  428. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  429. package/cache/inmemory/types.d.ts.map +0 -1
  430. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  431. package/config/jest/setup.d.ts.map +0 -1
  432. package/core/ApolloClient.d.ts.map +0 -1
  433. package/core/LocalState.d.ts.map +0 -1
  434. package/core/ObservableQuery.d.ts.map +0 -1
  435. package/core/QueryInfo.d.ts.map +0 -1
  436. package/core/QueryManager.d.ts.map +0 -1
  437. package/core/equalByQuery.d.ts.map +0 -1
  438. package/core/index.d.ts.map +0 -1
  439. package/core/networkStatus.d.ts.map +0 -1
  440. package/core/types.d.ts.map +0 -1
  441. package/core/watchQueryOptions.d.ts.map +0 -1
  442. package/dev/index.d.ts.map +0 -1
  443. package/dev/loadDevMessages.d.ts.map +0 -1
  444. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  445. package/dev/loadErrorMessages.d.ts.map +0 -1
  446. package/errors/index.d.ts.map +0 -1
  447. package/index.d.ts.map +0 -1
  448. package/invariantErrorCodes.d.ts.map +0 -1
  449. package/link/batch/batchLink.d.ts.map +0 -1
  450. package/link/batch/batching.d.ts.map +0 -1
  451. package/link/batch/index.d.ts.map +0 -1
  452. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  453. package/link/batch-http/index.d.ts.map +0 -1
  454. package/link/context/index.d.ts.map +0 -1
  455. package/link/core/ApolloLink.d.ts.map +0 -1
  456. package/link/core/concat.d.ts.map +0 -1
  457. package/link/core/empty.d.ts.map +0 -1
  458. package/link/core/execute.d.ts.map +0 -1
  459. package/link/core/from.d.ts.map +0 -1
  460. package/link/core/index.d.ts.map +0 -1
  461. package/link/core/split.d.ts.map +0 -1
  462. package/link/core/types.d.ts.map +0 -1
  463. package/link/error/index.d.ts.map +0 -1
  464. package/link/http/HttpLink.d.ts.map +0 -1
  465. package/link/http/checkFetcher.d.ts.map +0 -1
  466. package/link/http/createHttpLink.d.ts.map +0 -1
  467. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  468. package/link/http/index.d.ts.map +0 -1
  469. package/link/http/iterators/async.d.ts.map +0 -1
  470. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  471. package/link/http/iterators/promise.d.ts.map +0 -1
  472. package/link/http/iterators/reader.d.ts.map +0 -1
  473. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  474. package/link/http/responseIterator.d.ts.map +0 -1
  475. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  476. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  477. package/link/http/selectURI.d.ts.map +0 -1
  478. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  479. package/link/persisted-queries/index.d.ts.map +0 -1
  480. package/link/remove-typename/index.d.ts.map +0 -1
  481. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  482. package/link/retry/delayFunction.d.ts.map +0 -1
  483. package/link/retry/index.d.ts.map +0 -1
  484. package/link/retry/retryFunction.d.ts.map +0 -1
  485. package/link/retry/retryLink.d.ts.map +0 -1
  486. package/link/schema/index.d.ts.map +0 -1
  487. package/link/subscriptions/index.d.ts.map +0 -1
  488. package/link/utils/createOperation.d.ts.map +0 -1
  489. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  490. package/link/utils/fromError.d.ts.map +0 -1
  491. package/link/utils/fromPromise.d.ts.map +0 -1
  492. package/link/utils/index.d.ts.map +0 -1
  493. package/link/utils/throwServerError.d.ts.map +0 -1
  494. package/link/utils/toPromise.d.ts.map +0 -1
  495. package/link/utils/transformOperation.d.ts.map +0 -1
  496. package/link/utils/validateOperation.d.ts.map +0 -1
  497. package/link/ws/index.d.ts.map +0 -1
  498. package/react/cache/QueryReference.d.ts.map +0 -1
  499. package/react/cache/SuspenseCache.d.ts.map +0 -1
  500. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  501. package/react/cache/index.d.ts.map +0 -1
  502. package/react/cache/types.d.ts.map +0 -1
  503. package/react/components/Mutation.d.ts.map +0 -1
  504. package/react/components/Query.d.ts.map +0 -1
  505. package/react/components/Subscription.d.ts.map +0 -1
  506. package/react/components/index.d.ts.map +0 -1
  507. package/react/components/types.d.ts.map +0 -1
  508. package/react/context/ApolloConsumer.d.ts.map +0 -1
  509. package/react/context/ApolloContext.d.ts.map +0 -1
  510. package/react/context/ApolloProvider.d.ts.map +0 -1
  511. package/react/context/index.d.ts.map +0 -1
  512. package/react/hoc/graphql.d.ts.map +0 -1
  513. package/react/hoc/hoc-utils.d.ts.map +0 -1
  514. package/react/hoc/index.d.ts.map +0 -1
  515. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  516. package/react/hoc/query-hoc.d.ts.map +0 -1
  517. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  518. package/react/hoc/types.d.ts.map +0 -1
  519. package/react/hoc/withApollo.d.ts.map +0 -1
  520. package/react/hooks/constants.d.ts.map +0 -1
  521. package/react/hooks/index.d.ts.map +0 -1
  522. package/react/hooks/internal/__use.d.ts.map +0 -1
  523. package/react/hooks/internal/index.d.ts.map +0 -1
  524. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  525. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  526. package/react/hooks/useApolloClient.d.ts.map +0 -1
  527. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  528. package/react/hooks/useFragment.d.ts.map +0 -1
  529. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  530. package/react/hooks/useMutation.d.ts.map +0 -1
  531. package/react/hooks/useQuery.d.ts.map +0 -1
  532. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  533. package/react/hooks/useReadQuery.d.ts.map +0 -1
  534. package/react/hooks/useSubscription.d.ts.map +0 -1
  535. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  536. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  537. package/react/index.d.ts.map +0 -1
  538. package/react/parser/index.d.ts.map +0 -1
  539. package/react/ssr/RenderPromises.d.ts.map +0 -1
  540. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  541. package/react/ssr/index.d.ts.map +0 -1
  542. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  543. package/react/types/types.d.ts.map +0 -1
  544. package/testing/core/index.d.ts.map +0 -1
  545. package/testing/core/itAsync.d.ts.map +0 -1
  546. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  547. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  548. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  549. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  550. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  551. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  552. package/testing/core/observableToPromise.d.ts.map +0 -1
  553. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  554. package/testing/core/wait.d.ts.map +0 -1
  555. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  556. package/testing/core/wrap.d.ts.map +0 -1
  557. package/testing/index.d.ts.map +0 -1
  558. package/testing/internal/ObservableStream.d.ts.map +0 -1
  559. package/testing/internal/disposables/index.d.ts.map +0 -1
  560. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  561. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  562. package/testing/internal/index.d.ts.map +0 -1
  563. package/testing/internal/profile/Render.d.ts.map +0 -1
  564. package/testing/internal/profile/index.d.ts.map +0 -1
  565. package/testing/internal/profile/profile.d.ts.map +0 -1
  566. package/testing/internal/profile/traces.d.ts.map +0 -1
  567. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  568. package/testing/matchers/index.d.ts.map +0 -1
  569. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  570. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  571. package/testing/react/MockedProvider.d.ts.map +0 -1
  572. package/utilities/common/arrays.d.ts.map +0 -1
  573. package/utilities/common/canUse.d.ts.map +0 -1
  574. package/utilities/common/cloneDeep.d.ts.map +0 -1
  575. package/utilities/common/compact.d.ts.map +0 -1
  576. package/utilities/common/errorHandling.d.ts.map +0 -1
  577. package/utilities/common/filterInPlace.d.ts +0 -2
  578. package/utilities/common/filterInPlace.d.ts.map +0 -1
  579. package/utilities/common/filterInPlace.js +0 -11
  580. package/utilities/common/filterInPlace.js.map +0 -1
  581. package/utilities/common/incrementalResult.d.ts.map +0 -1
  582. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  583. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  584. package/utilities/common/mergeDeep.d.ts.map +0 -1
  585. package/utilities/common/mergeOptions.d.ts.map +0 -1
  586. package/utilities/common/objects.d.ts.map +0 -1
  587. package/utilities/common/omitDeep.d.ts.map +0 -1
  588. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  589. package/utilities/common/stripTypename.d.ts.map +0 -1
  590. package/utilities/globals/global.d.ts.map +0 -1
  591. package/utilities/globals/index.d.ts.map +0 -1
  592. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  593. package/utilities/globals/maybe.d.ts.map +0 -1
  594. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  595. package/utilities/graphql/directives.d.ts.map +0 -1
  596. package/utilities/graphql/fragments.d.ts.map +0 -1
  597. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  598. package/utilities/graphql/operations.d.ts.map +0 -1
  599. package/utilities/graphql/print.d.ts.map +0 -1
  600. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  601. package/utilities/graphql/transform.d.ts.map +0 -1
  602. package/utilities/index.d.ts.map +0 -1
  603. package/utilities/observables/Concast.d.ts.map +0 -1
  604. package/utilities/observables/Observable.d.ts.map +0 -1
  605. package/utilities/observables/asyncMap.d.ts.map +0 -1
  606. package/utilities/observables/iteration.d.ts.map +0 -1
  607. package/utilities/observables/subclassing.d.ts.map +0 -1
  608. package/utilities/policies/pagination.d.ts.map +0 -1
  609. package/utilities/promises/decoration.d.ts.map +0 -1
  610. package/utilities/types/DeepOmit.d.ts.map +0 -1
  611. package/utilities/types/DeepPartial.d.ts.map +0 -1
  612. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  613. package/utilities/types/Primitive.d.ts.map +0 -1
  614. package/version.d.ts.map +0 -1
@@ -3,29 +3,40 @@ import { invariant, newInvariantError } from "../../utilities/globals/index.js";
3
3
  import { storeKeyNameFromField, argumentsObjectFromField, isReference, getStoreKeyName, isNonNullObject, stringifyForDisplay, } from "../../utilities/index.js";
4
4
  import { hasOwn, fieldNameFromStoreName, storeValueIsStoreObject, selectionSetMatchesResult, TypeOrFieldNameRegExp, defaultDataIdFromObject, isArray, } from "./helpers.js";
5
5
  import { cacheSlot } from "./reactiveVars.js";
6
+ // Upgrade to a faster version of the default stable JSON.stringify function
7
+ // used by getStoreKeyName. This function is used when computing storeFieldName
8
+ // strings (when no keyArgs has been configured for a field).
6
9
  import { canonicalStringify } from "./object-canon.js";
7
10
  import { keyArgsFnFromSpecifier, keyFieldsFnFromSpecifier, } from "./key-extractor.js";
8
11
  getStoreKeyName.setStringify(canonicalStringify);
9
12
  function argsFromFieldSpecifier(spec) {
10
- return spec.args !== void 0
11
- ? spec.args
12
- : spec.field
13
- ? argumentsObjectFromField(spec.field, spec.variables)
14
- : null;
13
+ return (spec.args !== void 0 ? spec.args
14
+ : spec.field ? argumentsObjectFromField(spec.field, spec.variables)
15
+ : null);
15
16
  }
16
17
  var nullKeyFieldsFn = function () { return void 0; };
17
18
  var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
19
+ // These merge functions can be selected by specifying merge:true or
20
+ // merge:false in a field policy.
18
21
  var mergeTrueFn = function (existing, incoming, _a) {
19
22
  var mergeObjects = _a.mergeObjects;
20
23
  return mergeObjects(existing, incoming);
21
24
  };
22
25
  var mergeFalseFn = function (_, incoming) { return incoming; };
23
- var Policies = (function () {
26
+ var Policies = /** @class */ (function () {
24
27
  function Policies(config) {
25
28
  this.config = config;
26
29
  this.typePolicies = Object.create(null);
27
30
  this.toBeAdded = Object.create(null);
31
+ // Map from subtype names to sets of supertype names. Note that this
32
+ // representation inverts the structure of possibleTypes (whose keys are
33
+ // supertypes and whose values are arrays of subtypes) because it tends
34
+ // to be much more efficient to search upwards than downwards.
28
35
  this.supertypeMap = new Map();
36
+ // Any fuzzy subtypes specified by possibleTypes will be converted to
37
+ // RegExp objects and recorded here. Every key of this map can also be
38
+ // found in supertypeMap. In many cases this Map will be empty, which
39
+ // means no fuzzy subtype checking will happen in fragmentMatches.
29
40
  this.fuzzySubtypes = new Map();
30
41
  this.rootIdsByTypename = Object.create(null);
31
42
  this.rootTypenamesById = Object.create(null);
@@ -48,9 +59,15 @@ var Policies = (function () {
48
59
  var typename = (partialContext &&
49
60
  (partialContext.typename || ((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename))) ||
50
61
  object.__typename;
62
+ // It should be possible to write root Query fields with writeFragment,
63
+ // using { __typename: "Query", ... } as the data, but it does not make
64
+ // sense to allow the same identification behavior for the Mutation and
65
+ // Subscription types, since application code should never be writing
66
+ // directly to (or reading directly from) those root objects.
51
67
  if (typename === this.rootTypenamesById.ROOT_QUERY) {
52
68
  return ["ROOT_QUERY"];
53
69
  }
70
+ // Default context.storeObject to object if not otherwise provided.
54
71
  var storeObject = (partialContext && partialContext.storeObject) || object;
55
72
  var context = __assign(__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: (partialContext && partialContext.readField) ||
56
73
  function () {
@@ -80,6 +97,20 @@ var Policies = (function () {
80
97
  var _this = this;
81
98
  Object.keys(typePolicies).forEach(function (typename) {
82
99
  var _a = typePolicies[typename], queryType = _a.queryType, mutationType = _a.mutationType, subscriptionType = _a.subscriptionType, incoming = __rest(_a, ["queryType", "mutationType", "subscriptionType"]);
100
+ // Though {query,mutation,subscription}Type configurations are rare,
101
+ // it's important to call setRootTypename as early as possible,
102
+ // since these configurations should apply consistently for the
103
+ // entire lifetime of the cache. Also, since only one __typename can
104
+ // qualify as one of these root types, these three properties cannot
105
+ // be inherited, unlike the rest of the incoming properties. That
106
+ // restriction is convenient, because the purpose of this.toBeAdded
107
+ // is to delay the processing of type/field policies until the first
108
+ // time they're used, allowing policies to be added in any order as
109
+ // long as all relevant policies (including policies for supertypes)
110
+ // have been added by the time a given policy is used for the first
111
+ // time. In other words, since inheritance doesn't matter for these
112
+ // properties, there's also no need to delay their processing using
113
+ // the this.toBeAdded queue.
83
114
  if (queryType)
84
115
  _this.setRootTypename("Query", typename);
85
116
  if (mutationType)
@@ -100,28 +131,28 @@ var Policies = (function () {
100
131
  var keyFields = incoming.keyFields, fields = incoming.fields;
101
132
  function setMerge(existing, merge) {
102
133
  existing.merge =
103
- typeof merge === "function"
104
- ? merge
105
- :
106
- merge === true
107
- ? mergeTrueFn
108
- :
109
- merge === false
110
- ? mergeFalseFn
111
- : existing.merge;
134
+ typeof merge === "function" ? merge
135
+ // Pass merge:true as a shorthand for a merge implementation
136
+ // that returns options.mergeObjects(existing, incoming).
137
+ : merge === true ? mergeTrueFn
138
+ // Pass merge:false to make incoming always replace existing
139
+ // without any warnings about data clobbering.
140
+ : merge === false ? mergeFalseFn
141
+ : existing.merge;
112
142
  }
143
+ // Type policies can define merge functions, as an alternative to
144
+ // using field policies to merge child objects.
113
145
  setMerge(existing, incoming.merge);
114
146
  existing.keyFn =
115
- keyFields === false
116
- ? nullKeyFieldsFn
117
- :
118
- isArray(keyFields)
119
- ? keyFieldsFnFromSpecifier(keyFields)
120
- :
121
- typeof keyFields === "function"
122
- ? keyFields
123
- :
124
- existing.keyFn;
147
+ // Pass false to disable normalization for this typename.
148
+ keyFields === false ? nullKeyFieldsFn
149
+ // Pass an array of strings to use those fields to compute a
150
+ // composite ID for objects of this typename.
151
+ : isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields)
152
+ // Pass a function to take full control over identification.
153
+ : typeof keyFields === "function" ? keyFields
154
+ // Leave existing.keyFn unchanged if above cases fail.
155
+ : existing.keyFn;
125
156
  if (fields) {
126
157
  Object.keys(fields).forEach(function (fieldName) {
127
158
  var existing = _this.getFieldPolicy(typename, fieldName, true);
@@ -132,22 +163,27 @@ var Policies = (function () {
132
163
  else {
133
164
  var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
134
165
  existing.keyFn =
135
- keyArgs === false
136
- ? simpleKeyArgsFn
137
- :
138
- isArray(keyArgs)
139
- ? keyArgsFnFromSpecifier(keyArgs)
140
- :
141
- typeof keyArgs === "function"
142
- ? keyArgs
143
- :
144
- existing.keyFn;
166
+ // Pass false to disable argument-based differentiation of
167
+ // field identities.
168
+ keyArgs === false ? simpleKeyArgsFn
169
+ // Pass an array of strings to use named arguments to
170
+ // compute a composite identity for the field.
171
+ : isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs)
172
+ // Pass a function to take full control over field identity.
173
+ : typeof keyArgs === "function" ? keyArgs
174
+ // Leave existing.keyFn unchanged if above cases fail.
175
+ : existing.keyFn;
145
176
  if (typeof read === "function") {
146
177
  existing.read = read;
147
178
  }
148
179
  setMerge(existing, merge);
149
180
  }
150
181
  if (existing.read && existing.merge) {
182
+ // If we have both a read and a merge function, assume
183
+ // keyArgs:false, because read and merge together can take
184
+ // responsibility for interpreting arguments in and out. This
185
+ // default assumption can always be overridden by specifying
186
+ // keyArgs explicitly in the FieldPolicy.
151
187
  existing.keyFn = existing.keyFn || simpleKeyArgsFn;
152
188
  }
153
189
  });
@@ -159,9 +195,13 @@ var Policies = (function () {
159
195
  var old = this.rootTypenamesById[rootId];
160
196
  if (typename !== old) {
161
197
  invariant(!old || old === which, 5, which);
198
+ // First, delete any old __typename associated with this rootId from
199
+ // rootIdsByTypename.
162
200
  if (old)
163
201
  delete this.rootIdsByTypename[old];
202
+ // Now make this the only __typename that maps to this rootId.
164
203
  this.rootIdsByTypename[typename] = rootId;
204
+ // Finally, update the __typename associated with this rootId.
165
205
  this.rootTypenamesById[rootId] = typename;
166
206
  }
167
207
  };
@@ -169,11 +209,15 @@ var Policies = (function () {
169
209
  var _this = this;
170
210
  this.usingPossibleTypes = true;
171
211
  Object.keys(possibleTypes).forEach(function (supertype) {
212
+ // Make sure all types have an entry in this.supertypeMap, even if
213
+ // their supertype set is empty, so we can return false immediately
214
+ // from policies.fragmentMatches for unknown supertypes.
172
215
  _this.getSupertypeSet(supertype, true);
173
216
  possibleTypes[supertype].forEach(function (subtype) {
174
217
  _this.getSupertypeSet(subtype, true).add(supertype);
175
218
  var match = subtype.match(TypeOrFieldNameRegExp);
176
219
  if (!match || match[0] !== subtype) {
220
+ // TODO Don't interpret just any invalid typename as a RegExp.
177
221
  _this.fuzzySubtypes.set(subtype, new RegExp(subtype));
178
222
  }
179
223
  });
@@ -184,11 +228,43 @@ var Policies = (function () {
184
228
  if (!hasOwn.call(this.typePolicies, typename)) {
185
229
  var policy_1 = (this.typePolicies[typename] = Object.create(null));
186
230
  policy_1.fields = Object.create(null);
231
+ // When the TypePolicy for typename is first accessed, instead of
232
+ // starting with an empty policy object, inherit any properties or
233
+ // fields from the type policies of the supertypes of typename.
234
+ //
235
+ // Any properties or fields defined explicitly within the TypePolicy
236
+ // for typename will take precedence, and if there are multiple
237
+ // supertypes, the properties of policies whose types were added
238
+ // later via addPossibleTypes will take precedence over those of
239
+ // earlier supertypes. TODO Perhaps we should warn about these
240
+ // conflicts in development, and recommend defining the property
241
+ // explicitly in the subtype policy?
242
+ //
243
+ // Field policy inheritance is atomic/shallow: you can't inherit a
244
+ // field policy and then override just its read function, since read
245
+ // and merge functions often need to cooperate, so changing only one
246
+ // of them would be a recipe for inconsistency.
247
+ //
248
+ // Once the TypePolicy for typename has been accessed, its properties can
249
+ // still be updated directly using addTypePolicies, but future changes to
250
+ // inherited supertype policies will not be reflected in this subtype
251
+ // policy, because this code runs at most once per typename.
187
252
  var supertypes_1 = this.supertypeMap.get(typename);
188
253
  if (!supertypes_1 && this.fuzzySubtypes.size) {
254
+ // To make the inheritance logic work for unknown typename strings that
255
+ // may have fuzzy supertypes, we give this typename an empty supertype
256
+ // set and then populate it with any fuzzy supertypes that match.
189
257
  supertypes_1 = this.getSupertypeSet(typename, true);
258
+ // This only works for typenames that are directly matched by a fuzzy
259
+ // supertype. What if there is an intermediate chain of supertypes?
260
+ // While possible, that situation can only be solved effectively by
261
+ // specifying the intermediate relationships via possibleTypes, manually
262
+ // and in a non-fuzzy way.
190
263
  this.fuzzySubtypes.forEach(function (regExp, fuzzy) {
191
264
  if (regExp.test(typename)) {
265
+ // The fuzzy parameter is just the original string version of regExp
266
+ // (not a valid __typename string), but we can look up the
267
+ // associated supertype(s) in this.supertypeMap.
192
268
  var fuzzySupertypes = _this.supertypeMap.get(fuzzy);
193
269
  if (fuzzySupertypes) {
194
270
  fuzzySupertypes.forEach(function (supertype) {
@@ -208,6 +284,8 @@ var Policies = (function () {
208
284
  }
209
285
  var inbox = this.toBeAdded[typename];
210
286
  if (inbox && inbox.length) {
287
+ // Merge the pending policies into this.typePolicies, in the order they
288
+ // were originally passed to addTypePolicy.
211
289
  inbox.splice(0).forEach(function (policy) {
212
290
  _this.updateTypePolicy(typename, policy);
213
291
  });
@@ -232,9 +310,12 @@ var Policies = (function () {
232
310
  var _this = this;
233
311
  if (!fragment.typeCondition)
234
312
  return true;
313
+ // If the fragment has a type condition but the object we're matching
314
+ // against does not have a __typename, the fragment cannot match.
235
315
  if (!typename)
236
316
  return false;
237
317
  var supertype = fragment.typeCondition.name.value;
318
+ // Common case: fragment type condition and __typename are the same.
238
319
  if (typename === supertype)
239
320
  return true;
240
321
  if (this.usingPossibleTypes && this.supertypeMap.has(supertype)) {
@@ -248,8 +329,16 @@ var Policies = (function () {
248
329
  workQueue_1.push(supertypeSet);
249
330
  }
250
331
  };
332
+ // We need to check fuzzy subtypes only if we encountered fuzzy
333
+ // subtype strings in addPossibleTypes, and only while writing to
334
+ // the cache, since that's when selectionSetMatchesResult gives a
335
+ // strong signal of fragment matching. The StoreReader class calls
336
+ // policies.fragmentMatches without passing a result object, so
337
+ // needToCheckFuzzySubtypes is always false while reading.
251
338
  var needToCheckFuzzySubtypes = !!(result && this.fuzzySubtypes.size);
252
339
  var checkingFuzzySubtypes = false;
340
+ // It's important to keep evaluating workQueue.length each time through
341
+ // the loop, because the queue can grow while we're iterating over it.
253
342
  for (var i = 0; i < workQueue_1.length; ++i) {
254
343
  var supertypeSet = workQueue_1[i];
255
344
  if (supertypeSet.has(supertype)) {
@@ -257,16 +346,33 @@ var Policies = (function () {
257
346
  if (checkingFuzzySubtypes) {
258
347
  globalThis.__DEV__ !== false && invariant.warn(6, typename, supertype);
259
348
  }
349
+ // Record positive results for faster future lookup.
350
+ // Unfortunately, we cannot safely cache negative results,
351
+ // because new possibleTypes data could always be added to the
352
+ // Policies class.
260
353
  typenameSupertypeSet.add(supertype);
261
354
  }
262
355
  return true;
263
356
  }
264
357
  supertypeSet.forEach(maybeEnqueue_1);
265
358
  if (needToCheckFuzzySubtypes &&
359
+ // Start checking fuzzy subtypes only after exhausting all
360
+ // non-fuzzy subtypes (after the final iteration of the loop).
266
361
  i === workQueue_1.length - 1 &&
362
+ // We could wait to compare fragment.selectionSet to result
363
+ // after we verify the supertype, but this check is often less
364
+ // expensive than that search, and we will have to do the
365
+ // comparison anyway whenever we find a potential match.
267
366
  selectionSetMatchesResult(fragment.selectionSet, result, variables)) {
367
+ // We don't always need to check fuzzy subtypes (if no result
368
+ // was provided, or !this.fuzzySubtypes.size), but, when we do,
369
+ // we only want to check them once.
268
370
  needToCheckFuzzySubtypes = false;
269
371
  checkingFuzzySubtypes = true;
372
+ // If we find any fuzzy subtypes that match typename, extend the
373
+ // workQueue to search through the supertypes of those fuzzy
374
+ // subtypes. Otherwise the for-loop will terminate and we'll
375
+ // return false below.
270
376
  this.fuzzySubtypes.forEach(function (regExp, fuzzyString) {
271
377
  var match = typename.match(regExp);
272
378
  if (match && match[0] === typename) {
@@ -301,21 +407,28 @@ var Policies = (function () {
301
407
  keyFn = keyArgsFnFromSpecifier(specifierOrString);
302
408
  }
303
409
  else {
410
+ // If the custom keyFn returns a falsy value, fall back to
411
+ // fieldName instead.
304
412
  storeFieldName = specifierOrString || fieldName;
305
413
  break;
306
414
  }
307
415
  }
308
416
  }
309
417
  if (storeFieldName === void 0) {
310
- storeFieldName = fieldSpec.field
311
- ? storeKeyNameFromField(fieldSpec.field, fieldSpec.variables)
312
- : getStoreKeyName(fieldName, argsFromFieldSpecifier(fieldSpec));
418
+ storeFieldName =
419
+ fieldSpec.field ?
420
+ storeKeyNameFromField(fieldSpec.field, fieldSpec.variables)
421
+ : getStoreKeyName(fieldName, argsFromFieldSpecifier(fieldSpec));
313
422
  }
423
+ // Returning false from a keyArgs function is like configuring
424
+ // keyArgs: false, but more dynamic.
314
425
  if (storeFieldName === false) {
315
426
  return fieldName;
316
427
  }
317
- return fieldName === fieldNameFromStoreName(storeFieldName)
318
- ? storeFieldName
428
+ // Make sure custom field names start with the actual field.name.value
429
+ // of the field, so we can always figure out which properties of a
430
+ // StoreObject correspond to which original field names.
431
+ return fieldName === fieldNameFromStoreName(storeFieldName) ? storeFieldName
319
432
  : fieldName + ":" + storeFieldName;
320
433
  };
321
434
  Policies.prototype.readField = function (options, context) {
@@ -336,9 +449,10 @@ var Policies = (function () {
336
449
  var policy = this.getFieldPolicy(options.typename, fieldName, false);
337
450
  var read = policy && policy.read;
338
451
  if (read) {
339
- var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(isReference(objectOrReference)
340
- ? objectOrReference.__ref
452
+ var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(isReference(objectOrReference) ?
453
+ objectOrReference.__ref
341
454
  : objectOrReference, storeFieldName));
455
+ // Call read(existing, readOptions) with cacheSlot holding this.cache.
342
456
  return cacheSlot.withValue(this.cache, read, [
343
457
  existing,
344
458
  readOptions,
@@ -362,15 +476,35 @@ var Policies = (function () {
362
476
  Policies.prototype.runMergeFunction = function (existing, incoming, _a, context, storage) {
363
477
  var field = _a.field, typename = _a.typename, merge = _a.merge;
364
478
  if (merge === mergeTrueFn) {
479
+ // Instead of going to the trouble of creating a full
480
+ // FieldFunctionOptions object and calling mergeTrueFn, we can
481
+ // simply call mergeObjects, as mergeTrueFn would.
365
482
  return makeMergeObjectsFunction(context.store)(existing, incoming);
366
483
  }
367
484
  if (merge === mergeFalseFn) {
485
+ // Likewise for mergeFalseFn, whose implementation is even simpler.
368
486
  return incoming;
369
487
  }
488
+ // If cache.writeQuery or cache.writeFragment was called with
489
+ // options.overwrite set to true, we still call merge functions, but
490
+ // the existing data is always undefined, so the merge function will
491
+ // not attempt to combine the incoming data with the existing data.
370
492
  if (context.overwrite) {
371
493
  existing = void 0;
372
494
  }
373
- return merge(existing, incoming, makeFieldFunctionOptions(this, void 0, {
495
+ return merge(existing, incoming, makeFieldFunctionOptions(this,
496
+ // Unlike options.readField for read functions, we do not fall
497
+ // back to the current object if no foreignObjOrRef is provided,
498
+ // because it's not clear what the current object should be for
499
+ // merge functions: the (possibly undefined) existing object, or
500
+ // the incoming object? If you think your merge function needs
501
+ // to read sibling fields in order to produce a new value for
502
+ // the current field, you might want to rethink your strategy,
503
+ // because that's a recipe for making merge behavior sensitive
504
+ // to the order in which fields are written into the cache.
505
+ // However, readField(name, ref) is useful for merge functions
506
+ // that need to deduplicate child objects and references.
507
+ void 0, {
374
508
  typename: typename,
375
509
  fieldName: field.name.value,
376
510
  field: field,
@@ -408,11 +542,16 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
408
542
  if (typeof fieldNameOrOptions === "string") {
409
543
  options = {
410
544
  fieldName: fieldNameOrOptions,
545
+ // Default to objectOrReference only when no second argument was
546
+ // passed for the from parameter, not when undefined is explicitly
547
+ // passed as the second argument.
411
548
  from: argc > 1 ? from : objectOrReference,
412
549
  };
413
550
  }
414
551
  else {
415
552
  options = __assign({}, fieldNameOrOptions);
553
+ // Default to objectOrReference only when fieldNameOrOptions.from is
554
+ // actually omitted, rather than just undefined.
416
555
  if (!hasOwn.call(options, "from")) {
417
556
  options.from = objectOrReference;
418
557
  }
@@ -430,6 +569,10 @@ function makeMergeObjectsFunction(store) {
430
569
  if (isArray(existing) || isArray(incoming)) {
431
570
  throw newInvariantError(8);
432
571
  }
572
+ // These dynamic checks are necessary because the parameters of a
573
+ // custom merge function can easily have the any type, so the type
574
+ // system cannot always enforce the StoreObject | Reference parameter
575
+ // types of options.mergeObjects.
433
576
  if (isNonNullObject(existing) && isNonNullObject(incoming)) {
434
577
  var eType = store.getFieldValue(existing, "__typename");
435
578
  var iType = store.getFieldValue(incoming, "__typename");
@@ -438,10 +581,17 @@ function makeMergeObjectsFunction(store) {
438
581
  return incoming;
439
582
  }
440
583
  if (isReference(existing) && storeValueIsStoreObject(incoming)) {
584
+ // Update the normalized EntityStore for the entity identified by
585
+ // existing.__ref, preferring/overwriting any fields contributed by the
586
+ // newer incoming StoreObject.
441
587
  store.merge(existing.__ref, incoming);
442
588
  return existing;
443
589
  }
444
590
  if (storeValueIsStoreObject(existing) && isReference(incoming)) {
591
+ // Update the normalized EntityStore for the entity identified by
592
+ // incoming.__ref, taking fields from the older existing object only if
593
+ // those fields are not already present in the newer StoreObject
594
+ // identified by incoming.__ref.
445
595
  store.merge(existing, incoming.__ref);
446
596
  return incoming;
447
597
  }