@apollo/client 3.4.17 → 3.5.6

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 (421) hide show
  1. package/README.md +1 -1
  2. package/{apollo-client.cjs.js → apollo-client.cjs} +1219 -1280
  3. package/apollo-client.cjs.map +1 -0
  4. package/apollo-client.min.cjs +1 -0
  5. package/cache/{cache.cjs.js → cache.cjs} +757 -601
  6. package/cache/cache.cjs.map +1 -0
  7. package/cache/core/cache.d.ts +6 -4
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js +28 -1
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/core/types/Cache.d.ts +12 -10
  12. package/cache/core/types/Cache.d.ts.map +1 -1
  13. package/cache/core/types/Cache.js.map +1 -1
  14. package/cache/core/types/DataProxy.d.ts +4 -0
  15. package/cache/core/types/DataProxy.d.ts.map +1 -1
  16. package/cache/core/types/DataProxy.js.map +1 -1
  17. package/cache/core/types/common.d.ts +8 -5
  18. package/cache/core/types/common.d.ts.map +1 -1
  19. package/cache/core/types/common.js +6 -11
  20. package/cache/core/types/common.js.map +1 -1
  21. package/cache/inmemory/helpers.js +1 -1
  22. package/cache/inmemory/helpers.js.map +1 -1
  23. package/cache/inmemory/inMemoryCache.d.ts +4 -4
  24. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  25. package/cache/inmemory/inMemoryCache.js +12 -3
  26. package/cache/inmemory/inMemoryCache.js.map +1 -1
  27. package/cache/inmemory/key-extractor.d.ts +9 -0
  28. package/cache/inmemory/key-extractor.d.ts.map +1 -0
  29. package/cache/inmemory/key-extractor.js +118 -0
  30. package/cache/inmemory/key-extractor.js.map +1 -0
  31. package/cache/inmemory/policies.d.ts +7 -3
  32. package/cache/inmemory/policies.d.ts.map +1 -1
  33. package/cache/inmemory/policies.js +47 -118
  34. package/cache/inmemory/policies.js.map +1 -1
  35. package/cache/inmemory/readFromStore.d.ts +2 -2
  36. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  37. package/cache/inmemory/readFromStore.js +54 -42
  38. package/cache/inmemory/readFromStore.js.map +1 -1
  39. package/cache/inmemory/writeToStore.d.ts +8 -3
  40. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  41. package/cache/inmemory/writeToStore.js +166 -95
  42. package/cache/inmemory/writeToStore.js.map +1 -1
  43. package/cache/package.json +2 -1
  44. package/core/ApolloClient.d.ts +0 -1
  45. package/core/ApolloClient.d.ts.map +1 -1
  46. package/core/ApolloClient.js +3 -3
  47. package/core/ApolloClient.js.map +1 -1
  48. package/core/LocalState.js +1 -1
  49. package/core/LocalState.js.map +1 -1
  50. package/core/ObservableQuery.d.ts +2 -2
  51. package/core/ObservableQuery.d.ts.map +1 -1
  52. package/core/ObservableQuery.js +19 -14
  53. package/core/ObservableQuery.js.map +1 -1
  54. package/core/QueryInfo.d.ts +2 -2
  55. package/core/QueryInfo.d.ts.map +1 -1
  56. package/core/QueryInfo.js.map +1 -1
  57. package/core/QueryManager.d.ts +0 -1
  58. package/core/QueryManager.d.ts.map +1 -1
  59. package/core/QueryManager.js +10 -10
  60. package/core/QueryManager.js.map +1 -1
  61. package/core/{core.cjs.js → core.cjs} +38 -34
  62. package/core/core.cjs.map +1 -0
  63. package/core/package.json +2 -1
  64. package/errors/{errors.cjs.js → errors.cjs} +3 -3
  65. package/errors/errors.cjs.map +1 -0
  66. package/errors/index.d.ts +3 -1
  67. package/errors/index.d.ts.map +1 -1
  68. package/errors/index.js +2 -2
  69. package/errors/index.js.map +1 -1
  70. package/errors/package.json +2 -1
  71. package/invariantErrorCodes.js +84 -104
  72. package/link/batch/{batch.cjs.js → batch.cjs} +2 -2
  73. package/link/batch/batch.cjs.map +1 -0
  74. package/link/batch/batchLink.d.ts +0 -1
  75. package/link/batch/batchLink.d.ts.map +1 -1
  76. package/link/batch/batching.d.ts +0 -1
  77. package/link/batch/batching.d.ts.map +1 -1
  78. package/link/batch/batching.js +1 -1
  79. package/link/batch/batching.js.map +1 -1
  80. package/link/batch/package.json +2 -1
  81. package/link/batch-http/{batch-http.cjs.js → batch-http.cjs} +3 -3
  82. package/link/batch-http/batch-http.cjs.map +1 -0
  83. package/link/batch-http/batchHttpLink.d.ts +0 -1
  84. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  85. package/link/batch-http/batchHttpLink.js +3 -3
  86. package/link/batch-http/batchHttpLink.js.map +1 -1
  87. package/link/batch-http/package.json +2 -1
  88. package/link/context/{context.cjs.js → context.cjs} +1 -1
  89. package/link/context/context.cjs.map +1 -0
  90. package/link/context/index.js.map +1 -1
  91. package/link/context/package.json +2 -1
  92. package/link/core/ApolloLink.d.ts +2 -3
  93. package/link/core/ApolloLink.d.ts.map +1 -1
  94. package/link/core/ApolloLink.js +1 -1
  95. package/link/core/ApolloLink.js.map +1 -1
  96. package/link/core/{core.cjs.js → core.cjs} +2 -2
  97. package/link/core/core.cjs.map +1 -0
  98. package/link/core/package.json +2 -1
  99. package/link/core/types.d.ts +4 -7
  100. package/link/core/types.d.ts.map +1 -1
  101. package/link/core/types.js.map +1 -1
  102. package/link/error/{error.cjs.js → error.cjs} +2 -2
  103. package/link/error/error.cjs.map +1 -0
  104. package/link/error/index.d.ts +5 -7
  105. package/link/error/index.d.ts.map +1 -1
  106. package/link/error/index.js +1 -1
  107. package/link/error/index.js.map +1 -1
  108. package/link/error/package.json +2 -1
  109. package/link/http/checkFetcher.js +1 -1
  110. package/link/http/createHttpLink.d.ts.map +1 -1
  111. package/link/http/createHttpLink.js +3 -3
  112. package/link/http/createHttpLink.js.map +1 -1
  113. package/link/http/{http.cjs.js → http.cjs} +28 -15
  114. package/link/http/http.cjs.map +1 -0
  115. package/link/http/index.d.ts +1 -1
  116. package/link/http/index.d.ts.map +1 -1
  117. package/link/http/index.js +1 -1
  118. package/link/http/index.js.map +1 -1
  119. package/link/http/package.json +2 -1
  120. package/link/http/parseAndCheckHttpResponse.js +3 -3
  121. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  122. package/link/http/rewriteURIForGET.js +1 -1
  123. package/link/http/rewriteURIForGET.js.map +1 -1
  124. package/link/http/selectHttpOptionsAndBody.d.ts +11 -1
  125. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  126. package/link/http/selectHttpOptionsAndBody.js +20 -7
  127. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  128. package/link/http/serializeFetchParameter.js +1 -1
  129. package/link/http/serializeFetchParameter.js.map +1 -1
  130. package/link/persisted-queries/index.d.ts.map +1 -1
  131. package/link/persisted-queries/index.js +3 -3
  132. package/link/persisted-queries/index.js.map +1 -1
  133. package/link/persisted-queries/package.json +2 -1
  134. package/link/persisted-queries/{persisted-queries.cjs.js → persisted-queries.cjs} +3 -3
  135. package/link/persisted-queries/persisted-queries.cjs.map +1 -0
  136. package/link/retry/package.json +2 -1
  137. package/link/retry/{retry.cjs.js → retry.cjs} +1 -1
  138. package/link/retry/retry.cjs.map +1 -0
  139. package/link/retry/retryLink.d.ts +0 -1
  140. package/link/retry/retryLink.d.ts.map +1 -1
  141. package/link/retry/retryLink.js.map +1 -1
  142. package/link/schema/index.d.ts +0 -1
  143. package/link/schema/index.d.ts.map +1 -1
  144. package/link/schema/index.js +8 -1
  145. package/link/schema/index.js.map +1 -1
  146. package/link/schema/package.json +2 -1
  147. package/link/schema/{schema.cjs.js → schema.cjs} +9 -2
  148. package/link/schema/schema.cjs.map +1 -0
  149. package/link/utils/fromError.d.ts +0 -1
  150. package/link/utils/fromError.d.ts.map +1 -1
  151. package/link/utils/fromPromise.d.ts +0 -1
  152. package/link/utils/fromPromise.d.ts.map +1 -1
  153. package/link/utils/package.json +2 -1
  154. package/link/utils/toPromise.d.ts +0 -1
  155. package/link/utils/toPromise.d.ts.map +1 -1
  156. package/link/utils/{utils.cjs.js → utils.cjs} +2 -2
  157. package/link/utils/utils.cjs.map +1 -0
  158. package/link/utils/validateOperation.js +1 -1
  159. package/link/utils/validateOperation.js.map +1 -1
  160. package/link/ws/index.d.ts +0 -1
  161. package/link/ws/index.d.ts.map +1 -1
  162. package/link/ws/package.json +2 -1
  163. package/link/ws/{ws.cjs.js → ws.cjs} +1 -1
  164. package/link/ws/ws.cjs.map +1 -0
  165. package/{main.cjs.js → main.cjs} +5 -5
  166. package/main.cjs.map +1 -0
  167. package/package.json +20 -19
  168. package/react/components/Query.js.map +1 -1
  169. package/react/components/{components.cjs.js → components.cjs} +4 -4
  170. package/react/components/components.cjs.map +1 -0
  171. package/react/components/package.json +2 -1
  172. package/react/context/ApolloConsumer.js +1 -1
  173. package/react/context/ApolloProvider.js +1 -1
  174. package/react/context/{context.cjs.js → context.cjs} +6 -6
  175. package/react/context/context.cjs.map +1 -0
  176. package/react/context/index.d.ts +3 -3
  177. package/react/context/index.d.ts.map +1 -1
  178. package/react/context/index.js +3 -3
  179. package/react/context/index.js.map +1 -1
  180. package/react/context/package.json +2 -1
  181. package/react/hoc/hoc-utils.js +1 -1
  182. package/react/hoc/{hoc.cjs.js → hoc.cjs} +12 -12
  183. package/react/hoc/hoc.cjs.map +1 -0
  184. package/react/hoc/mutation-hoc.js +2 -2
  185. package/react/hoc/mutation-hoc.js.map +1 -1
  186. package/react/hoc/package.json +2 -1
  187. package/react/hoc/query-hoc.js +1 -1
  188. package/react/hoc/query-hoc.js.map +1 -1
  189. package/react/hoc/subscription-hoc.js +1 -1
  190. package/react/hoc/subscription-hoc.js.map +1 -1
  191. package/react/hoc/withApollo.js +2 -2
  192. package/react/hoc/withApollo.js.map +1 -1
  193. package/react/hooks/hooks.cjs +502 -0
  194. package/react/hooks/hooks.cjs.map +1 -0
  195. package/react/hooks/package.json +2 -1
  196. package/react/hooks/useApolloClient.d.ts +1 -1
  197. package/react/hooks/useApolloClient.d.ts.map +1 -1
  198. package/react/hooks/useApolloClient.js +7 -5
  199. package/react/hooks/useApolloClient.js.map +1 -1
  200. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  201. package/react/hooks/useLazyQuery.js +56 -2
  202. package/react/hooks/useLazyQuery.js.map +1 -1
  203. package/react/hooks/useMutation.d.ts.map +1 -1
  204. package/react/hooks/useMutation.js +89 -21
  205. package/react/hooks/useMutation.js.map +1 -1
  206. package/react/hooks/useQuery.d.ts +2 -3
  207. package/react/hooks/useQuery.d.ts.map +1 -1
  208. package/react/hooks/useQuery.js +224 -2
  209. package/react/hooks/useQuery.js.map +1 -1
  210. package/react/hooks/useSubscription.d.ts +2 -7
  211. package/react/hooks/useSubscription.d.ts.map +1 -1
  212. package/react/hooks/useSubscription.js +89 -32
  213. package/react/hooks/useSubscription.js.map +1 -1
  214. package/react/package.json +2 -1
  215. package/react/parser/index.d.ts +1 -0
  216. package/react/parser/index.d.ts.map +1 -1
  217. package/react/parser/index.js +16 -9
  218. package/react/parser/index.js.map +1 -1
  219. package/react/parser/package.json +2 -1
  220. package/react/parser/{parser.cjs.js → parser.cjs} +18 -10
  221. package/react/parser/parser.cjs.map +1 -0
  222. package/react/{react.cjs.js → react.cjs} +3 -3
  223. package/react/react.cjs.map +1 -0
  224. package/react/ssr/RenderPromises.d.ts +7 -3
  225. package/react/ssr/RenderPromises.d.ts.map +1 -1
  226. package/react/ssr/RenderPromises.js.map +1 -1
  227. package/react/ssr/package.json +2 -1
  228. package/react/ssr/{ssr.cjs.js → ssr.cjs} +4 -4
  229. package/react/ssr/ssr.cjs.map +1 -0
  230. package/react/types/types.d.ts +7 -18
  231. package/react/types/types.d.ts.map +1 -1
  232. package/react/types/types.js.map +1 -1
  233. package/testing/{testing.cjs.js → core/core.cjs} +10 -104
  234. package/testing/core/core.cjs.map +1 -0
  235. package/{utilities/testing → testing/core}/index.d.ts +0 -1
  236. package/testing/core/index.d.ts.map +1 -0
  237. package/{utilities/testing → testing/core}/index.js +0 -1
  238. package/testing/core/index.js.map +1 -0
  239. package/{utilities/testing → testing/core}/itAsync.d.ts +0 -0
  240. package/testing/core/itAsync.d.ts.map +1 -0
  241. package/{utilities/testing → testing/core}/itAsync.js +0 -0
  242. package/testing/core/itAsync.js.map +1 -0
  243. package/{utilities/testing → testing/core}/mocking/mockClient.d.ts +0 -0
  244. package/testing/core/mocking/mockClient.d.ts.map +1 -0
  245. package/{utilities/testing → testing/core}/mocking/mockClient.js +0 -0
  246. package/testing/core/mocking/mockClient.js.map +1 -0
  247. package/{utilities/testing → testing/core}/mocking/mockFetch.d.ts +0 -0
  248. package/testing/core/mocking/mockFetch.d.ts.map +1 -0
  249. package/{utilities/testing → testing/core}/mocking/mockFetch.js +1 -1
  250. package/testing/core/mocking/mockFetch.js.map +1 -0
  251. package/{utilities/testing → testing/core}/mocking/mockLink.d.ts +0 -1
  252. package/testing/core/mocking/mockLink.d.ts.map +1 -0
  253. package/{utilities/testing → testing/core}/mocking/mockLink.js +5 -5
  254. package/testing/core/mocking/mockLink.js.map +1 -0
  255. package/{utilities/testing → testing/core}/mocking/mockQueryManager.d.ts +1 -1
  256. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
  257. package/{utilities/testing → testing/core}/mocking/mockQueryManager.js +1 -1
  258. package/testing/core/mocking/mockQueryManager.js.map +1 -0
  259. package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.d.ts +1 -4
  260. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
  261. package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.js +1 -1
  262. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
  263. package/{utilities/testing → testing/core}/mocking/mockWatchQuery.d.ts +1 -1
  264. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
  265. package/{utilities/testing → testing/core}/mocking/mockWatchQuery.js +0 -0
  266. package/testing/core/mocking/mockWatchQuery.js.map +1 -0
  267. package/{utilities/testing → testing/core}/observableToPromise.d.ts +2 -3
  268. package/testing/core/observableToPromise.d.ts.map +1 -0
  269. package/{utilities/testing → testing/core}/observableToPromise.js +1 -1
  270. package/testing/core/observableToPromise.js.map +1 -0
  271. package/testing/core/package.json +8 -0
  272. package/testing/core/subscribeAndCount.d.ts +4 -0
  273. package/testing/core/subscribeAndCount.d.ts.map +1 -0
  274. package/{utilities/testing → testing/core}/subscribeAndCount.js +1 -1
  275. package/testing/core/subscribeAndCount.js.map +1 -0
  276. package/{utilities/testing → testing/core}/withConsoleSpy.d.ts +0 -0
  277. package/testing/core/withConsoleSpy.d.ts.map +1 -0
  278. package/{utilities/testing → testing/core}/withConsoleSpy.js +0 -0
  279. package/testing/core/withConsoleSpy.js.map +1 -0
  280. package/{utilities/testing → testing/core}/wrap.d.ts +0 -0
  281. package/testing/core/wrap.d.ts.map +1 -0
  282. package/{utilities/testing → testing/core}/wrap.js +0 -0
  283. package/testing/core/wrap.js.map +1 -0
  284. package/testing/index.d.ts +2 -1
  285. package/testing/index.d.ts.map +1 -1
  286. package/testing/index.js +2 -1
  287. package/testing/index.js.map +1 -1
  288. package/testing/package.json +2 -1
  289. package/{utilities/testing/mocking → testing/react}/MockedProvider.d.ts +5 -5
  290. package/testing/react/MockedProvider.d.ts.map +1 -0
  291. package/{utilities/testing/mocking → testing/react}/MockedProvider.js +4 -4
  292. package/testing/react/MockedProvider.js.map +1 -0
  293. package/testing/testing.cjs +58 -0
  294. package/testing/testing.cjs.map +1 -0
  295. package/utilities/common/errorHandling.d.ts +1 -1
  296. package/utilities/common/errorHandling.d.ts.map +1 -1
  297. package/utilities/common/errorHandling.js.map +1 -1
  298. package/utilities/common/makeUniqueId.js +1 -1
  299. package/utilities/common/makeUniqueId.js.map +1 -1
  300. package/utilities/common/mergeDeep.d.ts.map +1 -1
  301. package/utilities/common/mergeDeep.js +6 -1
  302. package/utilities/common/mergeDeep.js.map +1 -1
  303. package/utilities/globals/fix-graphql.js +1 -1
  304. package/utilities/globals/global.d.ts.map +1 -1
  305. package/utilities/globals/global.js +1 -1
  306. package/utilities/globals/global.js.map +1 -1
  307. package/utilities/globals/{globals.cjs.js → globals.cjs} +3 -3
  308. package/utilities/globals/globals.cjs.map +1 -0
  309. package/utilities/globals/index.js +1 -1
  310. package/utilities/globals/package.json +2 -1
  311. package/utilities/graphql/directives.js +5 -5
  312. package/utilities/graphql/directives.js.map +1 -1
  313. package/utilities/graphql/fragments.d.ts.map +1 -1
  314. package/utilities/graphql/fragments.js +4 -4
  315. package/utilities/graphql/fragments.js.map +1 -1
  316. package/utilities/graphql/getFromAST.js +8 -8
  317. package/utilities/graphql/getFromAST.js.map +1 -1
  318. package/utilities/graphql/storeUtils.js +6 -6
  319. package/utilities/graphql/storeUtils.js.map +1 -1
  320. package/utilities/graphql/transform.d.ts.map +1 -1
  321. package/utilities/graphql/transform.js.map +1 -1
  322. package/utilities/observables/Concast.d.ts +0 -1
  323. package/utilities/observables/Concast.d.ts.map +1 -1
  324. package/utilities/observables/asyncMap.d.ts +0 -1
  325. package/utilities/observables/asyncMap.d.ts.map +1 -1
  326. package/utilities/observables/subclassing.d.ts +0 -1
  327. package/utilities/observables/subclassing.d.ts.map +1 -1
  328. package/utilities/package.json +2 -1
  329. package/utilities/{utilities.cjs.js → utilities.cjs} +31 -26
  330. package/utilities/utilities.cjs.map +1 -0
  331. package/version.js +1 -1
  332. package/apollo-client.cjs.js.map +0 -1
  333. package/apollo-client.cjs.min.js +0 -1
  334. package/cache/cache.cjs.js.map +0 -1
  335. package/core/core.cjs.js.map +0 -1
  336. package/errors/errors.cjs.js.map +0 -1
  337. package/link/batch/batch.cjs.js.map +0 -1
  338. package/link/batch-http/batch-http.cjs.js.map +0 -1
  339. package/link/context/context.cjs.js.map +0 -1
  340. package/link/core/core.cjs.js.map +0 -1
  341. package/link/error/error.cjs.js.map +0 -1
  342. package/link/http/http.cjs.js.map +0 -1
  343. package/link/persisted-queries/persisted-queries.cjs.js.map +0 -1
  344. package/link/retry/retry.cjs.js.map +0 -1
  345. package/link/schema/schema.cjs.js.map +0 -1
  346. package/link/utils/utils.cjs.js.map +0 -1
  347. package/link/ws/ws.cjs.js.map +0 -1
  348. package/main.cjs.js.map +0 -1
  349. package/react/components/components.cjs.js.map +0 -1
  350. package/react/context/context.cjs.js.map +0 -1
  351. package/react/data/MutationData.d.ts +0 -29
  352. package/react/data/MutationData.d.ts.map +0 -1
  353. package/react/data/MutationData.js +0 -115
  354. package/react/data/MutationData.js.map +0 -1
  355. package/react/data/OperationData.d.ts +0 -24
  356. package/react/data/OperationData.d.ts.map +0 -1
  357. package/react/data/OperationData.js +0 -53
  358. package/react/data/OperationData.js.map +0 -1
  359. package/react/data/QueryData.d.ts +0 -44
  360. package/react/data/QueryData.d.ts.map +0 -1
  361. package/react/data/QueryData.js +0 -298
  362. package/react/data/QueryData.js.map +0 -1
  363. package/react/data/SubscriptionData.d.ts +0 -28
  364. package/react/data/SubscriptionData.d.ts.map +0 -1
  365. package/react/data/SubscriptionData.js +0 -122
  366. package/react/data/SubscriptionData.js.map +0 -1
  367. package/react/data/data.cjs.js +0 -581
  368. package/react/data/data.cjs.js.map +0 -1
  369. package/react/data/index.d.ts +0 -6
  370. package/react/data/index.d.ts.map +0 -1
  371. package/react/data/index.js +0 -6
  372. package/react/data/index.js.map +0 -1
  373. package/react/data/package.json +0 -7
  374. package/react/hoc/hoc.cjs.js.map +0 -1
  375. package/react/hooks/hooks.cjs.js +0 -195
  376. package/react/hooks/hooks.cjs.js.map +0 -1
  377. package/react/hooks/utils/useAfterFastRefresh.d.ts +0 -3
  378. package/react/hooks/utils/useAfterFastRefresh.d.ts.map +0 -1
  379. package/react/hooks/utils/useAfterFastRefresh.js +0 -19
  380. package/react/hooks/utils/useAfterFastRefresh.js.map +0 -1
  381. package/react/hooks/utils/useBaseQuery.d.ts +0 -7
  382. package/react/hooks/utils/useBaseQuery.d.ts.map +0 -1
  383. package/react/hooks/utils/useBaseQuery.js +0 -55
  384. package/react/hooks/utils/useBaseQuery.js.map +0 -1
  385. package/react/hooks/utils/useDeepMemo.d.ts +0 -2
  386. package/react/hooks/utils/useDeepMemo.d.ts.map +0 -1
  387. package/react/hooks/utils/useDeepMemo.js +0 -10
  388. package/react/hooks/utils/useDeepMemo.js.map +0 -1
  389. package/react/parser/parser.cjs.js.map +0 -1
  390. package/react/react.cjs.js.map +0 -1
  391. package/react/ssr/ssr.cjs.js.map +0 -1
  392. package/testing/testing.cjs.js.map +0 -1
  393. package/utilities/globals/globals.cjs.js.map +0 -1
  394. package/utilities/testing/index.d.ts.map +0 -1
  395. package/utilities/testing/index.js.map +0 -1
  396. package/utilities/testing/itAsync.d.ts.map +0 -1
  397. package/utilities/testing/itAsync.js.map +0 -1
  398. package/utilities/testing/mocking/MockedProvider.d.ts.map +0 -1
  399. package/utilities/testing/mocking/MockedProvider.js.map +0 -1
  400. package/utilities/testing/mocking/mockClient.d.ts.map +0 -1
  401. package/utilities/testing/mocking/mockClient.js.map +0 -1
  402. package/utilities/testing/mocking/mockFetch.d.ts.map +0 -1
  403. package/utilities/testing/mocking/mockFetch.js.map +0 -1
  404. package/utilities/testing/mocking/mockLink.d.ts.map +0 -1
  405. package/utilities/testing/mocking/mockLink.js.map +0 -1
  406. package/utilities/testing/mocking/mockQueryManager.d.ts.map +0 -1
  407. package/utilities/testing/mocking/mockQueryManager.js.map +0 -1
  408. package/utilities/testing/mocking/mockSubscriptionLink.d.ts.map +0 -1
  409. package/utilities/testing/mocking/mockSubscriptionLink.js.map +0 -1
  410. package/utilities/testing/mocking/mockWatchQuery.d.ts.map +0 -1
  411. package/utilities/testing/mocking/mockWatchQuery.js.map +0 -1
  412. package/utilities/testing/observableToPromise.d.ts.map +0 -1
  413. package/utilities/testing/observableToPromise.js.map +0 -1
  414. package/utilities/testing/subscribeAndCount.d.ts +0 -5
  415. package/utilities/testing/subscribeAndCount.d.ts.map +0 -1
  416. package/utilities/testing/subscribeAndCount.js.map +0 -1
  417. package/utilities/testing/withConsoleSpy.d.ts.map +0 -1
  418. package/utilities/testing/withConsoleSpy.js.map +0 -1
  419. package/utilities/testing/wrap.d.ts.map +0 -1
  420. package/utilities/testing/wrap.js.map +0 -1
  421. package/utilities/utilities.cjs.js.map +0 -1
@@ -18,11 +18,11 @@ function _interopNamespace(e) {
18
18
  if (e && e.__esModule) return e;
19
19
  var n = Object.create(null);
20
20
  if (e) {
21
- Object.keys(e).forEach(function (k) {
21
+ for (var k in e) {
22
22
  n[k] = e[k];
23
- });
23
+ }
24
24
  }
25
- n['default'] = e;
25
+ n["default"] = e;
26
26
  return Object.freeze(n);
27
27
  }
28
28
 
@@ -45,7 +45,7 @@ function shouldInclude(_a, variables) {
45
45
  var evaledValue = false;
46
46
  if (ifArgument.value.kind === 'Variable') {
47
47
  evaledValue = variables && variables[ifArgument.value.name.value];
48
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.") : tsInvariant.invariant(evaledValue !== void 0, 39);
48
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 37);
49
49
  }
50
50
  else {
51
51
  evaledValue = ifArgument.value.value;
@@ -82,13 +82,13 @@ function getInclusionDirectives(directives) {
82
82
  return;
83
83
  var directiveArguments = directive.arguments;
84
84
  var directiveName = directive.name.value;
85
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.") : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 40);
85
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
86
86
  var ifArgument = directiveArguments[0];
87
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.") : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 41);
87
+ __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
88
88
  var ifValue = ifArgument.value;
89
89
  __DEV__ ? tsInvariant.invariant(ifValue &&
90
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.") : tsInvariant.invariant(ifValue &&
91
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 42);
90
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
91
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
92
92
  result.push({ directive: directive, ifArgument: ifArgument });
93
93
  });
94
94
  }
@@ -100,15 +100,15 @@ function getFragmentQueryDocument(document, fragmentName) {
100
100
  var fragments = [];
101
101
  document.definitions.forEach(function (definition) {
102
102
  if (definition.kind === 'OperationDefinition') {
103
- throw __DEV__ ? new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
104
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(43);
103
+ throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
104
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(41);
105
105
  }
106
106
  if (definition.kind === 'FragmentDefinition') {
107
107
  fragments.push(definition);
108
108
  }
109
109
  });
110
110
  if (typeof actualFragmentName === 'undefined') {
111
- __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.") : tsInvariant.invariant(fragments.length === 1, 44);
111
+ __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : tsInvariant.invariant(fragments.length === 1, 42);
112
112
  actualFragmentName = fragments[0].name.value;
113
113
  }
114
114
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -145,7 +145,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
145
145
  return selection;
146
146
  case 'FragmentSpread': {
147
147
  var fragment = fragmentMap && fragmentMap[selection.name.value];
148
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value + ".") : tsInvariant.invariant(fragment, 45);
148
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value, ".")) : tsInvariant.invariant(fragment, 43);
149
149
  return fragment;
150
150
  }
151
151
  default:
@@ -227,9 +227,9 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
227
227
  argObj[name.value] = null;
228
228
  }
229
229
  else {
230
- throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
230
+ throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
231
231
  'is not supported. Use variables instead of inline arguments to ' +
232
- 'overcome this limitation.') : new tsInvariant.InvariantError(54);
232
+ 'overcome this limitation.') : new tsInvariant.InvariantError(52);
233
233
  }
234
234
  }
235
235
  function storeKeyNameFromField(field, variables) {
@@ -279,7 +279,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
279
279
  filterKeys.forEach(function (key) {
280
280
  filteredArgs_1[key] = args[key];
281
281
  });
282
- return directives['connection']['key'] + "(" + stringify(filteredArgs_1) + ")";
282
+ return "".concat(directives['connection']['key'], "(").concat(stringify(filteredArgs_1), ")");
283
283
  }
284
284
  else {
285
285
  return directives['connection']['key'];
@@ -288,17 +288,17 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
288
288
  var completeFieldName = fieldName;
289
289
  if (args) {
290
290
  var stringifiedArgs = stringify(args);
291
- completeFieldName += "(" + stringifiedArgs + ")";
291
+ completeFieldName += "(".concat(stringifiedArgs, ")");
292
292
  }
293
293
  if (directives) {
294
294
  Object.keys(directives).forEach(function (key) {
295
295
  if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
296
296
  return;
297
297
  if (directives[key] && Object.keys(directives[key]).length) {
298
- completeFieldName += "@" + key + "(" + stringify(directives[key]) + ")";
298
+ completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
299
299
  }
300
300
  else {
301
- completeFieldName += "@" + key;
301
+ completeFieldName += "@".concat(key);
302
302
  }
303
303
  });
304
304
  }
@@ -363,16 +363,16 @@ function isInlineFragment(selection) {
363
363
  }
364
364
 
365
365
  function checkDocument(doc) {
366
- __DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 46);
366
+ __DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 44);
367
367
  var operations = doc.definitions
368
368
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
369
369
  .map(function (definition) {
370
370
  if (definition.kind !== 'OperationDefinition') {
371
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"") : new tsInvariant.InvariantError(47);
371
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(45);
372
372
  }
373
373
  return definition;
374
374
  });
375
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations") : tsInvariant.invariant(operations.length <= 1, 48);
375
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 46);
376
376
  return doc;
377
377
  }
378
378
  function getOperationDefinition(doc) {
@@ -391,14 +391,14 @@ function getFragmentDefinitions(doc) {
391
391
  }
392
392
  function getQueryDefinition(doc) {
393
393
  var queryDef = getOperationDefinition(doc);
394
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 49);
394
+ __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 47);
395
395
  return queryDef;
396
396
  }
397
397
  function getFragmentDefinition(doc) {
398
- __DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 50);
399
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 51);
398
+ __DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 48);
399
+ __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 49);
400
400
  var fragmentDef = doc.definitions[0];
401
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 52);
401
+ __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 50);
402
402
  return fragmentDef;
403
403
  }
404
404
  function getMainDefinition(queryDoc) {
@@ -421,7 +421,7 @@ function getMainDefinition(queryDoc) {
421
421
  if (fragmentDefinition) {
422
422
  return fragmentDefinition;
423
423
  }
424
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(53);
424
+ throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(51);
425
425
  }
426
426
  function getDefaultValues(definition) {
427
427
  var defaultValues = Object.create(null);
@@ -760,7 +760,12 @@ var DeepMerger = (function () {
760
760
  return source;
761
761
  };
762
762
  DeepMerger.prototype.shallowCopyForMerge = function (value) {
763
- if (isNonNullObject(value) && !this.pastCopies.has(value)) {
763
+ if (isNonNullObject(value)) {
764
+ if (this.pastCopies.has(value)) {
765
+ if (!Object.isFrozen(value))
766
+ return value;
767
+ this.pastCopies.delete(value);
768
+ }
764
769
  if (Array.isArray(value)) {
765
770
  value = value.slice(0);
766
771
  }
@@ -1072,7 +1077,7 @@ var prefixCounts = new Map();
1072
1077
  function makeUniqueId(prefix) {
1073
1078
  var count = prefixCounts.get(prefix) || 1;
1074
1079
  prefixCounts.set(prefix, count + 1);
1075
- return prefix + ":" + count + ":" + Math.random().toString(36).slice(2);
1080
+ return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
1076
1081
  }
1077
1082
 
1078
1083
  function stringifyForDisplay(value) {
@@ -1137,7 +1142,7 @@ function validateOperation(operation) {
1137
1142
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1138
1143
  var key = _a[_i];
1139
1144
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1140
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: " + key) : new tsInvariant.InvariantError(26);
1145
+ throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: ".concat(key)) : new tsInvariant.InvariantError(24);
1141
1146
  }
1142
1147
  }
1143
1148
  return operation;
@@ -1260,7 +1265,7 @@ var ApolloLink = (function () {
1260
1265
  return ApolloLink.concat(this, next);
1261
1266
  };
1262
1267
  ApolloLink.prototype.request = function (operation, forward) {
1263
- throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(21);
1268
+ throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(19);
1264
1269
  };
1265
1270
  ApolloLink.prototype.onError = function (error, observer) {
1266
1271
  if (observer && observer.error) {
@@ -1286,7 +1291,7 @@ var concat = ApolloLink.concat;
1286
1291
 
1287
1292
  var execute = ApolloLink.execute;
1288
1293
 
1289
- var version = '3.4.17';
1294
+ var version = '3.5.6';
1290
1295
 
1291
1296
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1292
1297
  function parseAndCheckHttpResponse(operations) {
@@ -1307,14 +1312,14 @@ function parseAndCheckHttpResponse(operations) {
1307
1312
  })
1308
1313
  .then(function (result) {
1309
1314
  if (response.status >= 300) {
1310
- throwServerError(response, result, "Response not successful: Received status code " + response.status);
1315
+ throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
1311
1316
  }
1312
1317
  if (!Array.isArray(result) &&
1313
1318
  !hasOwnProperty$2.call(result, 'data') &&
1314
1319
  !hasOwnProperty$2.call(result, 'errors')) {
1315
- throwServerError(response, result, "Server response was missing for query '" + (Array.isArray(operations)
1320
+ throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
1316
1321
  ? operations.map(function (op) { return op.operationName; })
1317
- : operations.operationName) + "'.");
1322
+ : operations.operationName, "'."));
1318
1323
  }
1319
1324
  return result;
1320
1325
  }); };
@@ -1326,7 +1331,7 @@ var serializeFetchParameter = function (p, label) {
1326
1331
  serialized = JSON.stringify(p);
1327
1332
  }
1328
1333
  catch (e) {
1329
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message) : new tsInvariant.InvariantError(23);
1334
+ var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new tsInvariant.InvariantError(21);
1330
1335
  parseError.parseError = e;
1331
1336
  throw parseError;
1332
1337
  }
@@ -1349,17 +1354,28 @@ var fallbackHttpConfig = {
1349
1354
  headers: defaultHeaders,
1350
1355
  options: defaultOptions,
1351
1356
  };
1352
- var selectHttpOptionsAndBody = function (operation, fallbackConfig) {
1357
+ var defaultPrinter = function (ast, printer) { return printer(ast); };
1358
+ function selectHttpOptionsAndBody(operation, fallbackConfig) {
1359
+ var configs = [];
1360
+ for (var _i = 2; _i < arguments.length; _i++) {
1361
+ configs[_i - 2] = arguments[_i];
1362
+ }
1363
+ configs.unshift(fallbackConfig);
1364
+ return selectHttpOptionsAndBodyInternal.apply(void 0, tslib.__spreadArray([operation,
1365
+ defaultPrinter], configs, false));
1366
+ }
1367
+ function selectHttpOptionsAndBodyInternal(operation, printer) {
1353
1368
  var configs = [];
1354
1369
  for (var _i = 2; _i < arguments.length; _i++) {
1355
1370
  configs[_i - 2] = arguments[_i];
1356
1371
  }
1357
- var options = tslib.__assign(tslib.__assign({}, fallbackConfig.options), { headers: fallbackConfig.headers, credentials: fallbackConfig.credentials });
1358
- var http = fallbackConfig.http || {};
1372
+ var options = {};
1373
+ var http = {};
1359
1374
  configs.forEach(function (config) {
1360
1375
  options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), headersToLowerCase(config.headers)) });
1361
- if (config.credentials)
1376
+ if (config.credentials) {
1362
1377
  options.credentials = config.credentials;
1378
+ }
1363
1379
  http = tslib.__assign(tslib.__assign({}, http), config.http);
1364
1380
  });
1365
1381
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
@@ -1367,12 +1383,12 @@ var selectHttpOptionsAndBody = function (operation, fallbackConfig) {
1367
1383
  if (http.includeExtensions)
1368
1384
  body.extensions = extensions;
1369
1385
  if (http.includeQuery)
1370
- body.query = graphql.print(query);
1386
+ body.query = printer(query, graphql.print);
1371
1387
  return {
1372
1388
  options: options,
1373
1389
  body: body,
1374
1390
  };
1375
- };
1391
+ }
1376
1392
  function headersToLowerCase(headers) {
1377
1393
  if (headers) {
1378
1394
  var normalized_1 = Object.create(null);
@@ -1386,7 +1402,7 @@ function headersToLowerCase(headers) {
1386
1402
 
1387
1403
  var checkFetcher = function (fetcher) {
1388
1404
  if (!fetcher && typeof fetch === 'undefined') {
1389
- throw __DEV__ ? new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ") : new tsInvariant.InvariantError(22);
1405
+ throw __DEV__ ? new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ") : new tsInvariant.InvariantError(20);
1390
1406
  }
1391
1407
  };
1392
1408
 
@@ -1415,7 +1431,7 @@ var selectURI = function (operation, fallbackURI) {
1415
1431
  function rewriteURIForGET(chosenURI, body) {
1416
1432
  var queryParams = [];
1417
1433
  var addQueryParam = function (key, value) {
1418
- queryParams.push(key + "=" + encodeURIComponent(value));
1434
+ queryParams.push("".concat(key, "=").concat(encodeURIComponent(value)));
1419
1435
  };
1420
1436
  if ('query' in body) {
1421
1437
  addQueryParam('query', body.query);
@@ -1457,7 +1473,7 @@ function rewriteURIForGET(chosenURI, body) {
1457
1473
  var backupFetch = maybe(function () { return fetch; });
1458
1474
  var createHttpLink = function (linkOptions) {
1459
1475
  if (linkOptions === void 0) { linkOptions = {}; }
1460
- var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, preferredFetch = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, _b = linkOptions.includeUnusedVariables, includeUnusedVariables = _b === void 0 ? false : _b, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries", "includeUnusedVariables"]);
1476
+ var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, preferredFetch = linkOptions.fetch, _b = linkOptions.print, print = _b === void 0 ? defaultPrinter : _b, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, _c = linkOptions.includeUnusedVariables, includeUnusedVariables = _c === void 0 ? false : _c, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "print", "includeExtensions", "useGETForQueries", "includeUnusedVariables"]);
1461
1477
  if (__DEV__) {
1462
1478
  checkFetcher(preferredFetch || backupFetch);
1463
1479
  }
@@ -1487,7 +1503,7 @@ var createHttpLink = function (linkOptions) {
1487
1503
  credentials: context.credentials,
1488
1504
  headers: contextHeaders,
1489
1505
  };
1490
- var _b = selectHttpOptionsAndBody(operation, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1506
+ var _b = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1491
1507
  if (body.variables && !includeUnusedVariables) {
1492
1508
  var unusedNames_1 = new Set(Object.keys(body.variables));
1493
1509
  graphql.visit(operation.query, {
@@ -1578,9 +1594,12 @@ var ApolloCache = (function () {
1578
1594
  this.getFragmentDoc = optimism.wrap(getFragmentQueryDocument);
1579
1595
  }
1580
1596
  ApolloCache.prototype.batch = function (options) {
1597
+ var _this = this;
1581
1598
  var optimisticId = typeof options.optimistic === "string" ? options.optimistic :
1582
1599
  options.optimistic === false ? null : void 0;
1583
- this.performTransaction(options.update, optimisticId);
1600
+ var updateResult;
1601
+ this.performTransaction(function () { return updateResult = options.update(_this); }, optimisticId);
1602
+ return updateResult;
1584
1603
  };
1585
1604
  ApolloCache.prototype.recordOptimisticTransaction = function (transaction, optimisticId) {
1586
1605
  this.performTransaction(transaction, optimisticId);
@@ -1623,6 +1642,30 @@ var ApolloCache = (function () {
1623
1642
  result: data,
1624
1643
  }));
1625
1644
  };
1645
+ ApolloCache.prototype.updateQuery = function (options, update) {
1646
+ return this.batch({
1647
+ update: function (cache) {
1648
+ var value = cache.readQuery(options);
1649
+ var data = update(value);
1650
+ if (data === void 0 || data === null)
1651
+ return value;
1652
+ cache.writeQuery(tslib.__assign(tslib.__assign({}, options), { data: data }));
1653
+ return data;
1654
+ },
1655
+ });
1656
+ };
1657
+ ApolloCache.prototype.updateFragment = function (options, update) {
1658
+ return this.batch({
1659
+ update: function (cache) {
1660
+ var value = cache.readFragment(options);
1661
+ var data = update(value);
1662
+ if (data === void 0 || data === null)
1663
+ return value;
1664
+ cache.writeFragment(tslib.__assign(tslib.__assign({}, options), { data: data }));
1665
+ return data;
1666
+ },
1667
+ });
1668
+ };
1626
1669
  return ApolloCache;
1627
1670
  }());
1628
1671
 
@@ -1630,19 +1673,15 @@ exports.Cache = void 0;
1630
1673
  (function (Cache) {
1631
1674
  })(exports.Cache || (exports.Cache = {}));
1632
1675
 
1633
- var MissingFieldError = (function (_super) {
1634
- tslib.__extends(MissingFieldError, _super);
1676
+ var MissingFieldError = (function () {
1635
1677
  function MissingFieldError(message, path, query, variables) {
1636
- var _this = _super.call(this, message) || this;
1637
- _this.message = message;
1638
- _this.path = path;
1639
- _this.query = query;
1640
- _this.variables = variables;
1641
- _this.__proto__ = MissingFieldError.prototype;
1642
- return _this;
1678
+ this.message = message;
1679
+ this.path = path;
1680
+ this.query = query;
1681
+ this.variables = variables;
1643
1682
  }
1644
1683
  return MissingFieldError;
1645
- }(Error));
1684
+ }());
1646
1685
 
1647
1686
  var hasOwn = Object.prototype.hasOwnProperty;
1648
1687
  function defaultDataIdFromObject(_a, context) {
@@ -1657,7 +1696,7 @@ function defaultDataIdFromObject(_a, context) {
1657
1696
  if (id === void 0)
1658
1697
  id = _id;
1659
1698
  if (id !== void 0) {
1660
- return __typename + ":" + ((typeof id === "number" ||
1699
+ return "".concat(__typename, ":").concat((typeof id === "number" ||
1661
1700
  typeof id === "string") ? id : JSON.stringify(id));
1662
1701
  }
1663
1702
  }
@@ -2283,9 +2322,6 @@ function resetCanonicalStringify() {
2283
2322
  stringifyCache = new (canUseWeakMap ? WeakMap : Map)();
2284
2323
  }
2285
2324
 
2286
- function missingFromInvariant(err, context) {
2287
- return new MissingFieldError(err.message, context.path.slice(), context.query, context.variables);
2288
- }
2289
2325
  function execSelectionSetKeyArgs(options) {
2290
2326
  return [
2291
2327
  options.selectionSet,
@@ -2347,6 +2383,7 @@ var StoreReader = (function () {
2347
2383
  var policies = this.config.cache.policies;
2348
2384
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(getQueryDefinition(query))), variables);
2349
2385
  var rootRef = makeReference(rootId);
2386
+ var merger = new DeepMerger;
2350
2387
  var execResult = this.executeSelectionSet({
2351
2388
  selectionSet: getMainDefinition(query).selectionSet,
2352
2389
  objectOrReference: rootRef,
@@ -2359,17 +2396,22 @@ var StoreReader = (function () {
2359
2396
  varString: canonicalStringify(variables),
2360
2397
  canonizeResults: canonizeResults,
2361
2398
  fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
2362
- path: [],
2399
+ merge: function (a, b) {
2400
+ return merger.merge(a, b);
2401
+ },
2363
2402
  },
2364
2403
  });
2365
- var hasMissingFields = execResult.missing && execResult.missing.length > 0;
2366
- if (hasMissingFields && !returnPartialData) {
2367
- throw execResult.missing[0];
2404
+ var missing;
2405
+ if (execResult.missing) {
2406
+ missing = [new MissingFieldError(firstMissing(execResult.missing), execResult.missing, query, variables)];
2407
+ if (!returnPartialData) {
2408
+ throw missing[0];
2409
+ }
2368
2410
  }
2369
2411
  return {
2370
2412
  result: execResult.result,
2371
- missing: execResult.missing,
2372
- complete: !hasMissingFields,
2413
+ complete: !missing,
2414
+ missing: missing,
2373
2415
  };
2374
2416
  };
2375
2417
  StoreReader.prototype.isFresh = function (result, parent, selectionSet, context) {
@@ -2390,30 +2432,28 @@ var StoreReader = (function () {
2390
2432
  !context.store.has(objectOrReference.__ref)) {
2391
2433
  return {
2392
2434
  result: this.canon.empty,
2393
- missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(5), context)],
2435
+ missing: "Dangling reference to missing ".concat(objectOrReference.__ref, " object"),
2394
2436
  };
2395
2437
  }
2396
2438
  var variables = context.variables, policies = context.policies, store = context.store;
2397
- var objectsToMerge = [];
2398
- var finalResult = { result: null };
2399
2439
  var typename = store.getFieldValue(objectOrReference, "__typename");
2440
+ var result = {};
2441
+ var missing;
2400
2442
  if (this.config.addTypename &&
2401
2443
  typeof typename === "string" &&
2402
2444
  !policies.rootIdsByTypename[typename]) {
2403
- objectsToMerge.push({ __typename: typename });
2404
- }
2405
- function getMissing() {
2406
- return finalResult.missing || (finalResult.missing = []);
2445
+ result = { __typename: typename };
2407
2446
  }
2408
- function handleMissing(result) {
2447
+ function handleMissing(result, resultName) {
2409
2448
  var _a;
2410
- if (result.missing)
2411
- (_a = getMissing()).push.apply(_a, result.missing);
2449
+ if (result.missing) {
2450
+ missing = context.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
2451
+ }
2412
2452
  return result.result;
2413
2453
  }
2414
2454
  var workSet = new Set(selectionSet.selections);
2415
2455
  workSet.forEach(function (selection) {
2416
- var _a;
2456
+ var _a, _b;
2417
2457
  if (!shouldInclude(selection, variables))
2418
2458
  return;
2419
2459
  if (isField(selection)) {
@@ -2424,12 +2464,13 @@ var StoreReader = (function () {
2424
2464
  from: objectOrReference,
2425
2465
  }, context);
2426
2466
  var resultName = resultKeyNameFromField(selection);
2427
- context.path.push(resultName);
2428
2467
  if (fieldValue === void 0) {
2429
2468
  if (!addTypenameToDocument.added(selection)) {
2430
- getMissing().push(missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
2431
- ? objectOrReference.__ref + " object"
2432
- : "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(6), context));
2469
+ missing = context.merge(missing, (_a = {},
2470
+ _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(isReference(objectOrReference)
2471
+ ? objectOrReference.__ref + " object"
2472
+ : "object " + JSON.stringify(objectOrReference, null, 2)),
2473
+ _a));
2433
2474
  }
2434
2475
  }
2435
2476
  else if (Array.isArray(fieldValue)) {
@@ -2438,7 +2479,7 @@ var StoreReader = (function () {
2438
2479
  array: fieldValue,
2439
2480
  enclosingRef: enclosingRef,
2440
2481
  context: context,
2441
- }));
2482
+ }), resultName);
2442
2483
  }
2443
2484
  else if (!selection.selectionSet) {
2444
2485
  if (context.canonizeResults) {
@@ -2451,12 +2492,11 @@ var StoreReader = (function () {
2451
2492
  objectOrReference: fieldValue,
2452
2493
  enclosingRef: isReference(fieldValue) ? fieldValue : enclosingRef,
2453
2494
  context: context,
2454
- }));
2495
+ }), resultName);
2455
2496
  }
2456
2497
  if (fieldValue !== void 0) {
2457
- objectsToMerge.push((_a = {}, _a[resultName] = fieldValue, _a));
2498
+ result = context.merge(result, (_b = {}, _b[resultName] = fieldValue, _b));
2458
2499
  }
2459
- tsInvariant.invariant(context.path.pop() === resultName);
2460
2500
  }
2461
2501
  else {
2462
2502
  var fragment = getFragmentFromSelection(selection, context.fragmentMap);
@@ -2465,23 +2505,24 @@ var StoreReader = (function () {
2465
2505
  }
2466
2506
  }
2467
2507
  });
2468
- var merged = mergeDeepArray(objectsToMerge);
2469
- finalResult.result = context.canonizeResults
2470
- ? this.canon.admit(merged)
2471
- : maybeDeepFreeze(merged);
2472
- this.knownResults.set(finalResult.result, selectionSet);
2473
- return finalResult;
2508
+ var finalResult = { result: result, missing: missing };
2509
+ var frozen = context.canonizeResults
2510
+ ? this.canon.admit(finalResult)
2511
+ : maybeDeepFreeze(finalResult);
2512
+ if (frozen.result) {
2513
+ this.knownResults.set(frozen.result, selectionSet);
2514
+ }
2515
+ return frozen;
2474
2516
  };
2475
2517
  StoreReader.prototype.execSubSelectedArrayImpl = function (_a) {
2476
2518
  var _this = this;
2477
2519
  var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
2478
2520
  var missing;
2479
2521
  function handleMissing(childResult, i) {
2522
+ var _a;
2480
2523
  if (childResult.missing) {
2481
- missing = missing || [];
2482
- missing.push.apply(missing, childResult.missing);
2524
+ missing = context.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
2483
2525
  }
2484
- tsInvariant.invariant(context.path.pop() === i);
2485
2526
  return childResult.result;
2486
2527
  }
2487
2528
  if (field.selectionSet) {
@@ -2491,7 +2532,6 @@ var StoreReader = (function () {
2491
2532
  if (item === null) {
2492
2533
  return null;
2493
2534
  }
2494
- context.path.push(i);
2495
2535
  if (Array.isArray(item)) {
2496
2536
  return handleMissing(_this.executeSubSelectedArray({
2497
2537
  field: field,
@@ -2511,7 +2551,6 @@ var StoreReader = (function () {
2511
2551
  if (__DEV__) {
2512
2552
  assertSelectionSetForIdValue(context.store, field, item);
2513
2553
  }
2514
- tsInvariant.invariant(context.path.pop() === i);
2515
2554
  return item;
2516
2555
  });
2517
2556
  return {
@@ -2521,401 +2560,206 @@ var StoreReader = (function () {
2521
2560
  };
2522
2561
  return StoreReader;
2523
2562
  }());
2563
+ function firstMissing(tree) {
2564
+ try {
2565
+ JSON.stringify(tree, function (_, value) {
2566
+ if (typeof value === "string")
2567
+ throw value;
2568
+ return value;
2569
+ });
2570
+ }
2571
+ catch (result) {
2572
+ return result;
2573
+ }
2574
+ }
2524
2575
  function assertSelectionSetForIdValue(store, field, fieldValue) {
2525
2576
  if (!field.selectionSet) {
2526
2577
  var workSet_1 = new Set([fieldValue]);
2527
2578
  workSet_1.forEach(function (value) {
2528
2579
  if (isNonNullObject(value)) {
2529
- __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!isReference(value), 7);
2580
+ __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : tsInvariant.invariant(!isReference(value), 5);
2530
2581
  Object.values(value).forEach(workSet_1.add, workSet_1);
2531
2582
  }
2532
2583
  });
2533
2584
  }
2534
2585
  }
2535
2586
 
2536
- var StoreWriter = (function () {
2537
- function StoreWriter(cache, reader) {
2538
- this.cache = cache;
2539
- this.reader = reader;
2540
- }
2541
- StoreWriter.prototype.writeToStore = function (store, _a) {
2542
- var _this = this;
2543
- var query = _a.query, result = _a.result, dataId = _a.dataId, variables = _a.variables, overwrite = _a.overwrite;
2544
- var operationDefinition = getOperationDefinition(query);
2545
- var merger = makeProcessedFieldsMerger();
2546
- variables = tslib.__assign(tslib.__assign({}, getDefaultValues(operationDefinition)), variables);
2547
- var context = {
2548
- store: store,
2549
- written: Object.create(null),
2550
- merge: function (existing, incoming) {
2551
- return merger.merge(existing, incoming);
2552
- },
2553
- variables: variables,
2554
- varString: canonicalStringify(variables),
2555
- fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
2556
- overwrite: !!overwrite,
2557
- incomingById: new Map,
2558
- clientOnly: false,
2559
- };
2560
- var ref = this.processSelectionSet({
2561
- result: result || Object.create(null),
2562
- dataId: dataId,
2563
- selectionSet: operationDefinition.selectionSet,
2564
- mergeTree: { map: new Map },
2565
- context: context,
2587
+ var cacheSlot = new context.Slot();
2588
+ var cacheInfoMap = new WeakMap();
2589
+ function getCacheInfo(cache) {
2590
+ var info = cacheInfoMap.get(cache);
2591
+ if (!info) {
2592
+ cacheInfoMap.set(cache, info = {
2593
+ vars: new Set,
2594
+ dep: optimism.dep(),
2566
2595
  });
2567
- if (!isReference(ref)) {
2568
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(8);
2569
- }
2570
- context.incomingById.forEach(function (_a, dataId) {
2571
- var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
2572
- var entityRef = makeReference(dataId);
2573
- if (mergeTree && mergeTree.map.size) {
2574
- var applied = _this.applyMerges(mergeTree, entityRef, fields, context);
2575
- if (isReference(applied)) {
2576
- return;
2577
- }
2578
- fields = applied;
2579
- }
2580
- if (__DEV__ && !context.overwrite) {
2581
- var hasSelectionSet_1 = function (storeFieldName) {
2582
- return fieldsWithSelectionSets_1.has(fieldNameFromStoreName(storeFieldName));
2583
- };
2584
- var fieldsWithSelectionSets_1 = new Set();
2585
- selections.forEach(function (selection) {
2586
- if (isField(selection) && selection.selectionSet) {
2587
- fieldsWithSelectionSets_1.add(selection.name.value);
2588
- }
2589
- });
2590
- var hasMergeFunction_1 = function (storeFieldName) {
2591
- var childTree = mergeTree && mergeTree.map.get(storeFieldName);
2592
- return Boolean(childTree && childTree.info && childTree.info.merge);
2593
- };
2594
- Object.keys(fields).forEach(function (storeFieldName) {
2595
- if (hasSelectionSet_1(storeFieldName) &&
2596
- !hasMergeFunction_1(storeFieldName)) {
2597
- warnAboutDataLoss(entityRef, fields, storeFieldName, context.store);
2598
- }
2596
+ }
2597
+ return info;
2598
+ }
2599
+ function forgetCache(cache) {
2600
+ getCacheInfo(cache).vars.forEach(function (rv) { return rv.forgetCache(cache); });
2601
+ }
2602
+ function recallCache(cache) {
2603
+ getCacheInfo(cache).vars.forEach(function (rv) { return rv.attachCache(cache); });
2604
+ }
2605
+ function makeVar(value) {
2606
+ var caches = new Set();
2607
+ var listeners = new Set();
2608
+ var rv = function (newValue) {
2609
+ if (arguments.length > 0) {
2610
+ if (value !== newValue) {
2611
+ value = newValue;
2612
+ caches.forEach(function (cache) {
2613
+ getCacheInfo(cache).dep.dirty(rv);
2614
+ broadcast(cache);
2599
2615
  });
2600
- }
2601
- store.merge(dataId, fields);
2602
- });
2603
- store.retain(ref.__ref);
2604
- return ref;
2605
- };
2606
- StoreWriter.prototype.processSelectionSet = function (_a) {
2607
- var _this = this;
2608
- var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
2609
- var policies = this.cache.policies;
2610
- var _b = policies.identify(result, selectionSet, context.fragmentMap), id = _b[0], keyObject = _b[1];
2611
- dataId = dataId || id;
2612
- if ("string" === typeof dataId) {
2613
- var sets = context.written[dataId] || (context.written[dataId] = []);
2614
- var ref = makeReference(dataId);
2615
- if (sets.indexOf(selectionSet) >= 0)
2616
- return ref;
2617
- sets.push(selectionSet);
2618
- if (this.reader && this.reader.isFresh(result, ref, selectionSet, context)) {
2619
- return ref;
2616
+ var oldListeners = Array.from(listeners);
2617
+ listeners.clear();
2618
+ oldListeners.forEach(function (listener) { return listener(value); });
2620
2619
  }
2621
2620
  }
2622
- var incomingFields = Object.create(null);
2623
- if (keyObject) {
2624
- incomingFields = context.merge(incomingFields, keyObject);
2625
- }
2626
- var typename = (dataId && policies.rootTypenamesById[dataId]) ||
2627
- getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
2628
- (dataId && context.store.get(dataId, "__typename"));
2629
- if ("string" === typeof typename) {
2630
- incomingFields.__typename = typename;
2621
+ else {
2622
+ var cache = cacheSlot.getValue();
2623
+ if (cache) {
2624
+ attach(cache);
2625
+ getCacheInfo(cache).dep(rv);
2626
+ }
2631
2627
  }
2632
- var selections = new Set(selectionSet.selections);
2633
- selections.forEach(function (selection) {
2634
- var _a;
2635
- if (!shouldInclude(selection, context.variables))
2636
- return;
2637
- if (isField(selection)) {
2638
- var resultFieldKey = resultKeyNameFromField(selection);
2639
- var value = result[resultFieldKey];
2640
- var wasClientOnly = context.clientOnly;
2641
- context.clientOnly = wasClientOnly || !!(selection.directives &&
2642
- selection.directives.some(function (d) { return d.name.value === "client"; }));
2643
- if (value !== void 0) {
2644
- var storeFieldName = policies.getStoreFieldName({
2645
- typename: typename,
2646
- fieldName: selection.name.value,
2647
- field: selection,
2648
- variables: context.variables,
2649
- });
2650
- var childTree = getChildMergeTree(mergeTree, storeFieldName);
2651
- var incomingValue = _this.processFieldValue(value, selection, context, childTree);
2652
- var childTypename = void 0;
2653
- if (selection.selectionSet) {
2654
- childTypename = context.store.getFieldValue(incomingValue, "__typename");
2655
- if (!childTypename && isReference(incomingValue)) {
2656
- var info = context.incomingById.get(incomingValue.__ref);
2657
- childTypename = info && info.fields.__typename;
2658
- }
2659
- }
2660
- var merge = policies.getMergeFunction(typename, selection.name.value, childTypename);
2661
- if (merge) {
2662
- childTree.info = {
2663
- field: selection,
2664
- typename: typename,
2665
- merge: merge,
2666
- };
2667
- }
2668
- else {
2669
- maybeRecycleChildMergeTree(mergeTree, storeFieldName);
2670
- }
2671
- incomingFields = context.merge(incomingFields, (_a = {},
2672
- _a[storeFieldName] = incomingValue,
2673
- _a));
2674
- }
2675
- else if (!context.clientOnly &&
2676
- !addTypenameToDocument.added(selection)) {
2677
- __DEV__ && tsInvariant.invariant.error(("Missing field '" + resultKeyNameFromField(selection) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
2628
+ return value;
2629
+ };
2630
+ rv.onNextChange = function (listener) {
2631
+ listeners.add(listener);
2632
+ return function () {
2633
+ listeners.delete(listener);
2634
+ };
2635
+ };
2636
+ var attach = rv.attachCache = function (cache) {
2637
+ caches.add(cache);
2638
+ getCacheInfo(cache).vars.add(rv);
2639
+ return rv;
2640
+ };
2641
+ rv.forgetCache = function (cache) { return caches.delete(cache); };
2642
+ return rv;
2643
+ }
2644
+ function broadcast(cache) {
2645
+ if (cache.broadcastWatches) {
2646
+ cache.broadcastWatches();
2647
+ }
2648
+ }
2649
+
2650
+ var specifierInfoCache = Object.create(null);
2651
+ function lookupSpecifierInfo(spec) {
2652
+ var cacheKey = JSON.stringify(spec);
2653
+ return specifierInfoCache[cacheKey] ||
2654
+ (specifierInfoCache[cacheKey] = Object.create(null));
2655
+ }
2656
+ function keyFieldsFnFromSpecifier(specifier) {
2657
+ var info = lookupSpecifierInfo(specifier);
2658
+ return info.keyFieldsFn || (info.keyFieldsFn = function (object, context) {
2659
+ var extract = function (from, key) { return context.readField(key, from); };
2660
+ var keyObject = context.keyObject = collectSpecifierPaths(specifier, function (schemaKeyPath) {
2661
+ var extracted = extractKeyPath(context.storeObject, schemaKeyPath, extract);
2662
+ if (extracted === void 0 &&
2663
+ object !== context.storeObject &&
2664
+ hasOwn.call(object, schemaKeyPath[0])) {
2665
+ extracted = extractKeyPath(object, schemaKeyPath, extractKey);
2666
+ }
2667
+ __DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '".concat(schemaKeyPath.join('.'), "' while extracting keyFields from ").concat(JSON.stringify(object))) : tsInvariant.invariant(extracted !== void 0, 2);
2668
+ return extracted;
2669
+ });
2670
+ return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
2671
+ });
2672
+ }
2673
+ function keyArgsFnFromSpecifier(specifier) {
2674
+ var info = lookupSpecifierInfo(specifier);
2675
+ return info.keyArgsFn || (info.keyArgsFn = function (args, _a) {
2676
+ var field = _a.field, variables = _a.variables, fieldName = _a.fieldName;
2677
+ var collected = collectSpecifierPaths(specifier, function (keyPath) {
2678
+ var firstKey = keyPath[0];
2679
+ var firstChar = firstKey.charAt(0);
2680
+ if (firstChar === "@") {
2681
+ if (field && isNonEmptyArray(field.directives)) {
2682
+ var directiveName_1 = firstKey.slice(1);
2683
+ var d = field.directives.find(function (d) { return d.name.value === directiveName_1; });
2684
+ var directiveArgs = d && argumentsObjectFromField(d, variables);
2685
+ return directiveArgs && extractKeyPath(directiveArgs, keyPath.slice(1));
2678
2686
  }
2679
- context.clientOnly = wasClientOnly;
2687
+ return;
2680
2688
  }
2681
- else {
2682
- var fragment = getFragmentFromSelection(selection, context.fragmentMap);
2683
- if (fragment &&
2684
- policies.fragmentMatches(fragment, typename, result, context.variables)) {
2685
- fragment.selectionSet.selections.forEach(selections.add, selections);
2689
+ if (firstChar === "$") {
2690
+ var variableName = firstKey.slice(1);
2691
+ if (variables && hasOwn.call(variables, variableName)) {
2692
+ var varKeyPath = keyPath.slice(0);
2693
+ varKeyPath[0] = variableName;
2694
+ return extractKeyPath(variables, varKeyPath);
2686
2695
  }
2696
+ return;
2697
+ }
2698
+ if (args) {
2699
+ return extractKeyPath(args, keyPath);
2687
2700
  }
2688
2701
  });
2689
- if ("string" === typeof dataId) {
2690
- var previous = context.incomingById.get(dataId);
2691
- if (previous) {
2692
- previous.fields = context.merge(previous.fields, incomingFields);
2693
- previous.mergeTree = mergeMergeTrees(previous.mergeTree, mergeTree);
2694
- previous.selections.forEach(selections.add, selections);
2695
- previous.selections = selections;
2702
+ var suffix = JSON.stringify(collected);
2703
+ if (args || suffix !== "{}") {
2704
+ fieldName += ":" + suffix;
2705
+ }
2706
+ return fieldName;
2707
+ });
2708
+ }
2709
+ function collectSpecifierPaths(specifier, extractor) {
2710
+ var merger = new DeepMerger;
2711
+ return getSpecifierPaths(specifier).reduce(function (collected, path) {
2712
+ var _a;
2713
+ var toMerge = extractor(path);
2714
+ if (toMerge !== void 0) {
2715
+ for (var i = path.length - 1; i >= 0; --i) {
2716
+ toMerge = (_a = {}, _a[path[i]] = toMerge, _a);
2717
+ }
2718
+ collected = merger.merge(collected, toMerge);
2719
+ }
2720
+ return collected;
2721
+ }, Object.create(null));
2722
+ }
2723
+ function getSpecifierPaths(spec) {
2724
+ var info = lookupSpecifierInfo(spec);
2725
+ if (!info.paths) {
2726
+ var paths_1 = info.paths = [];
2727
+ var currentPath_1 = [];
2728
+ spec.forEach(function (s, i) {
2729
+ if (Array.isArray(s)) {
2730
+ getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
2731
+ currentPath_1.length = 0;
2696
2732
  }
2697
2733
  else {
2698
- context.incomingById.set(dataId, {
2699
- fields: incomingFields,
2700
- mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
2701
- selections: selections,
2702
- });
2734
+ currentPath_1.push(s);
2735
+ if (!Array.isArray(spec[i + 1])) {
2736
+ paths_1.push(currentPath_1.slice(0));
2737
+ currentPath_1.length = 0;
2738
+ }
2703
2739
  }
2704
- return makeReference(dataId);
2705
- }
2706
- return incomingFields;
2707
- };
2708
- StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
2709
- var _this = this;
2710
- if (!field.selectionSet || value === null) {
2711
- return __DEV__ ? cloneDeep(value) : value;
2712
- }
2740
+ });
2741
+ }
2742
+ return info.paths;
2743
+ }
2744
+ function extractKey(object, key) {
2745
+ return object[key];
2746
+ }
2747
+ function extractKeyPath(object, path, extract) {
2748
+ extract = extract || extractKey;
2749
+ return normalize(path.reduce(function reducer(obj, key) {
2750
+ return Array.isArray(obj)
2751
+ ? obj.map(function (child) { return reducer(child, key); })
2752
+ : obj && extract(obj, key);
2753
+ }, object));
2754
+ }
2755
+ function normalize(value) {
2756
+ if (isNonNullObject(value)) {
2713
2757
  if (Array.isArray(value)) {
2714
- return value.map(function (item, i) {
2715
- var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
2716
- maybeRecycleChildMergeTree(mergeTree, i);
2717
- return value;
2718
- });
2758
+ return value.map(normalize);
2719
2759
  }
2720
- return this.processSelectionSet({
2721
- result: value,
2722
- selectionSet: field.selectionSet,
2723
- context: context,
2724
- mergeTree: mergeTree,
2725
- });
2726
- };
2727
- StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
2728
- var _a;
2729
- var _this = this;
2730
- if (mergeTree.map.size && !isReference(incoming)) {
2731
- var e_1 = (!Array.isArray(incoming) &&
2732
- (isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
2733
- var i_1 = incoming;
2734
- if (e_1 && !getStorageArgs) {
2735
- getStorageArgs = [isReference(e_1) ? e_1.__ref : e_1];
2736
- }
2737
- var changedFields_1;
2738
- var getValue_1 = function (from, name) {
2739
- return Array.isArray(from)
2740
- ? (typeof name === "number" ? from[name] : void 0)
2741
- : context.store.getFieldValue(from, String(name));
2742
- };
2743
- mergeTree.map.forEach(function (childTree, storeFieldName) {
2744
- var eVal = getValue_1(e_1, storeFieldName);
2745
- var iVal = getValue_1(i_1, storeFieldName);
2746
- if (void 0 === iVal)
2747
- return;
2748
- if (getStorageArgs) {
2749
- getStorageArgs.push(storeFieldName);
2750
- }
2751
- var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
2752
- if (aVal !== iVal) {
2753
- changedFields_1 = changedFields_1 || new Map;
2754
- changedFields_1.set(storeFieldName, aVal);
2755
- }
2756
- if (getStorageArgs) {
2757
- tsInvariant.invariant(getStorageArgs.pop() === storeFieldName);
2758
- }
2759
- });
2760
- if (changedFields_1) {
2761
- incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
2762
- changedFields_1.forEach(function (value, name) {
2763
- incoming[name] = value;
2764
- });
2765
- }
2766
- }
2767
- if (mergeTree.info) {
2768
- return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
2769
- }
2770
- return incoming;
2771
- };
2772
- return StoreWriter;
2773
- }());
2774
- var emptyMergeTreePool = [];
2775
- function getChildMergeTree(_a, name) {
2776
- var map = _a.map;
2777
- if (!map.has(name)) {
2778
- map.set(name, emptyMergeTreePool.pop() || { map: new Map });
2779
- }
2780
- return map.get(name);
2781
- }
2782
- function mergeMergeTrees(left, right) {
2783
- if (left === right || !right || mergeTreeIsEmpty(right))
2784
- return left;
2785
- if (!left || mergeTreeIsEmpty(left))
2786
- return right;
2787
- var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
2788
- var needToMergeMaps = left.map.size && right.map.size;
2789
- var map = needToMergeMaps ? new Map :
2790
- left.map.size ? left.map : right.map;
2791
- var merged = { info: info, map: map };
2792
- if (needToMergeMaps) {
2793
- var remainingRightKeys_1 = new Set(right.map.keys());
2794
- left.map.forEach(function (leftTree, key) {
2795
- merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
2796
- remainingRightKeys_1.delete(key);
2797
- });
2798
- remainingRightKeys_1.forEach(function (key) {
2799
- merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
2800
- });
2801
- }
2802
- return merged;
2803
- }
2804
- function mergeTreeIsEmpty(tree) {
2805
- return !tree || !(tree.info || tree.map.size);
2806
- }
2807
- function maybeRecycleChildMergeTree(_a, name) {
2808
- var map = _a.map;
2809
- var childTree = map.get(name);
2810
- if (childTree && mergeTreeIsEmpty(childTree)) {
2811
- emptyMergeTreePool.push(childTree);
2812
- map.delete(name);
2813
- }
2814
- }
2815
- var warnings = new Set();
2816
- function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
2817
- var getChild = function (objOrRef) {
2818
- var child = store.getFieldValue(objOrRef, storeFieldName);
2819
- return typeof child === "object" && child;
2820
- };
2821
- var existing = getChild(existingRef);
2822
- if (!existing)
2823
- return;
2824
- var incoming = getChild(incomingObj);
2825
- if (!incoming)
2826
- return;
2827
- if (isReference(existing))
2828
- return;
2829
- if (equality.equal(existing, incoming))
2830
- return;
2831
- if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
2832
- return;
2833
- }
2834
- var parentType = store.getFieldValue(existingRef, "__typename") ||
2835
- store.getFieldValue(incomingObj, "__typename");
2836
- var fieldName = fieldNameFromStoreName(storeFieldName);
2837
- var typeDotName = parentType + "." + fieldName;
2838
- if (warnings.has(typeDotName))
2839
- return;
2840
- warnings.add(typeDotName);
2841
- var childTypenames = [];
2842
- if (!Array.isArray(existing) &&
2843
- !Array.isArray(incoming)) {
2844
- [existing, incoming].forEach(function (child) {
2845
- var typename = store.getFieldValue(child, "__typename");
2846
- if (typeof typename === "string" &&
2847
- !childTypenames.includes(typename)) {
2848
- childTypenames.push(typename);
2849
- }
2850
- });
2851
- }
2852
- __DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the " + fieldName + " field of a " + parentType + " object.\n\nTo address this problem (which is not a bug in Apollo Client), " + (childTypenames.length
2853
- ? "either ensure all objects of type " +
2854
- childTypenames.join(" and ") + " have an ID or a custom merge function, or "
2855
- : "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
2856
- }
2857
-
2858
- var cacheSlot = new context.Slot();
2859
- var cacheInfoMap = new WeakMap();
2860
- function getCacheInfo(cache) {
2861
- var info = cacheInfoMap.get(cache);
2862
- if (!info) {
2863
- cacheInfoMap.set(cache, info = {
2864
- vars: new Set,
2865
- dep: optimism.dep(),
2866
- });
2867
- }
2868
- return info;
2869
- }
2870
- function forgetCache(cache) {
2871
- getCacheInfo(cache).vars.forEach(function (rv) { return rv.forgetCache(cache); });
2872
- }
2873
- function recallCache(cache) {
2874
- getCacheInfo(cache).vars.forEach(function (rv) { return rv.attachCache(cache); });
2875
- }
2876
- function makeVar(value) {
2877
- var caches = new Set();
2878
- var listeners = new Set();
2879
- var rv = function (newValue) {
2880
- if (arguments.length > 0) {
2881
- if (value !== newValue) {
2882
- value = newValue;
2883
- caches.forEach(function (cache) {
2884
- getCacheInfo(cache).dep.dirty(rv);
2885
- broadcast(cache);
2886
- });
2887
- var oldListeners = Array.from(listeners);
2888
- listeners.clear();
2889
- oldListeners.forEach(function (listener) { return listener(value); });
2890
- }
2891
- }
2892
- else {
2893
- var cache = cacheSlot.getValue();
2894
- if (cache) {
2895
- attach(cache);
2896
- getCacheInfo(cache).dep(rv);
2897
- }
2898
- }
2899
- return value;
2900
- };
2901
- rv.onNextChange = function (listener) {
2902
- listeners.add(listener);
2903
- return function () {
2904
- listeners.delete(listener);
2905
- };
2906
- };
2907
- var attach = rv.attachCache = function (cache) {
2908
- caches.add(cache);
2909
- getCacheInfo(cache).vars.add(rv);
2910
- return rv;
2911
- };
2912
- rv.forgetCache = function (cache) { return caches.delete(cache); };
2913
- return rv;
2914
- }
2915
- function broadcast(cache) {
2916
- if (cache.broadcastWatches) {
2917
- cache.broadcastWatches();
2760
+ return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
2918
2761
  }
2762
+ return value;
2919
2763
  }
2920
2764
 
2921
2765
  getStoreKeyName.setStringify(canonicalStringify);
@@ -2952,18 +2796,22 @@ var Policies = (function () {
2952
2796
  this.addTypePolicies(config.typePolicies);
2953
2797
  }
2954
2798
  }
2955
- Policies.prototype.identify = function (object, selectionSet, fragmentMap) {
2956
- var typename = selectionSet && fragmentMap
2957
- ? getTypenameFromResult(object, selectionSet, fragmentMap)
2958
- : object.__typename;
2799
+ Policies.prototype.identify = function (object, partialContext) {
2800
+ var _a;
2801
+ var policies = this;
2802
+ var typename = partialContext && (partialContext.typename ||
2803
+ ((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename)) || object.__typename;
2959
2804
  if (typename === this.rootTypenamesById.ROOT_QUERY) {
2960
2805
  return ["ROOT_QUERY"];
2961
2806
  }
2962
- var context = {
2963
- typename: typename,
2964
- selectionSet: selectionSet,
2965
- fragmentMap: fragmentMap,
2966
- };
2807
+ var storeObject = partialContext && partialContext.storeObject || object;
2808
+ var context = tslib.__assign(tslib.__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: partialContext && partialContext.readField || function () {
2809
+ var options = normalizeReadFieldOptions(arguments, storeObject);
2810
+ return policies.readField(options, {
2811
+ store: policies.cache["data"],
2812
+ variables: options.variables,
2813
+ });
2814
+ } });
2967
2815
  var id;
2968
2816
  var policy = typename && this.getTypePolicy(typename);
2969
2817
  var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
@@ -3045,7 +2893,7 @@ var Policies = (function () {
3045
2893
  var rootId = "ROOT_" + which.toUpperCase();
3046
2894
  var old = this.rootTypenamesById[rootId];
3047
2895
  if (typename !== old) {
3048
- __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 2);
2896
+ __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root ".concat(which, " __typename more than once")) : tsInvariant.invariant(!old || old === which, 3);
3049
2897
  if (old)
3050
2898
  delete this.rootIdsByTypename[old];
3051
2899
  this.rootIdsByTypename[typename] = rootId;
@@ -3129,7 +2977,7 @@ var Policies = (function () {
3129
2977
  if (supertypeSet.has(supertype)) {
3130
2978
  if (!typenameSupertypeSet.has(supertype)) {
3131
2979
  if (checkingFuzzySubtypes) {
3132
- __DEV__ && tsInvariant.invariant.warn("Inferring subtype " + typename + " of supertype " + supertype);
2980
+ __DEV__ && tsInvariant.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
3133
2981
  }
3134
2982
  typenameSupertypeSet.add(supertype);
3135
2983
  }
@@ -3217,6 +3065,10 @@ var Policies = (function () {
3217
3065
  }
3218
3066
  return existing;
3219
3067
  };
3068
+ Policies.prototype.getReadFunction = function (typename, fieldName) {
3069
+ var policy = this.getFieldPolicy(typename, fieldName, false);
3070
+ return policy && policy.read;
3071
+ };
3220
3072
  Policies.prototype.getMergeFunction = function (parentTypename, fieldName, childTypename) {
3221
3073
  var policy = this.getFieldPolicy(parentTypename, fieldName, false);
3222
3074
  var merge = policy && policy.merge;
@@ -3257,39 +3109,39 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
3257
3109
  storage: storage,
3258
3110
  cache: policies.cache,
3259
3111
  canRead: canRead,
3260
- readField: function (fieldNameOrOptions, from) {
3261
- var options;
3262
- if (typeof fieldNameOrOptions === "string") {
3263
- options = {
3264
- fieldName: fieldNameOrOptions,
3265
- from: arguments.length > 1 ? from : objectOrReference,
3266
- };
3267
- }
3268
- else if (isNonNullObject(fieldNameOrOptions)) {
3269
- options = tslib.__assign({}, fieldNameOrOptions);
3270
- if (!hasOwn.call(fieldNameOrOptions, "from")) {
3271
- options.from = objectOrReference;
3272
- }
3273
- }
3274
- else {
3275
- __DEV__ && tsInvariant.invariant.warn("Unexpected readField arguments: " + stringifyForDisplay(Array.from(arguments)));
3276
- return;
3277
- }
3278
- if (__DEV__ && options.from === void 0) {
3279
- __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + stringifyForDisplay(Array.from(arguments)));
3280
- }
3281
- if (void 0 === options.variables) {
3282
- options.variables = variables;
3283
- }
3284
- return policies.readField(options, context);
3112
+ readField: function () {
3113
+ return policies.readField(normalizeReadFieldOptions(arguments, objectOrReference, context), context);
3285
3114
  },
3286
3115
  mergeObjects: makeMergeObjectsFunction(context.store),
3287
3116
  };
3288
3117
  }
3118
+ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables) {
3119
+ var fieldNameOrOptions = readFieldArgs[0], from = readFieldArgs[1], argc = readFieldArgs.length;
3120
+ var options;
3121
+ if (typeof fieldNameOrOptions === "string") {
3122
+ options = {
3123
+ fieldName: fieldNameOrOptions,
3124
+ from: argc > 1 ? from : objectOrReference,
3125
+ };
3126
+ }
3127
+ else {
3128
+ options = tslib.__assign({}, fieldNameOrOptions);
3129
+ if (!hasOwn.call(options, "from")) {
3130
+ options.from = objectOrReference;
3131
+ }
3132
+ }
3133
+ if (__DEV__ && options.from === void 0) {
3134
+ __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments ".concat(stringifyForDisplay(Array.from(readFieldArgs))));
3135
+ }
3136
+ if (void 0 === options.variables) {
3137
+ options.variables = variables;
3138
+ }
3139
+ return options;
3140
+ }
3289
3141
  function makeMergeObjectsFunction(store) {
3290
3142
  return function mergeObjects(existing, incoming) {
3291
3143
  if (Array.isArray(existing) || Array.isArray(incoming)) {
3292
- throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(3);
3144
+ throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
3293
3145
  }
3294
3146
  if (isNonNullObject(existing) &&
3295
3147
  isNonNullObject(incoming)) {
@@ -3317,84 +3169,396 @@ function makeMergeObjectsFunction(store) {
3317
3169
  return incoming;
3318
3170
  };
3319
3171
  }
3320
- function keyArgsFnFromSpecifier(specifier) {
3321
- return function (args, context) {
3322
- return args ? context.fieldName + ":" + JSON.stringify(computeKeyObject(args, specifier, false)) : context.fieldName;
3323
- };
3172
+
3173
+ function getContextFlavor(context, clientOnly, deferred) {
3174
+ var key = "".concat(clientOnly).concat(deferred);
3175
+ var flavored = context.flavors.get(key);
3176
+ if (!flavored) {
3177
+ context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
3178
+ context.deferred === deferred) ? context : tslib.__assign(tslib.__assign({}, context), { clientOnly: clientOnly, deferred: deferred }));
3179
+ }
3180
+ return flavored;
3324
3181
  }
3325
- function keyFieldsFnFromSpecifier(specifier) {
3326
- var trie$1 = new trie.Trie(canUseWeakMap);
3327
- return function (object, context) {
3328
- var aliasMap;
3329
- if (context.selectionSet && context.fragmentMap) {
3330
- var info = trie$1.lookupArray([
3331
- context.selectionSet,
3332
- context.fragmentMap,
3333
- ]);
3334
- aliasMap = info.aliasMap || (info.aliasMap = makeAliasMap(context.selectionSet, context.fragmentMap));
3182
+ var StoreWriter = (function () {
3183
+ function StoreWriter(cache, reader) {
3184
+ this.cache = cache;
3185
+ this.reader = reader;
3186
+ }
3187
+ StoreWriter.prototype.writeToStore = function (store, _a) {
3188
+ var _this = this;
3189
+ var query = _a.query, result = _a.result, dataId = _a.dataId, variables = _a.variables, overwrite = _a.overwrite;
3190
+ var operationDefinition = getOperationDefinition(query);
3191
+ var merger = makeProcessedFieldsMerger();
3192
+ variables = tslib.__assign(tslib.__assign({}, getDefaultValues(operationDefinition)), variables);
3193
+ var context = {
3194
+ store: store,
3195
+ written: Object.create(null),
3196
+ merge: function (existing, incoming) {
3197
+ return merger.merge(existing, incoming);
3198
+ },
3199
+ variables: variables,
3200
+ varString: canonicalStringify(variables),
3201
+ fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
3202
+ overwrite: !!overwrite,
3203
+ incomingById: new Map,
3204
+ clientOnly: false,
3205
+ deferred: false,
3206
+ flavors: new Map,
3207
+ };
3208
+ var ref = this.processSelectionSet({
3209
+ result: result || Object.create(null),
3210
+ dataId: dataId,
3211
+ selectionSet: operationDefinition.selectionSet,
3212
+ mergeTree: { map: new Map },
3213
+ context: context,
3214
+ });
3215
+ if (!isReference(ref)) {
3216
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new tsInvariant.InvariantError(6);
3335
3217
  }
3336
- var keyObject = context.keyObject =
3337
- computeKeyObject(object, specifier, true, aliasMap);
3338
- return context.typename + ":" + JSON.stringify(keyObject);
3218
+ context.incomingById.forEach(function (_a, dataId) {
3219
+ var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
3220
+ var entityRef = makeReference(dataId);
3221
+ if (mergeTree && mergeTree.map.size) {
3222
+ var applied = _this.applyMerges(mergeTree, entityRef, storeObject, context);
3223
+ if (isReference(applied)) {
3224
+ return;
3225
+ }
3226
+ storeObject = applied;
3227
+ }
3228
+ if (__DEV__ && !context.overwrite) {
3229
+ var fieldsWithSelectionSets_1 = Object.create(null);
3230
+ fieldNodeSet.forEach(function (field) {
3231
+ if (field.selectionSet) {
3232
+ fieldsWithSelectionSets_1[field.name.value] = true;
3233
+ }
3234
+ });
3235
+ var hasSelectionSet_1 = function (storeFieldName) {
3236
+ return fieldsWithSelectionSets_1[fieldNameFromStoreName(storeFieldName)] === true;
3237
+ };
3238
+ var hasMergeFunction_1 = function (storeFieldName) {
3239
+ var childTree = mergeTree && mergeTree.map.get(storeFieldName);
3240
+ return Boolean(childTree && childTree.info && childTree.info.merge);
3241
+ };
3242
+ Object.keys(storeObject).forEach(function (storeFieldName) {
3243
+ if (hasSelectionSet_1(storeFieldName) &&
3244
+ !hasMergeFunction_1(storeFieldName)) {
3245
+ warnAboutDataLoss(entityRef, storeObject, storeFieldName, context.store);
3246
+ }
3247
+ });
3248
+ }
3249
+ store.merge(dataId, storeObject);
3250
+ });
3251
+ store.retain(ref.__ref);
3252
+ return ref;
3339
3253
  };
3340
- }
3341
- function makeAliasMap(selectionSet, fragmentMap) {
3342
- var map = Object.create(null);
3343
- var workQueue = new Set([selectionSet]);
3344
- workQueue.forEach(function (selectionSet) {
3345
- selectionSet.selections.forEach(function (selection) {
3346
- if (isField(selection)) {
3347
- if (selection.alias) {
3348
- var responseKey = selection.alias.value;
3349
- var storeKey = selection.name.value;
3350
- if (storeKey !== responseKey) {
3351
- var aliases = map.aliases || (map.aliases = Object.create(null));
3352
- aliases[storeKey] = responseKey;
3254
+ StoreWriter.prototype.processSelectionSet = function (_a) {
3255
+ var _this = this;
3256
+ var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
3257
+ var policies = this.cache.policies;
3258
+ var incoming = Object.create(null);
3259
+ var typename = (dataId && policies.rootTypenamesById[dataId]) ||
3260
+ getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
3261
+ (dataId && context.store.get(dataId, "__typename"));
3262
+ if ("string" === typeof typename) {
3263
+ incoming.__typename = typename;
3264
+ }
3265
+ var readField = function () {
3266
+ var options = normalizeReadFieldOptions(arguments, incoming, context.variables);
3267
+ if (isReference(options.from)) {
3268
+ var info = context.incomingById.get(options.from.__ref);
3269
+ if (info) {
3270
+ var result_1 = policies.readField(tslib.__assign(tslib.__assign({}, options), { from: info.storeObject }), context);
3271
+ if (result_1 !== void 0) {
3272
+ return result_1;
3353
3273
  }
3354
3274
  }
3355
- if (selection.selectionSet) {
3356
- var subsets = map.subsets || (map.subsets = Object.create(null));
3357
- subsets[selection.name.value] =
3358
- makeAliasMap(selection.selectionSet, fragmentMap);
3359
- }
3360
3275
  }
3361
- else {
3362
- var fragment = getFragmentFromSelection(selection, fragmentMap);
3363
- if (fragment) {
3364
- workQueue.add(fragment.selectionSet);
3276
+ return policies.readField(options, context);
3277
+ };
3278
+ var fieldNodeSet = new Set();
3279
+ this.flattenFields(selectionSet, result, context, typename).forEach(function (context, field) {
3280
+ var _a;
3281
+ var resultFieldKey = resultKeyNameFromField(field);
3282
+ var value = result[resultFieldKey];
3283
+ fieldNodeSet.add(field);
3284
+ if (value !== void 0) {
3285
+ var storeFieldName = policies.getStoreFieldName({
3286
+ typename: typename,
3287
+ fieldName: field.name.value,
3288
+ field: field,
3289
+ variables: context.variables,
3290
+ });
3291
+ var childTree = getChildMergeTree(mergeTree, storeFieldName);
3292
+ var incomingValue = _this.processFieldValue(value, field, field.selectionSet
3293
+ ? getContextFlavor(context, false, false)
3294
+ : context, childTree);
3295
+ var childTypename = void 0;
3296
+ if (field.selectionSet &&
3297
+ (isReference(incomingValue) ||
3298
+ storeValueIsStoreObject(incomingValue))) {
3299
+ childTypename = readField("__typename", incomingValue);
3365
3300
  }
3301
+ var merge = policies.getMergeFunction(typename, field.name.value, childTypename);
3302
+ if (merge) {
3303
+ childTree.info = {
3304
+ field: field,
3305
+ typename: typename,
3306
+ merge: merge,
3307
+ };
3308
+ }
3309
+ else {
3310
+ maybeRecycleChildMergeTree(mergeTree, storeFieldName);
3311
+ }
3312
+ incoming = context.merge(incoming, (_a = {},
3313
+ _a[storeFieldName] = incomingValue,
3314
+ _a));
3315
+ }
3316
+ else if (__DEV__ &&
3317
+ !context.clientOnly &&
3318
+ !context.deferred &&
3319
+ !addTypenameToDocument.added(field) &&
3320
+ !policies.getReadFunction(typename, field.name.value)) {
3321
+ __DEV__ && tsInvariant.invariant.error("Missing field '".concat(resultKeyNameFromField(field), "' while writing result ").concat(JSON.stringify(result, null, 2)).substring(0, 1000));
3366
3322
  }
3367
3323
  });
3368
- });
3369
- return map;
3370
- }
3371
- function computeKeyObject(response, specifier, strict, aliasMap) {
3372
- var keyObj = Object.create(null);
3373
- var lastResponseKey;
3374
- var lastActualKey;
3375
- specifier.forEach(function (s) {
3376
- if (Array.isArray(s)) {
3377
- if (typeof lastActualKey === "string" &&
3378
- typeof lastResponseKey === "string") {
3379
- var subsets = aliasMap && aliasMap.subsets;
3380
- var subset = subsets && subsets[lastActualKey];
3381
- keyObj[lastActualKey] =
3382
- computeKeyObject(response[lastResponseKey], s, strict, subset);
3324
+ try {
3325
+ var _b = policies.identify(result, {
3326
+ typename: typename,
3327
+ selectionSet: selectionSet,
3328
+ fragmentMap: context.fragmentMap,
3329
+ storeObject: incoming,
3330
+ readField: readField,
3331
+ }), id = _b[0], keyObject = _b[1];
3332
+ dataId = dataId || id;
3333
+ if (keyObject) {
3334
+ incoming = context.merge(incoming, keyObject);
3383
3335
  }
3384
3336
  }
3385
- else {
3386
- var aliases = aliasMap && aliasMap.aliases;
3387
- var responseName = aliases && aliases[s] || s;
3388
- if (hasOwn.call(response, responseName)) {
3389
- keyObj[lastActualKey = s] = response[lastResponseKey = responseName];
3337
+ catch (e) {
3338
+ if (!dataId)
3339
+ throw e;
3340
+ }
3341
+ if ("string" === typeof dataId) {
3342
+ var dataRef = makeReference(dataId);
3343
+ var sets = context.written[dataId] || (context.written[dataId] = []);
3344
+ if (sets.indexOf(selectionSet) >= 0)
3345
+ return dataRef;
3346
+ sets.push(selectionSet);
3347
+ if (this.reader && this.reader.isFresh(result, dataRef, selectionSet, context)) {
3348
+ return dataRef;
3349
+ }
3350
+ var previous_1 = context.incomingById.get(dataId);
3351
+ if (previous_1) {
3352
+ previous_1.storeObject = context.merge(previous_1.storeObject, incoming);
3353
+ previous_1.mergeTree = mergeMergeTrees(previous_1.mergeTree, mergeTree);
3354
+ fieldNodeSet.forEach(function (field) { return previous_1.fieldNodeSet.add(field); });
3390
3355
  }
3391
3356
  else {
3392
- __DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 4);
3393
- lastResponseKey = lastActualKey = void 0;
3357
+ context.incomingById.set(dataId, {
3358
+ storeObject: incoming,
3359
+ mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
3360
+ fieldNodeSet: fieldNodeSet,
3361
+ });
3394
3362
  }
3363
+ return dataRef;
3395
3364
  }
3396
- });
3397
- return keyObj;
3365
+ return incoming;
3366
+ };
3367
+ StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
3368
+ var _this = this;
3369
+ if (!field.selectionSet || value === null) {
3370
+ return __DEV__ ? cloneDeep(value) : value;
3371
+ }
3372
+ if (Array.isArray(value)) {
3373
+ return value.map(function (item, i) {
3374
+ var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
3375
+ maybeRecycleChildMergeTree(mergeTree, i);
3376
+ return value;
3377
+ });
3378
+ }
3379
+ return this.processSelectionSet({
3380
+ result: value,
3381
+ selectionSet: field.selectionSet,
3382
+ context: context,
3383
+ mergeTree: mergeTree,
3384
+ });
3385
+ };
3386
+ StoreWriter.prototype.flattenFields = function (selectionSet, result, context, typename) {
3387
+ if (typename === void 0) { typename = getTypenameFromResult(result, selectionSet, context.fragmentMap); }
3388
+ var fieldMap = new Map();
3389
+ var policies = this.cache.policies;
3390
+ var limitingTrie = new trie.Trie(false);
3391
+ (function flatten(selectionSet, inheritedContext) {
3392
+ var visitedNode = limitingTrie.lookup(selectionSet, inheritedContext.clientOnly, inheritedContext.deferred);
3393
+ if (visitedNode.visited)
3394
+ return;
3395
+ visitedNode.visited = true;
3396
+ selectionSet.selections.forEach(function (selection) {
3397
+ if (!shouldInclude(selection, context.variables))
3398
+ return;
3399
+ var clientOnly = inheritedContext.clientOnly, deferred = inheritedContext.deferred;
3400
+ if (!(clientOnly && deferred) &&
3401
+ isNonEmptyArray(selection.directives)) {
3402
+ selection.directives.forEach(function (dir) {
3403
+ var name = dir.name.value;
3404
+ if (name === "client")
3405
+ clientOnly = true;
3406
+ if (name === "defer") {
3407
+ var args = argumentsObjectFromField(dir, context.variables);
3408
+ if (!args || args.if !== false) {
3409
+ deferred = true;
3410
+ }
3411
+ }
3412
+ });
3413
+ }
3414
+ if (isField(selection)) {
3415
+ var existing = fieldMap.get(selection);
3416
+ if (existing) {
3417
+ clientOnly = clientOnly && existing.clientOnly;
3418
+ deferred = deferred && existing.deferred;
3419
+ }
3420
+ fieldMap.set(selection, getContextFlavor(context, clientOnly, deferred));
3421
+ }
3422
+ else {
3423
+ var fragment = getFragmentFromSelection(selection, context.fragmentMap);
3424
+ if (fragment &&
3425
+ policies.fragmentMatches(fragment, typename, result, context.variables)) {
3426
+ flatten(fragment.selectionSet, getContextFlavor(context, clientOnly, deferred));
3427
+ }
3428
+ }
3429
+ });
3430
+ })(selectionSet, context);
3431
+ return fieldMap;
3432
+ };
3433
+ StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
3434
+ var _a;
3435
+ var _this = this;
3436
+ if (mergeTree.map.size && !isReference(incoming)) {
3437
+ var e_1 = (!Array.isArray(incoming) &&
3438
+ (isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
3439
+ var i_1 = incoming;
3440
+ if (e_1 && !getStorageArgs) {
3441
+ getStorageArgs = [isReference(e_1) ? e_1.__ref : e_1];
3442
+ }
3443
+ var changedFields_1;
3444
+ var getValue_1 = function (from, name) {
3445
+ return Array.isArray(from)
3446
+ ? (typeof name === "number" ? from[name] : void 0)
3447
+ : context.store.getFieldValue(from, String(name));
3448
+ };
3449
+ mergeTree.map.forEach(function (childTree, storeFieldName) {
3450
+ var eVal = getValue_1(e_1, storeFieldName);
3451
+ var iVal = getValue_1(i_1, storeFieldName);
3452
+ if (void 0 === iVal)
3453
+ return;
3454
+ if (getStorageArgs) {
3455
+ getStorageArgs.push(storeFieldName);
3456
+ }
3457
+ var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
3458
+ if (aVal !== iVal) {
3459
+ changedFields_1 = changedFields_1 || new Map;
3460
+ changedFields_1.set(storeFieldName, aVal);
3461
+ }
3462
+ if (getStorageArgs) {
3463
+ tsInvariant.invariant(getStorageArgs.pop() === storeFieldName);
3464
+ }
3465
+ });
3466
+ if (changedFields_1) {
3467
+ incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
3468
+ changedFields_1.forEach(function (value, name) {
3469
+ incoming[name] = value;
3470
+ });
3471
+ }
3472
+ }
3473
+ if (mergeTree.info) {
3474
+ return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
3475
+ }
3476
+ return incoming;
3477
+ };
3478
+ return StoreWriter;
3479
+ }());
3480
+ var emptyMergeTreePool = [];
3481
+ function getChildMergeTree(_a, name) {
3482
+ var map = _a.map;
3483
+ if (!map.has(name)) {
3484
+ map.set(name, emptyMergeTreePool.pop() || { map: new Map });
3485
+ }
3486
+ return map.get(name);
3487
+ }
3488
+ function mergeMergeTrees(left, right) {
3489
+ if (left === right || !right || mergeTreeIsEmpty(right))
3490
+ return left;
3491
+ if (!left || mergeTreeIsEmpty(left))
3492
+ return right;
3493
+ var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
3494
+ var needToMergeMaps = left.map.size && right.map.size;
3495
+ var map = needToMergeMaps ? new Map :
3496
+ left.map.size ? left.map : right.map;
3497
+ var merged = { info: info, map: map };
3498
+ if (needToMergeMaps) {
3499
+ var remainingRightKeys_1 = new Set(right.map.keys());
3500
+ left.map.forEach(function (leftTree, key) {
3501
+ merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
3502
+ remainingRightKeys_1.delete(key);
3503
+ });
3504
+ remainingRightKeys_1.forEach(function (key) {
3505
+ merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
3506
+ });
3507
+ }
3508
+ return merged;
3509
+ }
3510
+ function mergeTreeIsEmpty(tree) {
3511
+ return !tree || !(tree.info || tree.map.size);
3512
+ }
3513
+ function maybeRecycleChildMergeTree(_a, name) {
3514
+ var map = _a.map;
3515
+ var childTree = map.get(name);
3516
+ if (childTree && mergeTreeIsEmpty(childTree)) {
3517
+ emptyMergeTreePool.push(childTree);
3518
+ map.delete(name);
3519
+ }
3520
+ }
3521
+ var warnings = new Set();
3522
+ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3523
+ var getChild = function (objOrRef) {
3524
+ var child = store.getFieldValue(objOrRef, storeFieldName);
3525
+ return typeof child === "object" && child;
3526
+ };
3527
+ var existing = getChild(existingRef);
3528
+ if (!existing)
3529
+ return;
3530
+ var incoming = getChild(incomingObj);
3531
+ if (!incoming)
3532
+ return;
3533
+ if (isReference(existing))
3534
+ return;
3535
+ if (equality.equal(existing, incoming))
3536
+ return;
3537
+ if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
3538
+ return;
3539
+ }
3540
+ var parentType = store.getFieldValue(existingRef, "__typename") ||
3541
+ store.getFieldValue(incomingObj, "__typename");
3542
+ var fieldName = fieldNameFromStoreName(storeFieldName);
3543
+ var typeDotName = "".concat(parentType, ".").concat(fieldName);
3544
+ if (warnings.has(typeDotName))
3545
+ return;
3546
+ warnings.add(typeDotName);
3547
+ var childTypenames = [];
3548
+ if (!Array.isArray(existing) &&
3549
+ !Array.isArray(incoming)) {
3550
+ [existing, incoming].forEach(function (child) {
3551
+ var typename = store.getFieldValue(child, "__typename");
3552
+ if (typeof typename === "string" &&
3553
+ !childTypenames.includes(typename)) {
3554
+ childTypenames.push(typename);
3555
+ }
3556
+ });
3557
+ }
3558
+ __DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the ".concat(fieldName, " field of a ").concat(parentType, " object.\n\nTo address this problem (which is not a bug in Apollo Client), ").concat(childTypenames.length
3559
+ ? "either ensure all objects of type " +
3560
+ childTypenames.join(" and ") + " have an ID or a custom merge function, or "
3561
+ : "", "define a custom merge function for the ").concat(typeDotName, " field, so InMemoryCache can safely merge these objects:\n\n existing: ").concat(JSON.stringify(existing).slice(0, 1000), "\n incoming: ").concat(JSON.stringify(incoming).slice(0, 1000), "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n"));
3398
3562
  }
3399
3563
 
3400
3564
  var InMemoryCache = (function (_super) {
@@ -3543,8 +3707,14 @@ var InMemoryCache = (function (_super) {
3543
3707
  return (optimistic ? this.optimisticData : this.data).release(rootId);
3544
3708
  };
3545
3709
  InMemoryCache.prototype.identify = function (object) {
3546
- return isReference(object) ? object.__ref :
3547
- this.policies.identify(object)[0];
3710
+ if (isReference(object))
3711
+ return object.__ref;
3712
+ try {
3713
+ return this.policies.identify(object)[0];
3714
+ }
3715
+ catch (e) {
3716
+ __DEV__ && tsInvariant.invariant.warn(e);
3717
+ }
3548
3718
  };
3549
3719
  InMemoryCache.prototype.evict = function (options) {
3550
3720
  if (!options.id) {
@@ -3587,6 +3757,7 @@ var InMemoryCache = (function (_super) {
3587
3757
  InMemoryCache.prototype.batch = function (options) {
3588
3758
  var _this = this;
3589
3759
  var update = options.update, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, removeOptimistic = options.removeOptimistic, onWatchUpdated = options.onWatchUpdated;
3760
+ var updateResult;
3590
3761
  var perform = function (layer) {
3591
3762
  var _a = _this, data = _a.data, optimisticData = _a.optimisticData;
3592
3763
  ++_this.txCount;
@@ -3594,7 +3765,7 @@ var InMemoryCache = (function (_super) {
3594
3765
  _this.data = _this.optimisticData = layer;
3595
3766
  }
3596
3767
  try {
3597
- update(_this);
3768
+ return updateResult = update(_this);
3598
3769
  }
3599
3770
  finally {
3600
3771
  --_this.txCount;
@@ -3636,6 +3807,7 @@ var InMemoryCache = (function (_super) {
3636
3807
  else {
3637
3808
  this.broadcastWatches(options);
3638
3809
  }
3810
+ return updateResult;
3639
3811
  };
3640
3812
  InMemoryCache.prototype.performTransaction = function (update, optimisticId) {
3641
3813
  return this.batch({
@@ -3693,11 +3865,11 @@ var generateErrorMessage = function (err) {
3693
3865
  var errorMessage = error
3694
3866
  ? error.message
3695
3867
  : 'Error message not found.';
3696
- message += errorMessage + "\n";
3868
+ message += "".concat(errorMessage, "\n");
3697
3869
  });
3698
3870
  }
3699
3871
  if (err.networkError) {
3700
- message += err.networkError.message + "\n";
3872
+ message += "".concat(err.networkError.message, "\n");
3701
3873
  }
3702
3874
  message = message.replace(/\n$/, '');
3703
3875
  return message;
@@ -3810,11 +3982,11 @@ var ObservableQuery = (function (_super) {
3810
3982
  exports.NetworkStatus.ready;
3811
3983
  var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
3812
3984
  var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
3813
- var shouldReturnCachedData = lastResult || (fetchPolicy !== 'network-only' &&
3814
- fetchPolicy !== 'no-cache' &&
3815
- fetchPolicy !== 'standby');
3816
- if (shouldReturnCachedData &&
3817
- !this.queryManager.transform(this.options.query).hasForcedResolvers) {
3985
+ if (fetchPolicy === 'network-only' ||
3986
+ fetchPolicy === 'no-cache' ||
3987
+ fetchPolicy === 'standby' ||
3988
+ this.queryManager.transform(this.options.query).hasForcedResolvers) ;
3989
+ else {
3818
3990
  var diff = this.queryInfo.getDiff();
3819
3991
  if (diff.complete || this.options.returnPartialData) {
3820
3992
  result.data = diff.result;
@@ -3823,15 +3995,16 @@ var ObservableQuery = (function (_super) {
3823
3995
  result.data = void 0;
3824
3996
  }
3825
3997
  if (diff.complete) {
3826
- if (result.networkStatus === exports.NetworkStatus.loading &&
3998
+ delete result.partial;
3999
+ if (diff.complete &&
4000
+ result.networkStatus === exports.NetworkStatus.loading &&
3827
4001
  (fetchPolicy === 'cache-first' ||
3828
4002
  fetchPolicy === 'cache-only')) {
3829
4003
  result.networkStatus = exports.NetworkStatus.ready;
3830
4004
  result.loading = false;
3831
4005
  }
3832
- delete result.partial;
3833
4006
  }
3834
- else if (fetchPolicy !== "no-cache") {
4007
+ else {
3835
4008
  result.partial = true;
3836
4009
  }
3837
4010
  if (__DEV__ &&
@@ -3878,17 +4051,20 @@ var ObservableQuery = (function (_super) {
3878
4051
  pollInterval: 0,
3879
4052
  };
3880
4053
  var fetchPolicy = this.options.fetchPolicy;
3881
- if (fetchPolicy === 'no-cache') {
4054
+ if (fetchPolicy === 'standby' || fetchPolicy === 'cache-and-network') {
4055
+ reobserveOptions.fetchPolicy = fetchPolicy;
4056
+ }
4057
+ else if (fetchPolicy === 'no-cache') {
3882
4058
  reobserveOptions.fetchPolicy = 'no-cache';
3883
4059
  }
3884
- else if (fetchPolicy !== 'cache-and-network') {
4060
+ else {
3885
4061
  reobserveOptions.fetchPolicy = 'network-only';
3886
4062
  }
3887
4063
  if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
3888
4064
  var queryDef = getQueryDefinition(this.options.query);
3889
4065
  var vars = queryDef.variableDefinitions;
3890
4066
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
3891
- __DEV__ && tsInvariant.invariant.warn("Called refetch(" + JSON.stringify(variables) + ") for query " + (((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef)) + ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?");
4067
+ __DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
3892
4068
  }
3893
4069
  }
3894
4070
  if (variables && !equality.equal(this.options.variables, variables)) {
@@ -4035,7 +4211,7 @@ var ObservableQuery = (function (_super) {
4035
4211
  pollingInfo.interval === pollInterval) {
4036
4212
  return;
4037
4213
  }
4038
- __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 12);
4214
+ __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 10);
4039
4215
  var info = pollingInfo || (this.pollingInfo = {});
4040
4216
  info.interval = pollInterval;
4041
4217
  var maybeFetch = function () {
@@ -4150,8 +4326,8 @@ function defaultSubscriptionObserverErrorCallback(error) {
4150
4326
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4151
4327
  }
4152
4328
  function logMissingFieldErrors(missing) {
4153
- if (__DEV__ && isNonEmptyArray(missing)) {
4154
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
4329
+ if (__DEV__ && missing) {
4330
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
4155
4331
  }
4156
4332
  }
4157
4333
  function applyNextFetchPolicy(options) {
@@ -4332,7 +4508,7 @@ var LocalState = (function () {
4332
4508
  }
4333
4509
  else {
4334
4510
  fragment = fragmentMap[selection.name.value];
4335
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named " + selection.name.value) : tsInvariant.invariant(fragment, 11);
4511
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value)) : tsInvariant.invariant(fragment, 9);
4336
4512
  }
4337
4513
  if (fragment && fragment.typeCondition) {
4338
4514
  typeCondition = fragment.typeCondition.name.value;
@@ -4718,7 +4894,7 @@ var QueryManager = (function () {
4718
4894
  this.queries.forEach(function (_info, queryId) {
4719
4895
  _this.stopQueryNoBroadcast(queryId);
4720
4896
  });
4721
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(13));
4897
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(11));
4722
4898
  };
4723
4899
  QueryManager.prototype.cancelPendingFetches = function (error) {
4724
4900
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -4731,10 +4907,10 @@ var QueryManager = (function () {
4731
4907
  return tslib.__generator(this, function (_f) {
4732
4908
  switch (_f.label) {
4733
4909
  case 0:
4734
- __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 14);
4910
+ __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
4735
4911
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
4736
4912
  fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : tsInvariant.invariant(fetchPolicy === 'network-only' ||
4737
- fetchPolicy === 'no-cache', 15);
4913
+ fetchPolicy === 'no-cache', 13);
4738
4914
  mutationId = this.generateMutationId();
4739
4915
  mutation = this.transform(mutation).document;
4740
4916
  variables = this.getVariables(mutation, variables);
@@ -5019,10 +5195,10 @@ var QueryManager = (function () {
5019
5195
  var _this = this;
5020
5196
  if (queryId === void 0) { queryId = this.generateQueryId(); }
5021
5197
  __DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
5022
- 'in the query option.') : tsInvariant.invariant(options.query, 16);
5023
- __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 17);
5024
- __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 18);
5025
- __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 19);
5198
+ 'in the query option.') : tsInvariant.invariant(options.query, 14);
5199
+ __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 15);
5200
+ __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 16);
5201
+ __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 17);
5026
5202
  return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
5027
5203
  };
5028
5204
  QueryManager.prototype.generateQueryId = function () {
@@ -5047,7 +5223,7 @@ var QueryManager = (function () {
5047
5223
  if (options === void 0) { options = {
5048
5224
  discardWatches: true,
5049
5225
  }; }
5050
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(20));
5226
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(18));
5051
5227
  this.queries.forEach(function (queryInfo) {
5052
5228
  if (queryInfo.observableQuery) {
5053
5229
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -5123,7 +5299,7 @@ var QueryManager = (function () {
5123
5299
  if (__DEV__ && queryNamesAndDocs.size) {
5124
5300
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
5125
5301
  if (!included) {
5126
- __DEV__ && tsInvariant.invariant.warn("Unknown query " + (typeof nameOrDoc === "string" ? "named " : "") + JSON.stringify(nameOrDoc, null, 2) + " requested in refetchQueries options.include array");
5302
+ __DEV__ && tsInvariant.invariant.warn("Unknown query ".concat(typeof nameOrDoc === "string" ? "named " : "").concat(JSON.stringify(nameOrDoc, null, 2), " requested in refetchQueries options.include array"));
5127
5303
  }
5128
5304
  });
5129
5305
  }
@@ -5359,7 +5535,7 @@ var QueryManager = (function () {
5359
5535
  if (result !== false) {
5360
5536
  results.set(oq, result);
5361
5537
  }
5362
- return false;
5538
+ return result;
5363
5539
  }
5364
5540
  if (onQueryUpdated !== null) {
5365
5541
  includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
@@ -5535,7 +5711,7 @@ var ApolloClient = (function () {
5535
5711
  if (!cache) {
5536
5712
  throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
5537
5713
  "in the options object. \n" +
5538
- "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
5714
+ "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(7);
5539
5715
  }
5540
5716
  this.link = link;
5541
5717
  this.cache = cache;
@@ -5631,7 +5807,7 @@ var ApolloClient = (function () {
5631
5807
  __DEV__ ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
5632
5808
  'client.query can only return a single result. Please use client.watchQuery ' +
5633
5809
  'to receive multiple results from the cache and the network, or consider ' +
5634
- 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 10);
5810
+ 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 8);
5635
5811
  if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
5636
5812
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
5637
5813
  }
@@ -5714,7 +5890,7 @@ var ApolloClient = (function () {
5714
5890
  result.queries = queries;
5715
5891
  result.results = results;
5716
5892
  result.catch(function (error) {
5717
- __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
5893
+ __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error ".concat(error));
5718
5894
  });
5719
5895
  return result;
5720
5896
  };
@@ -5767,7 +5943,7 @@ var ApolloConsumer = function (props) {
5767
5943
  var ApolloContext = getApolloContext();
5768
5944
  return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5769
5945
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5770
- 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 27);
5946
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 25);
5771
5947
  return props.children(context.client);
5772
5948
  });
5773
5949
  };
@@ -5781,15 +5957,17 @@ var ApolloProvider = function (_a) {
5781
5957
  context = Object.assign({}, context, { client: client });
5782
5958
  }
5783
5959
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5784
- 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 28);
5960
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 26);
5785
5961
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5786
5962
  });
5787
5963
  };
5788
5964
 
5789
- function useApolloClient() {
5790
- var client = React__namespace.useContext(getApolloContext()).client;
5791
- __DEV__ ? tsInvariant.invariant(client, 'No Apollo Client instance can be found. Please ensure that you ' +
5792
- 'have called `ApolloProvider` higher up in your tree.') : tsInvariant.invariant(client, 33);
5965
+ function useApolloClient(override) {
5966
+ var context = React.useContext(getApolloContext());
5967
+ var client = override || context.client;
5968
+ __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5969
+ 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient' +
5970
+ 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 29);
5793
5971
  return client;
5794
5972
  }
5795
5973
 
@@ -5820,9 +5998,9 @@ function parser(document) {
5820
5998
  if (cached)
5821
5999
  return cached;
5822
6000
  var variables, type, name;
5823
- __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
6001
+ __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
5824
6002
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
5825
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 34);
6003
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
5826
6004
  var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
5827
6005
  var queries = document.definitions.filter(function (x) {
5828
6006
  return x.kind === 'OperationDefinition' && x.operation === 'query';
@@ -5836,11 +6014,11 @@ function parser(document) {
5836
6014
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
5837
6015
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
5838
6016
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
5839
- (queries.length || mutations.length || subscriptions.length), 35);
6017
+ (queries.length || mutations.length || subscriptions.length), 31);
5840
6018
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
5841
- (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
5842
- ("subscriptions and " + mutations.length + " mutations. ") +
5843
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 36);
6019
+ "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6020
+ "subscriptions and ".concat(mutations.length, " mutations. ") +
6021
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
5844
6022
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
5845
6023
  if (!queries.length && !mutations.length)
5846
6024
  type = exports.DocumentType.Subscription;
@@ -5849,9 +6027,9 @@ function parser(document) {
5849
6027
  : mutations.length
5850
6028
  ? mutations
5851
6029
  : subscriptions;
5852
- __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
5853
- (definitions.length + " definitions. ") +
5854
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 37);
6030
+ __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6031
+ "".concat(definitions.length, " definitions. ") +
6032
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 33);
5855
6033
  var definition = definitions[0];
5856
6034
  variables = definition.variableDefinitions || [];
5857
6035
  if (definition.name && definition.name.kind === 'Name') {
@@ -5864,711 +6042,470 @@ function parser(document) {
5864
6042
  cache.set(document, payload);
5865
6043
  return payload;
5866
6044
  }
6045
+ function verifyDocumentType(document, type) {
6046
+ var operation = parser(document);
6047
+ var requiredOperationName = operationName(type);
6048
+ var usedOperationName = operationName(operation.type);
6049
+ __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6050
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6051
+ }
5867
6052
 
5868
- var OperationData = (function () {
5869
- function OperationData(options, context) {
5870
- this.isMounted = false;
5871
- this.previousOptions = {};
5872
- this.context = {};
5873
- this.options = {};
5874
- this.options = options || {};
5875
- this.context = context || {};
5876
- }
5877
- OperationData.prototype.getOptions = function () {
5878
- return this.options;
5879
- };
5880
- OperationData.prototype.setOptions = function (newOptions, storePrevious) {
5881
- if (storePrevious === void 0) { storePrevious = false; }
5882
- if (storePrevious && !equality.equal(this.options, newOptions)) {
5883
- this.previousOptions = this.options;
5884
- }
5885
- this.options = newOptions;
5886
- };
5887
- OperationData.prototype.unmount = function () {
5888
- this.isMounted = false;
5889
- };
5890
- OperationData.prototype.refreshClient = function () {
5891
- var client = (this.options && this.options.client) ||
5892
- (this.context && this.context.client);
5893
- __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5894
- 'Wrap the root component in an <ApolloProvider>, or pass an ' +
5895
- 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 29);
5896
- var isNew = false;
5897
- if (client !== this.client) {
5898
- isNew = true;
5899
- this.client = client;
5900
- this.cleanup();
5901
- }
5902
- return {
5903
- client: this.client,
5904
- isNew: isNew
5905
- };
5906
- };
5907
- OperationData.prototype.verifyDocumentType = function (document, type) {
5908
- var operation = parser(document);
5909
- var requiredOperationName = operationName(type);
5910
- var usedOperationName = operationName(operation.type);
5911
- __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
5912
- (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 30);
5913
- };
5914
- return OperationData;
5915
- }());
5916
-
5917
- var SubscriptionData = (function (_super) {
5918
- tslib.__extends(SubscriptionData, _super);
5919
- function SubscriptionData(_a) {
5920
- var options = _a.options, context = _a.context, setResult = _a.setResult;
5921
- var _this = _super.call(this, options, context) || this;
5922
- _this.currentObservable = {};
5923
- _this.setResult = setResult;
5924
- _this.initialize(options);
5925
- return _this;
5926
- }
5927
- SubscriptionData.prototype.execute = function (result) {
5928
- if (this.getOptions().skip === true) {
5929
- this.cleanup();
5930
- return {
5931
- loading: false,
5932
- error: undefined,
5933
- data: undefined,
5934
- variables: this.getOptions().variables
5935
- };
5936
- }
5937
- var currentResult = result;
5938
- if (this.refreshClient().isNew) {
5939
- currentResult = this.getLoadingResult();
5940
- }
5941
- var shouldResubscribe = this.getOptions().shouldResubscribe;
5942
- if (typeof shouldResubscribe === 'function') {
5943
- shouldResubscribe = !!shouldResubscribe(this.getOptions());
5944
- }
5945
- if (shouldResubscribe !== false &&
5946
- this.previousOptions &&
5947
- Object.keys(this.previousOptions).length > 0 &&
5948
- (this.previousOptions.subscription !== this.getOptions().subscription ||
5949
- !equality.equal(this.previousOptions.variables, this.getOptions().variables) ||
5950
- this.previousOptions.skip !== this.getOptions().skip)) {
5951
- this.cleanup();
5952
- currentResult = this.getLoadingResult();
5953
- }
5954
- this.initialize(this.getOptions());
5955
- this.startSubscription();
5956
- this.previousOptions = this.getOptions();
5957
- return tslib.__assign(tslib.__assign({}, currentResult), { variables: this.getOptions().variables });
5958
- };
5959
- SubscriptionData.prototype.afterExecute = function () {
5960
- this.isMounted = true;
5961
- };
5962
- SubscriptionData.prototype.cleanup = function () {
5963
- this.endSubscription();
5964
- delete this.currentObservable.query;
5965
- };
5966
- SubscriptionData.prototype.initialize = function (options) {
5967
- if (this.currentObservable.query || this.getOptions().skip === true)
5968
- return;
5969
- this.currentObservable.query = this.refreshClient().client.subscribe({
5970
- query: options.subscription,
5971
- variables: options.variables,
5972
- fetchPolicy: options.fetchPolicy,
5973
- context: options.context,
5974
- });
5975
- };
5976
- SubscriptionData.prototype.startSubscription = function () {
5977
- if (this.currentObservable.subscription)
5978
- return;
5979
- this.currentObservable.subscription = this.currentObservable.query.subscribe({
5980
- next: this.updateCurrentData.bind(this),
5981
- error: this.updateError.bind(this),
5982
- complete: this.completeSubscription.bind(this)
5983
- });
5984
- };
5985
- SubscriptionData.prototype.getLoadingResult = function () {
5986
- return {
5987
- loading: true,
5988
- error: undefined,
5989
- data: undefined
5990
- };
5991
- };
5992
- SubscriptionData.prototype.updateResult = function (result) {
5993
- if (this.isMounted) {
5994
- this.setResult(result);
5995
- }
5996
- };
5997
- SubscriptionData.prototype.updateCurrentData = function (result) {
5998
- var onSubscriptionData = this.getOptions().onSubscriptionData;
5999
- this.updateResult({
6000
- data: result.data,
6001
- loading: false,
6002
- error: undefined
6003
- });
6004
- if (onSubscriptionData) {
6005
- onSubscriptionData({
6006
- client: this.refreshClient().client,
6007
- subscriptionData: result
6008
- });
6009
- }
6010
- };
6011
- SubscriptionData.prototype.updateError = function (error) {
6012
- this.updateResult({
6013
- error: error,
6014
- loading: false
6015
- });
6016
- };
6017
- SubscriptionData.prototype.completeSubscription = function () {
6018
- var _this = this;
6019
- Promise.resolve().then(function () {
6020
- var onSubscriptionComplete = _this.getOptions().onSubscriptionComplete;
6021
- if (onSubscriptionComplete)
6022
- onSubscriptionComplete();
6023
- _this.endSubscription();
6024
- });
6025
- };
6026
- SubscriptionData.prototype.endSubscription = function () {
6027
- if (this.currentObservable.subscription) {
6028
- this.currentObservable.subscription.unsubscribe();
6029
- delete this.currentObservable.subscription;
6030
- }
6031
- };
6032
- return SubscriptionData;
6033
- }(OperationData));
6034
-
6035
- var MutationData = (function (_super) {
6036
- tslib.__extends(MutationData, _super);
6037
- function MutationData(_a) {
6038
- var options = _a.options, context = _a.context, result = _a.result, setResult = _a.setResult;
6039
- var _this = _super.call(this, options, context) || this;
6040
- _this.runMutation = function (mutationFunctionOptions) {
6041
- if (mutationFunctionOptions === void 0) { mutationFunctionOptions = {}; }
6042
- _this.onMutationStart();
6043
- var mutationId = _this.generateNewMutationId();
6044
- return _this.mutate(mutationFunctionOptions)
6045
- .then(function (response) {
6046
- _this.onMutationCompleted(response, mutationId);
6047
- return response;
6048
- })
6049
- .catch(function (error) {
6050
- var onError = _this.getOptions().onError;
6051
- _this.onMutationError(error, mutationId);
6052
- if (onError) {
6053
- onError(error);
6054
- return {
6055
- data: undefined,
6056
- errors: error,
6057
- };
6058
- }
6059
- else {
6060
- throw error;
6061
- }
6062
- });
6063
- };
6064
- _this.verifyDocumentType(options.mutation, exports.DocumentType.Mutation);
6065
- _this.result = result;
6066
- _this.setResult = setResult;
6067
- _this.mostRecentMutationId = 0;
6068
- return _this;
6069
- }
6070
- MutationData.prototype.execute = function (result) {
6071
- this.isMounted = true;
6072
- this.verifyDocumentType(this.getOptions().mutation, exports.DocumentType.Mutation);
6073
- return [
6074
- this.runMutation,
6075
- tslib.__assign(tslib.__assign({}, result), { client: this.refreshClient().client })
6076
- ];
6077
- };
6078
- MutationData.prototype.afterExecute = function () {
6079
- this.isMounted = true;
6080
- return this.unmount.bind(this);
6081
- };
6082
- MutationData.prototype.cleanup = function () {
6083
- };
6084
- MutationData.prototype.mutate = function (options) {
6085
- return this.refreshClient().client.mutate(mergeOptions(this.getOptions(), options));
6086
- };
6087
- MutationData.prototype.onMutationStart = function () {
6088
- if (!this.result.loading && !this.getOptions().ignoreResults) {
6089
- this.updateResult({
6090
- loading: true,
6091
- error: undefined,
6092
- data: undefined,
6093
- called: true
6094
- });
6095
- }
6096
- };
6097
- MutationData.prototype.onMutationCompleted = function (response, mutationId) {
6098
- var _a = this.getOptions(), onCompleted = _a.onCompleted, ignoreResults = _a.ignoreResults;
6099
- var data = response.data, errors = response.errors;
6100
- var error = errors && errors.length > 0
6101
- ? new ApolloError({ graphQLErrors: errors })
6102
- : undefined;
6103
- var callOncomplete = function () {
6104
- return onCompleted ? onCompleted(data) : null;
6105
- };
6106
- if (this.isMostRecentMutation(mutationId) && !ignoreResults) {
6107
- this.updateResult({
6108
- called: true,
6109
- loading: false,
6110
- data: data,
6111
- error: error
6112
- });
6113
- }
6114
- callOncomplete();
6115
- };
6116
- MutationData.prototype.onMutationError = function (error, mutationId) {
6117
- if (this.isMostRecentMutation(mutationId)) {
6118
- this.updateResult({
6119
- loading: false,
6120
- error: error,
6121
- data: undefined,
6122
- called: true
6123
- });
6124
- }
6125
- };
6126
- MutationData.prototype.generateNewMutationId = function () {
6127
- return ++this.mostRecentMutationId;
6128
- };
6129
- MutationData.prototype.isMostRecentMutation = function (mutationId) {
6130
- return this.mostRecentMutationId === mutationId;
6131
- };
6132
- MutationData.prototype.updateResult = function (result) {
6133
- if (this.isMounted &&
6134
- (!this.previousResult || !equality.equal(this.previousResult, result))) {
6135
- this.setResult(result);
6136
- this.previousResult = result;
6137
- return result;
6053
+ function useQuery(query, options) {
6054
+ var _a;
6055
+ var context = React.useContext(getApolloContext());
6056
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6057
+ verifyDocumentType(query, exports.DocumentType.Query);
6058
+ var _b = React.useState(function () {
6059
+ var watchQueryOptions = createWatchQueryOptions(query, options);
6060
+ var obsQuery = null;
6061
+ if (context.renderPromises) {
6062
+ obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);
6063
+ }
6064
+ if (!obsQuery) {
6065
+ obsQuery = client.watchQuery(watchQueryOptions);
6066
+ if (context.renderPromises) {
6067
+ context.renderPromises.registerSSRObservable(obsQuery, watchQueryOptions);
6068
+ }
6069
+ }
6070
+ if (context.renderPromises &&
6071
+ (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6072
+ !(options === null || options === void 0 ? void 0 : options.skip) &&
6073
+ obsQuery.getCurrentResult().loading) {
6074
+ context.renderPromises.addQueryPromise({
6075
+ getOptions: function () { return createWatchQueryOptions(query, options); },
6076
+ fetchData: function () { return new Promise(function (resolve) {
6077
+ var sub = obsQuery.subscribe({
6078
+ next: function (result) {
6079
+ if (!result.loading) {
6080
+ resolve();
6081
+ sub.unsubscribe();
6082
+ }
6083
+ },
6084
+ error: function () {
6085
+ resolve();
6086
+ sub.unsubscribe();
6087
+ },
6088
+ complete: function () {
6089
+ resolve();
6090
+ },
6091
+ });
6092
+ }); },
6093
+ }, function () { return null; });
6138
6094
  }
6139
- };
6140
- return MutationData;
6141
- }(OperationData));
6142
-
6143
- var QueryData = (function (_super) {
6144
- tslib.__extends(QueryData, _super);
6145
- function QueryData(_a) {
6146
- var options = _a.options, context = _a.context, onNewData = _a.onNewData;
6147
- var _this = _super.call(this, options, context) || this;
6148
- _this.runLazy = false;
6149
- _this.previous = Object.create(null);
6150
- _this.runLazyQuery = function (options) {
6151
- _this.cleanup();
6152
- _this.runLazy = true;
6153
- _this.lazyOptions = options;
6154
- _this.onNewData();
6155
- };
6156
- _this.obsRefetch = function (variables) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.refetch(variables); };
6157
- _this.obsFetchMore = function (fetchMoreOptions) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.fetchMore(fetchMoreOptions); };
6158
- _this.obsUpdateQuery = function (mapFn) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.updateQuery(mapFn); };
6159
- _this.obsStartPolling = function (pollInterval) {
6160
- var _a;
6161
- (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.startPolling(pollInterval);
6162
- };
6163
- _this.obsStopPolling = function () {
6164
- var _a;
6165
- (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.stopPolling();
6166
- };
6167
- _this.obsSubscribeToMore = function (options) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.subscribeToMore(options); };
6168
- _this.onNewData = onNewData;
6169
- return _this;
6170
- }
6171
- QueryData.prototype.execute = function () {
6172
- this.refreshClient();
6173
- var _a = this.getOptions(), skip = _a.skip, query = _a.query;
6174
- if (skip || query !== this.previous.query) {
6175
- this.removeQuerySubscription();
6176
- this.removeObservable(!skip);
6177
- this.previous.query = query;
6178
- }
6179
- this.updateObservableQuery();
6180
- return this.getExecuteSsrResult() || this.getExecuteResult();
6181
- };
6182
- QueryData.prototype.executeLazy = function () {
6183
- return !this.runLazy
6184
- ? [
6185
- this.runLazyQuery,
6186
- {
6187
- loading: false,
6188
- networkStatus: exports.NetworkStatus.ready,
6189
- called: false,
6190
- data: undefined
6191
- }
6192
- ]
6193
- : [this.runLazyQuery, this.execute()];
6194
- };
6195
- QueryData.prototype.fetchData = function () {
6196
- var _this = this;
6197
- var options = this.getOptions();
6198
- if (options.skip || options.ssr === false)
6199
- return false;
6200
- return new Promise(function (resolve) { return _this.startQuerySubscription(resolve); });
6201
- };
6202
- QueryData.prototype.afterExecute = function (_a) {
6203
- var _b = _a === void 0 ? {} : _a, _c = _b.lazy, lazy = _c === void 0 ? false : _c;
6204
- this.isMounted = true;
6205
- var options = this.getOptions();
6206
- if (this.currentObservable && !this.ssrInitiated()) {
6207
- this.startQuerySubscription();
6208
- }
6209
- if (!lazy || this.runLazy) {
6210
- this.handleErrorOrCompleted();
6211
- }
6212
- this.previousOptions = options;
6213
- return this.unmount.bind(this);
6214
- };
6215
- QueryData.prototype.cleanup = function () {
6216
- this.removeQuerySubscription();
6217
- this.removeObservable(true);
6218
- delete this.previous.result;
6219
- };
6220
- QueryData.prototype.getOptions = function () {
6221
- var options = _super.prototype.getOptions.call(this);
6222
- if (this.lazyOptions) {
6223
- options.variables = tslib.__assign(tslib.__assign({}, options.variables), this.lazyOptions.variables);
6224
- options.context = tslib.__assign(tslib.__assign({}, options.context), this.lazyOptions.context);
6225
- }
6226
- if (this.runLazy) {
6227
- delete options.skip;
6228
- }
6229
- return options;
6230
- };
6231
- QueryData.prototype.ssrInitiated = function () {
6232
- return this.context && this.context.renderPromises;
6233
- };
6234
- QueryData.prototype.getExecuteSsrResult = function () {
6235
- var _a = this.getOptions(), ssr = _a.ssr, skip = _a.skip;
6236
- var ssrDisabled = ssr === false;
6237
- var fetchDisabled = this.refreshClient().client.disableNetworkFetches;
6238
- var ssrLoading = tslib.__assign({ loading: true, networkStatus: exports.NetworkStatus.loading, called: true, data: undefined, stale: false, client: this.client }, this.observableQueryFields());
6239
- if (ssrDisabled && (this.ssrInitiated() || fetchDisabled)) {
6240
- this.previous.result = ssrLoading;
6241
- return ssrLoading;
6242
- }
6243
- if (this.ssrInitiated()) {
6244
- var result = this.getExecuteResult() || ssrLoading;
6245
- if (result.loading && !skip) {
6246
- this.context.renderPromises.addQueryPromise(this, function () { return null; });
6095
+ return obsQuery;
6096
+ }), obsQuery = _b[0], setObsQuery = _b[1];
6097
+ var _c = React.useState(function () {
6098
+ var _a, _b;
6099
+ var result = obsQuery.getCurrentResult();
6100
+ if (!result.loading && options) {
6101
+ if (result.error) {
6102
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6247
6103
  }
6248
- return result;
6249
- }
6250
- };
6251
- QueryData.prototype.prepareObservableQueryOptions = function () {
6252
- var options = this.getOptions();
6253
- this.verifyDocumentType(options.query, exports.DocumentType.Query);
6254
- var displayName = options.displayName || 'Query';
6255
- if (this.ssrInitiated() &&
6256
- (options.fetchPolicy === 'network-only' ||
6257
- options.fetchPolicy === 'cache-and-network')) {
6258
- options.fetchPolicy = 'cache-first';
6259
- }
6260
- return tslib.__assign(tslib.__assign({}, options), { displayName: displayName, context: options.context });
6261
- };
6262
- QueryData.prototype.initializeObservableQuery = function () {
6263
- if (this.ssrInitiated()) {
6264
- this.currentObservable = this.context.renderPromises.getSSRObservable(this.getOptions());
6265
- }
6266
- if (!this.currentObservable) {
6267
- var observableQueryOptions = this.prepareObservableQueryOptions();
6268
- this.previous.observableQueryOptions = tslib.__assign(tslib.__assign({}, observableQueryOptions), { children: void 0 });
6269
- this.currentObservable = this.refreshClient().client.watchQuery(tslib.__assign({}, observableQueryOptions));
6270
- if (this.ssrInitiated()) {
6271
- this.context.renderPromises.registerSSRObservable(this.currentObservable, observableQueryOptions);
6104
+ else if (result.data) {
6105
+ (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6272
6106
  }
6273
6107
  }
6274
- };
6275
- QueryData.prototype.updateObservableQuery = function () {
6276
- if (!this.currentObservable) {
6277
- this.initializeObservableQuery();
6278
- return;
6279
- }
6280
- var newObservableQueryOptions = tslib.__assign(tslib.__assign({}, this.prepareObservableQueryOptions()), { children: void 0 });
6281
- if (this.getOptions().skip) {
6282
- this.previous.observableQueryOptions = newObservableQueryOptions;
6283
- return;
6284
- }
6285
- if (!equality.equal(newObservableQueryOptions, this.previous.observableQueryOptions)) {
6286
- this.previous.observableQueryOptions = newObservableQueryOptions;
6287
- this.currentObservable
6288
- .setOptions(newObservableQueryOptions)
6289
- .catch(function () { });
6290
- }
6291
- };
6292
- QueryData.prototype.startQuerySubscription = function (onNewData) {
6293
- var _this = this;
6294
- if (onNewData === void 0) { onNewData = this.onNewData; }
6295
- if (this.currentSubscription || this.getOptions().skip)
6296
- return;
6297
- this.currentSubscription = this.currentObservable.subscribe({
6298
- next: function (_a) {
6299
- var loading = _a.loading, networkStatus = _a.networkStatus, data = _a.data;
6300
- var previousResult = _this.previous.result;
6301
- if (previousResult &&
6302
- previousResult.loading === loading &&
6303
- previousResult.networkStatus === networkStatus &&
6304
- equality.equal(previousResult.data, data)) {
6305
- return;
6306
- }
6307
- onNewData();
6308
- },
6309
- error: function (error) {
6310
- _this.resubscribeToQuery();
6311
- if (!error.hasOwnProperty('graphQLErrors'))
6312
- throw error;
6313
- var previousResult = _this.previous.result;
6314
- if ((previousResult && previousResult.loading) ||
6315
- !equality.equal(error, _this.previous.error)) {
6316
- _this.previous.error = error;
6317
- onNewData();
6108
+ return result;
6109
+ }), result = _c[0], setResult = _c[1];
6110
+ var ref = React.useRef({
6111
+ client: client,
6112
+ query: query,
6113
+ options: options,
6114
+ result: result,
6115
+ previousData: void 0,
6116
+ watchQueryOptions: createWatchQueryOptions(query, options),
6117
+ });
6118
+ React.useEffect(function () {
6119
+ var _a, _b;
6120
+ var watchQueryOptions = createWatchQueryOptions(query, options);
6121
+ var nextResult;
6122
+ if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
6123
+ var obsQuery_1 = client.watchQuery(watchQueryOptions);
6124
+ setObsQuery(obsQuery_1);
6125
+ nextResult = obsQuery_1.getCurrentResult();
6126
+ }
6127
+ else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
6128
+ obsQuery.setOptions(watchQueryOptions).catch(function () { });
6129
+ nextResult = obsQuery.getCurrentResult();
6130
+ ref.current.watchQueryOptions = watchQueryOptions;
6131
+ }
6132
+ if (nextResult) {
6133
+ var previousResult = ref.current.result;
6134
+ if (previousResult.data) {
6135
+ ref.current.previousData = previousResult.data;
6136
+ }
6137
+ setResult(ref.current.result = nextResult);
6138
+ if (!nextResult.loading && options) {
6139
+ if (!result.loading) {
6140
+ if (result.error) {
6141
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
6142
+ }
6143
+ else if (result.data) {
6144
+ (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
6145
+ }
6318
6146
  }
6319
6147
  }
6320
- });
6321
- };
6322
- QueryData.prototype.resubscribeToQuery = function () {
6323
- this.removeQuerySubscription();
6324
- var currentObservable = this.currentObservable;
6325
- if (currentObservable) {
6326
- var last = currentObservable["last"];
6327
- try {
6328
- currentObservable.resetLastResults();
6329
- this.startQuerySubscription();
6330
- }
6331
- finally {
6332
- currentObservable["last"] = last;
6333
- }
6334
6148
  }
6335
- };
6336
- QueryData.prototype.getExecuteResult = function () {
6337
- var result = this.observableQueryFields();
6338
- var options = this.getOptions();
6339
- if (options.skip) {
6340
- result = tslib.__assign(tslib.__assign({}, result), { data: undefined, error: undefined, loading: false, networkStatus: exports.NetworkStatus.ready, called: true });
6149
+ Object.assign(ref.current, { client: client, query: query });
6150
+ }, [obsQuery, client, query, options]);
6151
+ React.useEffect(function () {
6152
+ if (context.renderPromises) {
6153
+ return;
6341
6154
  }
6342
- else if (this.currentObservable) {
6343
- var currentResult = this.currentObservable.getCurrentResult();
6344
- var data = currentResult.data, loading = currentResult.loading, partial = currentResult.partial, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
6345
- var error = currentResult.error;
6346
- if (errors && errors.length > 0) {
6347
- error = new ApolloError({ graphQLErrors: errors });
6155
+ var subscription = obsQuery.subscribe(onNext, onError);
6156
+ function onNext() {
6157
+ var _a, _b;
6158
+ var previousResult = ref.current.result;
6159
+ var result = obsQuery.getCurrentResult();
6160
+ if (previousResult &&
6161
+ previousResult.loading === result.loading &&
6162
+ previousResult.networkStatus === result.networkStatus &&
6163
+ equality.equal(previousResult.data, result.data)) {
6164
+ return;
6348
6165
  }
6349
- result = tslib.__assign(tslib.__assign({}, result), { data: data, loading: loading, networkStatus: networkStatus, error: error, called: true });
6350
- if (loading) ;
6351
- else if (error) {
6352
- Object.assign(result, {
6353
- data: (this.currentObservable.getLastResult() || {})
6354
- .data
6355
- });
6166
+ if (previousResult.data) {
6167
+ ref.current.previousData = previousResult.data;
6356
6168
  }
6357
- else {
6358
- var fetchPolicy = this.currentObservable.options.fetchPolicy;
6359
- var partialRefetch = options.partialRefetch;
6360
- if (partialRefetch &&
6361
- partial &&
6362
- (!data || Object.keys(data).length === 0) &&
6363
- fetchPolicy !== 'cache-only') {
6364
- Object.assign(result, {
6365
- loading: true,
6366
- networkStatus: exports.NetworkStatus.loading
6367
- });
6368
- result.refetch();
6369
- return result;
6370
- }
6169
+ setResult(ref.current.result = result);
6170
+ if (!result.loading) {
6171
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
6371
6172
  }
6372
6173
  }
6373
- result.client = this.client;
6374
- this.setOptions(options, true);
6375
- var previousResult = this.previous.result;
6376
- this.previous.loading =
6377
- previousResult && previousResult.loading || false;
6378
- result.previousData = previousResult &&
6379
- (previousResult.data || previousResult.previousData);
6380
- this.previous.result = result;
6381
- this.currentObservable && this.currentObservable.resetQueryStoreErrors();
6382
- return result;
6383
- };
6384
- QueryData.prototype.handleErrorOrCompleted = function () {
6385
- if (!this.currentObservable || !this.previous.result)
6386
- return;
6387
- var _a = this.previous.result, data = _a.data, loading = _a.loading, error = _a.error;
6388
- if (!loading) {
6389
- var _b = this.getOptions(), query = _b.query, variables = _b.variables, onCompleted = _b.onCompleted, onError = _b.onError, skip = _b.skip;
6390
- if (this.previousOptions &&
6391
- !this.previous.loading &&
6392
- equality.equal(this.previousOptions.query, query) &&
6393
- equality.equal(this.previousOptions.variables, variables)) {
6394
- return;
6395
- }
6396
- if (onCompleted && !error && !skip) {
6397
- onCompleted(data);
6174
+ function onError(error) {
6175
+ var _a, _b;
6176
+ var last = obsQuery["last"];
6177
+ subscription.unsubscribe();
6178
+ try {
6179
+ obsQuery.resetLastResults();
6180
+ subscription = obsQuery.subscribe(onNext, onError);
6398
6181
  }
6399
- else if (onError && error) {
6400
- onError(error);
6182
+ finally {
6183
+ obsQuery["last"] = last;
6401
6184
  }
6402
- }
6403
- };
6404
- QueryData.prototype.removeQuerySubscription = function () {
6405
- if (this.currentSubscription) {
6406
- this.currentSubscription.unsubscribe();
6407
- delete this.currentSubscription;
6408
- }
6409
- };
6410
- QueryData.prototype.removeObservable = function (andDelete) {
6411
- if (this.currentObservable) {
6412
- this.currentObservable["tearDownQuery"]();
6413
- if (andDelete) {
6414
- delete this.currentObservable;
6185
+ if (!error.hasOwnProperty('graphQLErrors')) {
6186
+ throw error;
6415
6187
  }
6416
- }
6417
- };
6418
- QueryData.prototype.observableQueryFields = function () {
6419
- var _a;
6420
- return {
6421
- variables: (_a = this.currentObservable) === null || _a === void 0 ? void 0 : _a.variables,
6422
- refetch: this.obsRefetch,
6423
- fetchMore: this.obsFetchMore,
6424
- updateQuery: this.obsUpdateQuery,
6425
- startPolling: this.obsStartPolling,
6426
- stopPolling: this.obsStopPolling,
6427
- subscribeToMore: this.obsSubscribeToMore
6188
+ var previousResult = ref.current.result;
6189
+ if ((previousResult && previousResult.loading) ||
6190
+ !equality.equal(error, previousResult.error)) {
6191
+ setResult(ref.current.result = {
6192
+ data: previousResult.data,
6193
+ error: error,
6194
+ loading: false,
6195
+ networkStatus: exports.NetworkStatus.error,
6196
+ });
6197
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
6198
+ }
6199
+ }
6200
+ return function () { return subscription.unsubscribe(); };
6201
+ }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
6202
+ var partial;
6203
+ (_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
6204
+ {
6205
+ if (partial &&
6206
+ (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
6207
+ !result.loading &&
6208
+ (!result.data || Object.keys(result.data).length === 0) &&
6209
+ obsQuery.options.fetchPolicy !== 'cache-only') {
6210
+ result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
6211
+ obsQuery.refetch();
6212
+ }
6213
+ if (context.renderPromises &&
6214
+ (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6215
+ !(options === null || options === void 0 ? void 0 : options.skip) &&
6216
+ result.loading) {
6217
+ obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(function () { });
6218
+ }
6219
+ Object.assign(ref.current, { options: options });
6220
+ }
6221
+ if ((context.renderPromises || client.disableNetworkFetches) &&
6222
+ (options === null || options === void 0 ? void 0 : options.ssr) === false) {
6223
+ result = ref.current.result = {
6224
+ loading: true,
6225
+ data: void 0,
6226
+ error: void 0,
6227
+ networkStatus: exports.NetworkStatus.loading,
6428
6228
  };
6429
- };
6430
- return QueryData;
6431
- }(OperationData));
6432
-
6433
- function useDeepMemo(memoFn, key) {
6434
- var ref = React.useRef();
6435
- if (!ref.current || !equality.equal(key, ref.current.key)) {
6436
- ref.current = { key: key, value: memoFn() };
6437
6229
  }
6438
- return ref.current.value;
6439
- }
6440
-
6441
- function useAfterFastRefresh(effectFn) {
6442
- if (__DEV__) {
6443
- var didRefresh_1 = React.useRef(false);
6444
- React.useEffect(function () {
6445
- return function () {
6446
- didRefresh_1.current = true;
6447
- };
6448
- }, []);
6449
- React.useEffect(function () {
6450
- if (didRefresh_1.current === true) {
6451
- didRefresh_1.current = false;
6452
- effectFn();
6453
- }
6454
- }, []);
6230
+ else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
6231
+ result = {
6232
+ loading: false,
6233
+ data: void 0,
6234
+ error: void 0,
6235
+ networkStatus: exports.NetworkStatus.ready,
6236
+ };
6237
+ }
6238
+ if (result.errors && result.errors.length) {
6239
+ result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
6240
+ }
6241
+ var obsQueryFields = React.useMemo(function () { return ({
6242
+ refetch: obsQuery.refetch.bind(obsQuery),
6243
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
6244
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
6245
+ startPolling: obsQuery.startPolling.bind(obsQuery),
6246
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
6247
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
6248
+ }); }, [obsQuery]);
6249
+ return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options).variables, client: client, called: true, previousData: ref.current.previousData }), result);
6250
+ }
6251
+ function createWatchQueryOptions(query, options) {
6252
+ var _a;
6253
+ if (options === void 0) { options = {}; }
6254
+ var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var watchQueryOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
6255
+ if (skip) {
6256
+ watchQueryOptions.fetchPolicy = 'standby';
6257
+ }
6258
+ else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
6259
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
6260
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
6261
+ watchQueryOptions.fetchPolicy = 'cache-first';
6262
+ }
6263
+ else if (!watchQueryOptions.fetchPolicy) {
6264
+ watchQueryOptions.fetchPolicy = 'cache-first';
6455
6265
  }
6266
+ if (!watchQueryOptions.variables) {
6267
+ watchQueryOptions.variables = {};
6268
+ }
6269
+ return tslib.__assign({ query: query }, watchQueryOptions);
6456
6270
  }
6457
6271
 
6458
- function useBaseQuery(query, options, lazy) {
6459
- if (lazy === void 0) { lazy = false; }
6460
- var context = React.useContext(getApolloContext());
6461
- var _a = React.useReducer(function (x) { return x + 1; }, 0), tick = _a[0], forceUpdate = _a[1];
6462
- var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { query: query }) : { query: query };
6463
- var queryDataRef = React.useRef();
6464
- var queryData = queryDataRef.current || (queryDataRef.current = new QueryData({
6465
- options: updatedOptions,
6466
- context: context,
6467
- onNewData: function () {
6468
- if (!queryData.ssrInitiated()) {
6469
- Promise.resolve().then(function () { return queryDataRef.current && queryDataRef.current.isMounted && forceUpdate(); });
6470
- }
6471
- else {
6472
- forceUpdate();
6272
+ var EAGER_METHODS = [
6273
+ 'refetch',
6274
+ 'fetchMore',
6275
+ 'updateQuery',
6276
+ 'startPolling',
6277
+ 'subscribeToMore',
6278
+ ];
6279
+ function useLazyQuery(query, options) {
6280
+ var _a = React.useState({
6281
+ called: false,
6282
+ resolves: [],
6283
+ }), execution = _a[0], setExecution = _a[1];
6284
+ var execute = React.useCallback(function (executeOptions) {
6285
+ var resolve;
6286
+ var promise = new Promise(function (resolve1) { return (resolve = resolve1); });
6287
+ setExecution(function (execution) {
6288
+ if (execution.called) {
6289
+ result && result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables);
6473
6290
  }
6474
- }
6475
- }));
6476
- queryData.setOptions(updatedOptions);
6477
- queryData.context = context;
6478
- var memo = {
6479
- options: tslib.__assign(tslib.__assign({}, updatedOptions), { onError: void 0, onCompleted: void 0 }),
6480
- context: context,
6481
- tick: tick
6482
- };
6483
- var result = useDeepMemo(function () { return (lazy ? queryData.executeLazy() : queryData.execute()); }, memo);
6484
- var queryResult = lazy
6485
- ? result[1]
6486
- : result;
6487
- if (__DEV__) {
6488
- useAfterFastRefresh(forceUpdate);
6489
- }
6291
+ return {
6292
+ called: true,
6293
+ resolves: tslib.__spreadArray(tslib.__spreadArray([], execution.resolves, true), [resolve], false),
6294
+ options: executeOptions,
6295
+ };
6296
+ });
6297
+ return promise;
6298
+ }, []);
6299
+ var result = useQuery(query, tslib.__assign(tslib.__assign(tslib.__assign({}, options), execution.options), { fetchPolicy: execution.called ? options === null || options === void 0 ? void 0 : options.fetchPolicy : 'standby', skip: undefined }));
6490
6300
  React.useEffect(function () {
6491
- return function () {
6492
- queryData.cleanup();
6493
- queryDataRef.current = void 0;
6301
+ var resolves = execution.resolves;
6302
+ if (!result.loading && resolves.length) {
6303
+ setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { resolves: [] })); });
6304
+ resolves.forEach(function (resolve) { return resolve(result); });
6305
+ }
6306
+ }, [result, execution]);
6307
+ if (!execution.called) {
6308
+ result = tslib.__assign(tslib.__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
6309
+ var _loop_1 = function (key) {
6310
+ var method = result[key];
6311
+ result[key] = function () {
6312
+ var args = [];
6313
+ for (var _i = 0; _i < arguments.length; _i++) {
6314
+ args[_i] = arguments[_i];
6315
+ }
6316
+ setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { called: true })); });
6317
+ return method.apply(void 0, args);
6318
+ };
6494
6319
  };
6495
- }, []);
6496
- React.useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
6497
- queryResult.loading,
6498
- queryResult.networkStatus,
6499
- queryResult.error,
6500
- queryResult.data,
6501
- queryData.currentObservable,
6502
- ]);
6503
- return result;
6504
- }
6505
-
6506
- function useLazyQuery(query, options) {
6507
- return useBaseQuery(query, options, true);
6320
+ for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
6321
+ var key = EAGER_METHODS_1[_i];
6322
+ _loop_1(key);
6323
+ }
6324
+ }
6325
+ return [execute, result];
6508
6326
  }
6509
6327
 
6510
6328
  function useMutation(mutation, options) {
6511
- var context = React.useContext(getApolloContext());
6512
- var _a = React.useState({ called: false, loading: false }), result = _a[0], setResult = _a[1];
6513
- var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { mutation: mutation }) : { mutation: mutation };
6514
- var mutationDataRef = React.useRef();
6515
- function getMutationDataRef() {
6516
- if (!mutationDataRef.current) {
6517
- mutationDataRef.current = new MutationData({
6518
- options: updatedOptions,
6519
- context: context,
6520
- result: result,
6521
- setResult: setResult
6329
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6330
+ verifyDocumentType(mutation, exports.DocumentType.Mutation);
6331
+ var _a = React.useState({
6332
+ called: false,
6333
+ loading: false,
6334
+ client: client,
6335
+ }), result = _a[0], setResult = _a[1];
6336
+ var ref = React.useRef({
6337
+ result: result,
6338
+ mutationId: 0,
6339
+ isMounted: true,
6340
+ client: client,
6341
+ mutation: mutation,
6342
+ options: options,
6343
+ });
6344
+ {
6345
+ Object.assign(ref.current, { client: client, options: options, mutation: mutation });
6346
+ }
6347
+ var execute = React.useCallback(function (executeOptions) {
6348
+ if (executeOptions === void 0) { executeOptions = {}; }
6349
+ var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
6350
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6351
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6352
+ setResult(ref.current.result = {
6353
+ loading: true,
6354
+ error: void 0,
6355
+ data: void 0,
6356
+ called: true,
6357
+ client: client,
6522
6358
  });
6523
6359
  }
6524
- return mutationDataRef.current;
6525
- }
6526
- var mutationData = getMutationDataRef();
6527
- mutationData.setOptions(updatedOptions);
6528
- mutationData.context = context;
6529
- React.useEffect(function () { return mutationData.afterExecute(); });
6530
- return mutationData.execute(result);
6531
- }
6532
-
6533
- function useQuery(query, options) {
6534
- return useBaseQuery(query, options, false);
6360
+ var mutationId = ++ref.current.mutationId;
6361
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
6362
+ return client.mutate(clientOptions).then(function (response) {
6363
+ var _a, _b;
6364
+ var data = response.data, errors = response.errors;
6365
+ var error = errors && errors.length > 0
6366
+ ? new ApolloError({ graphQLErrors: errors })
6367
+ : void 0;
6368
+ if (mutationId === ref.current.mutationId &&
6369
+ !clientOptions.ignoreResults) {
6370
+ var result_1 = {
6371
+ called: true,
6372
+ loading: false,
6373
+ data: data,
6374
+ error: error,
6375
+ client: client,
6376
+ };
6377
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6378
+ setResult(ref.current.result = result_1);
6379
+ }
6380
+ }
6381
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6382
+ (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
6383
+ return response;
6384
+ }).catch(function (error) {
6385
+ var _a, _b;
6386
+ if (mutationId === ref.current.mutationId &&
6387
+ ref.current.isMounted) {
6388
+ var result_2 = {
6389
+ loading: false,
6390
+ error: error,
6391
+ data: void 0,
6392
+ called: true,
6393
+ client: client,
6394
+ };
6395
+ if (!equality.equal(ref.current.result, result_2)) {
6396
+ setResult(ref.current.result = result_2);
6397
+ }
6398
+ }
6399
+ if (baseOptions.onError || clientOptions.onError) {
6400
+ (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
6401
+ (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
6402
+ return { data: void 0, errors: error };
6403
+ }
6404
+ throw error;
6405
+ });
6406
+ }, []);
6407
+ var reset = React.useCallback(function () {
6408
+ setResult({ called: false, loading: false, client: client });
6409
+ }, []);
6410
+ React.useEffect(function () { return function () {
6411
+ ref.current.isMounted = false;
6412
+ }; }, []);
6413
+ return [execute, tslib.__assign({ reset: reset }, result)];
6535
6414
  }
6536
6415
 
6537
6416
  function useSubscription(subscription, options) {
6538
- var _a = React.useReducer(function (x) { return x + 1; }, 0), forceUpdate = _a[1];
6539
- var context = React.useContext(getApolloContext());
6540
- var updatedOptions = options
6541
- ? tslib.__assign(tslib.__assign({}, options), { subscription: subscription }) : { subscription: subscription };
6542
- var _b = React.useState({
6543
- loading: !updatedOptions.skip,
6417
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6418
+ verifyDocumentType(subscription, exports.DocumentType.Subscription);
6419
+ var _a = React.useState({
6420
+ loading: !(options === null || options === void 0 ? void 0 : options.skip),
6544
6421
  error: void 0,
6545
6422
  data: void 0,
6546
- }), result = _b[0], setResult = _b[1];
6547
- var subscriptionDataRef = React.useRef();
6548
- function getSubscriptionDataRef() {
6549
- if (!subscriptionDataRef.current) {
6550
- subscriptionDataRef.current = new SubscriptionData({
6551
- options: updatedOptions,
6552
- context: context,
6553
- setResult: setResult
6554
- });
6423
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6424
+ }), result = _a[0], setResult = _a[1];
6425
+ var _b = React.useState(function () {
6426
+ if (options === null || options === void 0 ? void 0 : options.skip) {
6427
+ return null;
6555
6428
  }
6556
- return subscriptionDataRef.current;
6557
- }
6558
- var subscriptionData = getSubscriptionDataRef();
6559
- subscriptionData.setOptions(updatedOptions, true);
6560
- subscriptionData.context = context;
6561
- if (__DEV__) {
6562
- useAfterFastRefresh(forceUpdate);
6563
- }
6564
- React.useEffect(function () { return subscriptionData.afterExecute(); });
6429
+ return client.subscribe({
6430
+ query: subscription,
6431
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6432
+ fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6433
+ context: options === null || options === void 0 ? void 0 : options.context,
6434
+ });
6435
+ }), observable = _b[0], setObservable = _b[1];
6436
+ var ref = React.useRef({ client: client, subscription: subscription, options: options });
6437
+ React.useEffect(function () {
6438
+ var _a, _b, _c, _d;
6439
+ var shouldResubscribe = options === null || options === void 0 ? void 0 : options.shouldResubscribe;
6440
+ if (typeof shouldResubscribe === 'function') {
6441
+ shouldResubscribe = !!shouldResubscribe(options);
6442
+ }
6443
+ if ((options === null || options === void 0 ? void 0 : options.skip) && !(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6444
+ setResult({
6445
+ loading: false,
6446
+ data: void 0,
6447
+ error: void 0,
6448
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6449
+ });
6450
+ setObservable(null);
6451
+ }
6452
+ else if (shouldResubscribe !== false && (client !== ref.current.client ||
6453
+ subscription !== ref.current.subscription ||
6454
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6455
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6456
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6457
+ setResult({
6458
+ loading: true,
6459
+ data: void 0,
6460
+ error: void 0,
6461
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6462
+ });
6463
+ setObservable(client.subscribe({
6464
+ query: subscription,
6465
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6466
+ fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6467
+ context: options === null || options === void 0 ? void 0 : options.context,
6468
+ }));
6469
+ }
6470
+ Object.assign(ref.current, { client: client, subscription: subscription, options: options });
6471
+ }, [client, subscription, options]);
6565
6472
  React.useEffect(function () {
6473
+ if (!observable) {
6474
+ return;
6475
+ }
6476
+ var subscription = observable.subscribe({
6477
+ next: function (fetchResult) {
6478
+ var _a, _b;
6479
+ var result = {
6480
+ loading: false,
6481
+ data: fetchResult.data,
6482
+ error: void 0,
6483
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6484
+ };
6485
+ setResult(result);
6486
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionData) === null || _b === void 0 ? void 0 : _b.call(_a, {
6487
+ client: client,
6488
+ subscriptionData: result
6489
+ });
6490
+ },
6491
+ error: function (error) {
6492
+ setResult({
6493
+ loading: false,
6494
+ data: void 0,
6495
+ error: error,
6496
+ variables: options === null || options === void 0 ? void 0 : options.variables,
6497
+ });
6498
+ },
6499
+ complete: function () {
6500
+ var _a, _b;
6501
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
6502
+ },
6503
+ });
6566
6504
  return function () {
6567
- subscriptionData.cleanup();
6568
- subscriptionDataRef.current = void 0;
6505
+ subscription.unsubscribe();
6569
6506
  };
6570
- }, []);
6571
- return subscriptionData.execute(result);
6507
+ }, [observable]);
6508
+ return result;
6572
6509
  }
6573
6510
 
6574
6511
  function useReactiveVar(rv) {
@@ -6609,6 +6546,7 @@ exports.concat = concat;
6609
6546
  exports.createHttpLink = createHttpLink;
6610
6547
  exports.createSignalIfSupported = createSignalIfSupported;
6611
6548
  exports.defaultDataIdFromObject = defaultDataIdFromObject;
6549
+ exports.defaultPrinter = defaultPrinter;
6612
6550
  exports.empty = empty;
6613
6551
  exports.execute = execute;
6614
6552
  exports.fallbackHttpConfig = fallbackHttpConfig;
@@ -6627,6 +6565,7 @@ exports.parser = parser;
6627
6565
  exports.resetApolloContext = getApolloContext;
6628
6566
  exports.rewriteURIForGET = rewriteURIForGET;
6629
6567
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
6568
+ exports.selectHttpOptionsAndBodyInternal = selectHttpOptionsAndBodyInternal;
6630
6569
  exports.selectURI = selectURI;
6631
6570
  exports.serializeFetchParameter = serializeFetchParameter;
6632
6571
  exports.split = split;
@@ -6638,4 +6577,4 @@ exports.useMutation = useMutation;
6638
6577
  exports.useQuery = useQuery;
6639
6578
  exports.useReactiveVar = useReactiveVar;
6640
6579
  exports.useSubscription = useSubscription;
6641
- //# sourceMappingURL=apollo-client.cjs.js.map
6580
+ //# sourceMappingURL=apollo-client.cjs.map