@apollo/client 0.0.0-pr-10521-20230206180228

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 (778) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +45 -0
  3. package/apollo-client.cjs +7614 -0
  4. package/apollo-client.cjs.map +1 -0
  5. package/apollo-client.min.cjs +1 -0
  6. package/cache/cache.cjs +2425 -0
  7. package/cache/cache.cjs.map +1 -0
  8. package/cache/cache.cjs.native.js +2425 -0
  9. package/cache/core/cache.d.ts +32 -0
  10. package/cache/core/cache.d.ts.map +1 -0
  11. package/cache/core/cache.js +84 -0
  12. package/cache/core/cache.js.map +1 -0
  13. package/cache/core/types/Cache.d.ts +55 -0
  14. package/cache/core/types/Cache.d.ts.map +1 -0
  15. package/cache/core/types/Cache.js +4 -0
  16. package/cache/core/types/Cache.js.map +1 -0
  17. package/cache/core/types/DataProxy.d.ts +52 -0
  18. package/cache/core/types/DataProxy.d.ts.map +1 -0
  19. package/cache/core/types/DataProxy.js +2 -0
  20. package/cache/core/types/DataProxy.js.map +1 -0
  21. package/cache/core/types/common.d.ts +47 -0
  22. package/cache/core/types/common.d.ts.map +1 -0
  23. package/cache/core/types/common.js +26 -0
  24. package/cache/core/types/common.js.map +1 -0
  25. package/cache/index.d.ts +15 -0
  26. package/cache/index.d.ts.map +1 -0
  27. package/cache/index.js +14 -0
  28. package/cache/index.js.map +1 -0
  29. package/cache/inmemory/__mocks__/optimism.d.ts +2 -0
  30. package/cache/inmemory/__mocks__/optimism.d.ts.map +1 -0
  31. package/cache/inmemory/__mocks__/optimism.js +14 -0
  32. package/cache/inmemory/__mocks__/optimism.js.map +1 -0
  33. package/cache/inmemory/entityStore.d.ts +83 -0
  34. package/cache/inmemory/entityStore.d.ts.map +1 -0
  35. package/cache/inmemory/entityStore.js +467 -0
  36. package/cache/inmemory/entityStore.js.map +1 -0
  37. package/cache/inmemory/fixPolyfills.d.ts +1 -0
  38. package/cache/inmemory/fixPolyfills.d.ts.map +1 -0
  39. package/cache/inmemory/fixPolyfills.js +1 -0
  40. package/cache/inmemory/fixPolyfills.js.map +1 -0
  41. package/cache/inmemory/fixPolyfills.native.d.ts +2 -0
  42. package/cache/inmemory/fixPolyfills.native.d.ts.map +1 -0
  43. package/cache/inmemory/fixPolyfills.native.js +48 -0
  44. package/cache/inmemory/fixPolyfills.native.js.map +1 -0
  45. package/cache/inmemory/fragmentRegistry.d.ts +8 -0
  46. package/cache/inmemory/fragmentRegistry.d.ts.map +1 -0
  47. package/cache/inmemory/fragmentRegistry.js +113 -0
  48. package/cache/inmemory/fragmentRegistry.js.map +1 -0
  49. package/cache/inmemory/helpers.d.ts +27 -0
  50. package/cache/inmemory/helpers.d.ts.map +1 -0
  51. package/cache/inmemory/helpers.js +85 -0
  52. package/cache/inmemory/helpers.js.map +1 -0
  53. package/cache/inmemory/inMemoryCache.d.ts +52 -0
  54. package/cache/inmemory/inMemoryCache.d.ts.map +1 -0
  55. package/cache/inmemory/inMemoryCache.js +316 -0
  56. package/cache/inmemory/inMemoryCache.js.map +1 -0
  57. package/cache/inmemory/key-extractor.d.ts +9 -0
  58. package/cache/inmemory/key-extractor.d.ts.map +1 -0
  59. package/cache/inmemory/key-extractor.js +118 -0
  60. package/cache/inmemory/key-extractor.js.map +1 -0
  61. package/cache/inmemory/object-canon.d.ts +17 -0
  62. package/cache/inmemory/object-canon.d.ts.map +1 -0
  63. package/cache/inmemory/object-canon.js +120 -0
  64. package/cache/inmemory/object-canon.js.map +1 -0
  65. package/cache/inmemory/policies.d.ts +96 -0
  66. package/cache/inmemory/policies.d.ts.map +1 -0
  67. package/cache/inmemory/policies.js +416 -0
  68. package/cache/inmemory/policies.js.map +1 -0
  69. package/cache/inmemory/reactiveVars.d.ts +18 -0
  70. package/cache/inmemory/reactiveVars.d.ts.map +1 -0
  71. package/cache/inmemory/reactiveVars.js +65 -0
  72. package/cache/inmemory/reactiveVars.js.map +1 -0
  73. package/cache/inmemory/readFromStore.d.ts +36 -0
  74. package/cache/inmemory/readFromStore.d.ts.map +1 -0
  75. package/cache/inmemory/readFromStore.js +267 -0
  76. package/cache/inmemory/readFromStore.js.map +1 -0
  77. package/cache/inmemory/types.d.ts +81 -0
  78. package/cache/inmemory/types.d.ts.map +1 -0
  79. package/cache/inmemory/types.js +4 -0
  80. package/cache/inmemory/types.js.map +1 -0
  81. package/cache/inmemory/writeToStore.d.ts +37 -0
  82. package/cache/inmemory/writeToStore.d.ts.map +1 -0
  83. package/cache/inmemory/writeToStore.js +394 -0
  84. package/cache/inmemory/writeToStore.js.map +1 -0
  85. package/cache/package.json +8 -0
  86. package/config/jest/setup.d.ts +2 -0
  87. package/config/jest/setup.d.ts.map +1 -0
  88. package/config/jest/setup.js +5 -0
  89. package/config/jest/setup.js.map +1 -0
  90. package/core/ApolloClient.d.ts +76 -0
  91. package/core/ApolloClient.d.ts.map +1 -0
  92. package/core/ApolloClient.js +240 -0
  93. package/core/ApolloClient.js.map +1 -0
  94. package/core/LocalState.d.ts +69 -0
  95. package/core/LocalState.d.ts.map +1 -0
  96. package/core/LocalState.js +321 -0
  97. package/core/LocalState.js.map +1 -0
  98. package/core/ObservableQuery.d.ts +74 -0
  99. package/core/ObservableQuery.d.ts.map +1 -0
  100. package/core/ObservableQuery.js +507 -0
  101. package/core/ObservableQuery.js.map +1 -0
  102. package/core/QueryInfo.d.ts +62 -0
  103. package/core/QueryInfo.d.ts.map +1 -0
  104. package/core/QueryInfo.js +287 -0
  105. package/core/QueryInfo.js.map +1 -0
  106. package/core/QueryManager.d.ts +120 -0
  107. package/core/QueryManager.d.ts.map +1 -0
  108. package/core/QueryManager.js +890 -0
  109. package/core/QueryManager.js.map +1 -0
  110. package/core/core.cjs +2349 -0
  111. package/core/core.cjs.map +1 -0
  112. package/core/core.cjs.native.js +2349 -0
  113. package/core/index.d.ts +17 -0
  114. package/core/index.d.ts.map +1 -0
  115. package/core/index.js +17 -0
  116. package/core/index.js.map +1 -0
  117. package/core/networkStatus.d.ts +11 -0
  118. package/core/networkStatus.d.ts.map +1 -0
  119. package/core/networkStatus.js +14 -0
  120. package/core/networkStatus.js.map +1 -0
  121. package/core/package.json +8 -0
  122. package/core/types.d.ts +74 -0
  123. package/core/types.d.ts.map +1 -0
  124. package/core/types.js +3 -0
  125. package/core/types.js.map +1 -0
  126. package/core/watchQueryOptions.d.ts +78 -0
  127. package/core/watchQueryOptions.d.ts.map +1 -0
  128. package/core/watchQueryOptions.js +2 -0
  129. package/core/watchQueryOptions.js.map +1 -0
  130. package/errors/errors.cjs +49 -0
  131. package/errors/errors.cjs.map +1 -0
  132. package/errors/errors.cjs.native.js +49 -0
  133. package/errors/index.d.ts +23 -0
  134. package/errors/index.d.ts.map +1 -0
  135. package/errors/index.js +42 -0
  136. package/errors/index.js.map +1 -0
  137. package/errors/package.json +8 -0
  138. package/index.d.ts +3 -0
  139. package/index.d.ts.map +1 -0
  140. package/index.js +3 -0
  141. package/index.js.map +1 -0
  142. package/invariantErrorCodes.js +339 -0
  143. package/link/batch/batch.cjs +159 -0
  144. package/link/batch/batch.cjs.map +1 -0
  145. package/link/batch/batch.cjs.native.js +159 -0
  146. package/link/batch/batchLink.d.ts +19 -0
  147. package/link/batch/batchLink.d.ts.map +1 -0
  148. package/link/batch/batchLink.js +31 -0
  149. package/link/batch/batchLink.js.map +1 -0
  150. package/link/batch/batching.d.ts +27 -0
  151. package/link/batch/batching.d.ts.map +1 -0
  152. package/link/batch/batching.js +125 -0
  153. package/link/batch/batching.js.map +1 -0
  154. package/link/batch/index.d.ts +2 -0
  155. package/link/batch/index.d.ts.map +1 -0
  156. package/link/batch/index.js +2 -0
  157. package/link/batch/index.js.map +1 -0
  158. package/link/batch/package.json +8 -0
  159. package/link/batch-http/batch-http.cjs +137 -0
  160. package/link/batch-http/batch-http.cjs.map +1 -0
  161. package/link/batch-http/batch-http.cjs.native.js +137 -0
  162. package/link/batch-http/batchHttpLink.d.ts +16 -0
  163. package/link/batch-http/batchHttpLink.d.ts.map +1 -0
  164. package/link/batch-http/batchHttpLink.js +131 -0
  165. package/link/batch-http/batchHttpLink.js.map +1 -0
  166. package/link/batch-http/index.d.ts +2 -0
  167. package/link/batch-http/index.d.ts.map +1 -0
  168. package/link/batch-http/index.js +2 -0
  169. package/link/batch-http/index.js.map +1 -0
  170. package/link/batch-http/package.json +8 -0
  171. package/link/context/context.cjs +38 -0
  172. package/link/context/context.cjs.map +1 -0
  173. package/link/context/context.cjs.native.js +38 -0
  174. package/link/context/index.d.ts +5 -0
  175. package/link/context/index.d.ts.map +1 -0
  176. package/link/context/index.js +31 -0
  177. package/link/context/index.js.map +1 -0
  178. package/link/context/package.json +8 -0
  179. package/link/core/ApolloLink.d.ts +16 -0
  180. package/link/core/ApolloLink.d.ts.map +1 -0
  181. package/link/core/ApolloLink.js +100 -0
  182. package/link/core/ApolloLink.js.map +1 -0
  183. package/link/core/concat.d.ts +3 -0
  184. package/link/core/concat.d.ts.map +1 -0
  185. package/link/core/concat.js +3 -0
  186. package/link/core/concat.js.map +1 -0
  187. package/link/core/core.cjs +121 -0
  188. package/link/core/core.cjs.map +1 -0
  189. package/link/core/core.cjs.native.js +121 -0
  190. package/link/core/empty.d.ts +3 -0
  191. package/link/core/empty.d.ts.map +1 -0
  192. package/link/core/empty.js +3 -0
  193. package/link/core/empty.js.map +1 -0
  194. package/link/core/execute.d.ts +3 -0
  195. package/link/core/execute.d.ts.map +1 -0
  196. package/link/core/execute.js +3 -0
  197. package/link/core/execute.js.map +1 -0
  198. package/link/core/from.d.ts +3 -0
  199. package/link/core/from.d.ts.map +1 -0
  200. package/link/core/from.js +3 -0
  201. package/link/core/from.js.map +1 -0
  202. package/link/core/index.d.ts +9 -0
  203. package/link/core/index.d.ts.map +1 -0
  204. package/link/core/index.js +9 -0
  205. package/link/core/index.js.map +1 -0
  206. package/link/core/package.json +8 -0
  207. package/link/core/split.d.ts +3 -0
  208. package/link/core/split.d.ts.map +1 -0
  209. package/link/core/split.js +3 -0
  210. package/link/core/split.js.map +1 -0
  211. package/link/core/types.d.ts +52 -0
  212. package/link/core/types.d.ts.map +1 -0
  213. package/link/core/types.js +2 -0
  214. package/link/core/types.js.map +1 -0
  215. package/link/error/error.cjs +90 -0
  216. package/link/error/error.cjs.map +1 -0
  217. package/link/error/error.cjs.native.js +90 -0
  218. package/link/error/index.d.ts +24 -0
  219. package/link/error/index.d.ts.map +1 -0
  220. package/link/error/index.js +83 -0
  221. package/link/error/index.js.map +1 -0
  222. package/link/error/package.json +8 -0
  223. package/link/http/HttpLink.d.ts +8 -0
  224. package/link/http/HttpLink.d.ts.map +1 -0
  225. package/link/http/HttpLink.js +15 -0
  226. package/link/http/HttpLink.js.map +1 -0
  227. package/link/http/checkFetcher.d.ts +2 -0
  228. package/link/http/checkFetcher.d.ts.map +1 -0
  229. package/link/http/checkFetcher.js +7 -0
  230. package/link/http/checkFetcher.js.map +1 -0
  231. package/link/http/createHttpLink.d.ts +4 -0
  232. package/link/http/createHttpLink.d.ts.map +1 -0
  233. package/link/http/createHttpLink.js +127 -0
  234. package/link/http/createHttpLink.js.map +1 -0
  235. package/link/http/createSignalIfSupported.d.ts +8 -0
  236. package/link/http/createSignalIfSupported.d.ts.map +1 -0
  237. package/link/http/createSignalIfSupported.js +8 -0
  238. package/link/http/createSignalIfSupported.js.map +1 -0
  239. package/link/http/http.cjs +593 -0
  240. package/link/http/http.cjs.map +1 -0
  241. package/link/http/http.cjs.native.js +593 -0
  242. package/link/http/index.d.ts +11 -0
  243. package/link/http/index.d.ts.map +1 -0
  244. package/link/http/index.js +11 -0
  245. package/link/http/index.js.map +1 -0
  246. package/link/http/iterators/async.d.ts +2 -0
  247. package/link/http/iterators/async.d.ts.map +1 -0
  248. package/link/http/iterators/async.js +14 -0
  249. package/link/http/iterators/async.js.map +1 -0
  250. package/link/http/iterators/nodeStream.d.ts +4 -0
  251. package/link/http/iterators/nodeStream.d.ts.map +1 -0
  252. package/link/http/iterators/nodeStream.js +71 -0
  253. package/link/http/iterators/nodeStream.js.map +1 -0
  254. package/link/http/iterators/promise.d.ts +2 -0
  255. package/link/http/iterators/promise.d.ts.map +1 -0
  256. package/link/http/iterators/promise.js +28 -0
  257. package/link/http/iterators/promise.js.map +1 -0
  258. package/link/http/iterators/reader.d.ts +2 -0
  259. package/link/http/iterators/reader.d.ts.map +1 -0
  260. package/link/http/iterators/reader.js +15 -0
  261. package/link/http/iterators/reader.js.map +1 -0
  262. package/link/http/package.json +8 -0
  263. package/link/http/parseAndCheckHttpResponse.d.ts +14 -0
  264. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -0
  265. package/link/http/parseAndCheckHttpResponse.js +148 -0
  266. package/link/http/parseAndCheckHttpResponse.js.map +1 -0
  267. package/link/http/responseIterator.d.ts +3 -0
  268. package/link/http/responseIterator.d.ts.map +1 -0
  269. package/link/http/responseIterator.js +23 -0
  270. package/link/http/responseIterator.js.map +1 -0
  271. package/link/http/rewriteURIForGET.d.ts +9 -0
  272. package/link/http/rewriteURIForGET.d.ts.map +1 -0
  273. package/link/http/rewriteURIForGET.js +43 -0
  274. package/link/http/rewriteURIForGET.js.map +1 -0
  275. package/link/http/selectHttpOptionsAndBody.d.ts +57 -0
  276. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -0
  277. package/link/http/selectHttpOptionsAndBody.js +78 -0
  278. package/link/http/selectHttpOptionsAndBody.js.map +1 -0
  279. package/link/http/selectURI.d.ts +3 -0
  280. package/link/http/selectURI.d.ts.map +1 -0
  281. package/link/http/selectURI.js +14 -0
  282. package/link/http/selectURI.js.map +1 -0
  283. package/link/http/serializeFetchParameter.d.ts +6 -0
  284. package/link/http/serializeFetchParameter.d.ts.map +1 -0
  285. package/link/http/serializeFetchParameter.js +14 -0
  286. package/link/http/serializeFetchParameter.js.map +1 -0
  287. package/link/persisted-queries/index.d.ts +31 -0
  288. package/link/persisted-queries/index.d.ts.map +1 -0
  289. package/link/persisted-queries/index.js +170 -0
  290. package/link/persisted-queries/index.js.map +1 -0
  291. package/link/persisted-queries/package.json +8 -0
  292. package/link/persisted-queries/persisted-queries.cjs +174 -0
  293. package/link/persisted-queries/persisted-queries.cjs.map +1 -0
  294. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  295. package/link/retry/delayFunction.d.ts +11 -0
  296. package/link/retry/delayFunction.d.ts.map +1 -0
  297. package/link/retry/delayFunction.js +12 -0
  298. package/link/retry/delayFunction.js.map +1 -0
  299. package/link/retry/index.d.ts +2 -0
  300. package/link/retry/index.d.ts.map +1 -0
  301. package/link/retry/index.js +2 -0
  302. package/link/retry/index.js.map +1 -0
  303. package/link/retry/package.json +8 -0
  304. package/link/retry/retry.cjs +170 -0
  305. package/link/retry/retry.cjs.map +1 -0
  306. package/link/retry/retry.cjs.native.js +170 -0
  307. package/link/retry/retryFunction.d.ts +10 -0
  308. package/link/retry/retryFunction.d.ts.map +1 -0
  309. package/link/retry/retryFunction.js +9 -0
  310. package/link/retry/retryFunction.js.map +1 -0
  311. package/link/retry/retryLink.d.ts +17 -0
  312. package/link/retry/retryLink.d.ts.map +1 -0
  313. package/link/retry/retryLink.js +145 -0
  314. package/link/retry/retryLink.js.map +1 -0
  315. package/link/schema/index.d.ts +22 -0
  316. package/link/schema/index.d.ts.map +1 -0
  317. package/link/schema/index.js +50 -0
  318. package/link/schema/index.js.map +1 -0
  319. package/link/schema/package.json +8 -0
  320. package/link/schema/schema.cjs +56 -0
  321. package/link/schema/schema.cjs.map +1 -0
  322. package/link/schema/schema.cjs.native.js +56 -0
  323. package/link/subscriptions/index.d.ts +9 -0
  324. package/link/subscriptions/index.d.ts.map +1 -0
  325. package/link/subscriptions/index.js +39 -0
  326. package/link/subscriptions/index.js.map +1 -0
  327. package/link/subscriptions/package.json +8 -0
  328. package/link/subscriptions/subscriptions.cjs +45 -0
  329. package/link/subscriptions/subscriptions.cjs.map +1 -0
  330. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  331. package/link/utils/createOperation.d.ts +3 -0
  332. package/link/utils/createOperation.d.ts.map +1 -0
  333. package/link/utils/createOperation.js +23 -0
  334. package/link/utils/createOperation.js.map +1 -0
  335. package/link/utils/fromError.d.ts +3 -0
  336. package/link/utils/fromError.d.ts.map +1 -0
  337. package/link/utils/fromError.js +7 -0
  338. package/link/utils/fromError.js.map +1 -0
  339. package/link/utils/fromPromise.d.ts +3 -0
  340. package/link/utils/fromPromise.d.ts.map +1 -0
  341. package/link/utils/fromPromise.js +12 -0
  342. package/link/utils/fromPromise.js.map +1 -0
  343. package/link/utils/index.d.ts +9 -0
  344. package/link/utils/index.d.ts.map +1 -0
  345. package/link/utils/index.js +9 -0
  346. package/link/utils/index.js.map +1 -0
  347. package/link/utils/package.json +8 -0
  348. package/link/utils/throwServerError.d.ts +7 -0
  349. package/link/utils/throwServerError.d.ts.map +1 -0
  350. package/link/utils/throwServerError.js +9 -0
  351. package/link/utils/throwServerError.js.map +1 -0
  352. package/link/utils/toPromise.d.ts +3 -0
  353. package/link/utils/toPromise.d.ts.map +1 -0
  354. package/link/utils/toPromise.js +19 -0
  355. package/link/utils/toPromise.js.map +1 -0
  356. package/link/utils/transformOperation.d.ts +3 -0
  357. package/link/utils/transformOperation.d.ts.map +1 -0
  358. package/link/utils/transformOperation.js +17 -0
  359. package/link/utils/transformOperation.js.map +1 -0
  360. package/link/utils/utils.cjs +115 -0
  361. package/link/utils/utils.cjs.map +1 -0
  362. package/link/utils/utils.cjs.native.js +115 -0
  363. package/link/utils/validateOperation.d.ts +3 -0
  364. package/link/utils/validateOperation.d.ts.map +1 -0
  365. package/link/utils/validateOperation.js +18 -0
  366. package/link/utils/validateOperation.js.map +1 -0
  367. package/link/ws/index.d.ts +17 -0
  368. package/link/ws/index.d.ts.map +1 -0
  369. package/link/ws/index.js +22 -0
  370. package/link/ws/index.js.map +1 -0
  371. package/link/ws/package.json +8 -0
  372. package/link/ws/ws.cjs +28 -0
  373. package/link/ws/ws.cjs.map +1 -0
  374. package/link/ws/ws.cjs.native.js +28 -0
  375. package/main.cjs +16 -0
  376. package/main.cjs.map +1 -0
  377. package/main.cjs.native.js +16 -0
  378. package/package.json +141 -0
  379. package/react/cache/SuspenseCache.d.ts +18 -0
  380. package/react/cache/SuspenseCache.d.ts.map +1 -0
  381. package/react/cache/SuspenseCache.js +49 -0
  382. package/react/cache/SuspenseCache.js.map +1 -0
  383. package/react/cache/index.d.ts +2 -0
  384. package/react/cache/index.d.ts.map +1 -0
  385. package/react/cache/index.js +2 -0
  386. package/react/cache/index.js.map +1 -0
  387. package/react/components/Mutation.d.ts +12 -0
  388. package/react/components/Mutation.d.ts.map +1 -0
  389. package/react/components/Mutation.js +22 -0
  390. package/react/components/Mutation.js.map +1 -0
  391. package/react/components/Query.d.ts +12 -0
  392. package/react/components/Query.d.ts.map +1 -0
  393. package/react/components/Query.js +23 -0
  394. package/react/components/Query.js.map +1 -0
  395. package/react/components/Subscription.d.ts +12 -0
  396. package/react/components/Subscription.d.ts.map +1 -0
  397. package/react/components/Subscription.js +17 -0
  398. package/react/components/Subscription.js.map +1 -0
  399. package/react/components/components.cjs +81 -0
  400. package/react/components/components.cjs.map +1 -0
  401. package/react/components/components.cjs.native.js +81 -0
  402. package/react/components/index.d.ts +5 -0
  403. package/react/components/index.d.ts.map +1 -0
  404. package/react/components/index.js +5 -0
  405. package/react/components/index.js.map +1 -0
  406. package/react/components/package.json +8 -0
  407. package/react/components/types.d.ts +18 -0
  408. package/react/components/types.d.ts.map +1 -0
  409. package/react/components/types.js +2 -0
  410. package/react/components/types.js.map +1 -0
  411. package/react/context/ApolloConsumer.d.ts +7 -0
  412. package/react/context/ApolloConsumer.d.ts.map +1 -0
  413. package/react/context/ApolloConsumer.js +12 -0
  414. package/react/context/ApolloConsumer.js.map +1 -0
  415. package/react/context/ApolloContext.d.ts +12 -0
  416. package/react/context/ApolloContext.d.ts.map +1 -0
  417. package/react/context/ApolloContext.js +20 -0
  418. package/react/context/ApolloContext.js.map +1 -0
  419. package/react/context/ApolloProvider.d.ts +10 -0
  420. package/react/context/ApolloProvider.d.ts.map +1 -0
  421. package/react/context/ApolloProvider.js +20 -0
  422. package/react/context/ApolloProvider.js.map +1 -0
  423. package/react/context/context.cjs +70 -0
  424. package/react/context/context.cjs.map +1 -0
  425. package/react/context/context.cjs.native.js +70 -0
  426. package/react/context/index.d.ts +5 -0
  427. package/react/context/index.d.ts.map +1 -0
  428. package/react/context/index.js +5 -0
  429. package/react/context/index.js.map +1 -0
  430. package/react/context/package.json +8 -0
  431. package/react/hoc/graphql.d.ts +6 -0
  432. package/react/hoc/graphql.d.ts.map +1 -0
  433. package/react/hoc/graphql.js +17 -0
  434. package/react/hoc/graphql.js.map +1 -0
  435. package/react/hoc/hoc-utils.d.ts +17 -0
  436. package/react/hoc/hoc-utils.d.ts.map +1 -0
  437. package/react/hoc/hoc-utils.js +47 -0
  438. package/react/hoc/hoc-utils.js.map +1 -0
  439. package/react/hoc/hoc.cjs +325 -0
  440. package/react/hoc/hoc.cjs.map +1 -0
  441. package/react/hoc/hoc.cjs.native.js +325 -0
  442. package/react/hoc/index.d.ts +8 -0
  443. package/react/hoc/index.d.ts.map +1 -0
  444. package/react/hoc/index.js +8 -0
  445. package/react/hoc/index.js.map +1 -0
  446. package/react/hoc/mutation-hoc.d.ts +7 -0
  447. package/react/hoc/mutation-hoc.d.ts.map +1 -0
  448. package/react/hoc/mutation-hoc.js +63 -0
  449. package/react/hoc/mutation-hoc.js.map +1 -0
  450. package/react/hoc/package.json +8 -0
  451. package/react/hoc/query-hoc.d.ts +5 -0
  452. package/react/hoc/query-hoc.d.ts.map +1 -0
  453. package/react/hoc/query-hoc.js +70 -0
  454. package/react/hoc/query-hoc.js.map +1 -0
  455. package/react/hoc/subscription-hoc.d.ts +5 -0
  456. package/react/hoc/subscription-hoc.d.ts.map +1 -0
  457. package/react/hoc/subscription-hoc.js +80 -0
  458. package/react/hoc/subscription-hoc.js.map +1 -0
  459. package/react/hoc/types.d.ts +43 -0
  460. package/react/hoc/types.d.ts.map +1 -0
  461. package/react/hoc/types.js +2 -0
  462. package/react/hoc/types.js.map +1 -0
  463. package/react/hoc/withApollo.d.ts +4 -0
  464. package/react/hoc/withApollo.d.ts.map +1 -0
  465. package/react/hoc/withApollo.js +45 -0
  466. package/react/hoc/withApollo.js.map +1 -0
  467. package/react/hooks/compareResults.d.ts +3 -0
  468. package/react/hooks/compareResults.d.ts.map +1 -0
  469. package/react/hooks/compareResults.js +63 -0
  470. package/react/hooks/compareResults.js.map +1 -0
  471. package/react/hooks/hooks.cjs +913 -0
  472. package/react/hooks/hooks.cjs.map +1 -0
  473. package/react/hooks/hooks.cjs.native.js +913 -0
  474. package/react/hooks/index.d.ts +10 -0
  475. package/react/hooks/index.d.ts.map +1 -0
  476. package/react/hooks/index.js +10 -0
  477. package/react/hooks/index.js.map +1 -0
  478. package/react/hooks/internal/index.d.ts +3 -0
  479. package/react/hooks/internal/index.d.ts.map +1 -0
  480. package/react/hooks/internal/index.js +3 -0
  481. package/react/hooks/internal/index.js.map +1 -0
  482. package/react/hooks/internal/useDeepMemo.d.ts +3 -0
  483. package/react/hooks/internal/useDeepMemo.d.ts.map +1 -0
  484. package/react/hooks/internal/useDeepMemo.js +10 -0
  485. package/react/hooks/internal/useDeepMemo.js.map +1 -0
  486. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +3 -0
  487. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -0
  488. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -0
  489. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -0
  490. package/react/hooks/package.json +8 -0
  491. package/react/hooks/useApolloClient.d.ts +3 -0
  492. package/react/hooks/useApolloClient.d.ts.map +1 -0
  493. package/react/hooks/useApolloClient.js +12 -0
  494. package/react/hooks/useApolloClient.js.map +1 -0
  495. package/react/hooks/useFragment.d.ts +13 -0
  496. package/react/hooks/useFragment.d.ts.map +1 -0
  497. package/react/hooks/useFragment.js +39 -0
  498. package/react/hooks/useFragment.js.map +1 -0
  499. package/react/hooks/useLazyQuery.d.ts +6 -0
  500. package/react/hooks/useLazyQuery.d.ts.map +1 -0
  501. package/react/hooks/useLazyQuery.js +71 -0
  502. package/react/hooks/useLazyQuery.js.map +1 -0
  503. package/react/hooks/useMutation.d.ts +6 -0
  504. package/react/hooks/useMutation.d.ts.map +1 -0
  505. package/react/hooks/useMutation.js +100 -0
  506. package/react/hooks/useMutation.js.map +1 -0
  507. package/react/hooks/useQuery.d.ts +41 -0
  508. package/react/hooks/useQuery.d.ts.map +1 -0
  509. package/react/hooks/useQuery.js +302 -0
  510. package/react/hooks/useQuery.js.map +1 -0
  511. package/react/hooks/useReactiveVar.d.ts +3 -0
  512. package/react/hooks/useReactiveVar.d.ts.map +1 -0
  513. package/react/hooks/useReactiveVar.js +16 -0
  514. package/react/hooks/useReactiveVar.js.map +1 -0
  515. package/react/hooks/useSubscription.d.ts +6 -0
  516. package/react/hooks/useSubscription.d.ts.map +1 -0
  517. package/react/hooks/useSubscription.js +141 -0
  518. package/react/hooks/useSubscription.js.map +1 -0
  519. package/react/hooks/useSuspenseCache.d.ts +2 -0
  520. package/react/hooks/useSuspenseCache.d.ts.map +1 -0
  521. package/react/hooks/useSuspenseCache.js +10 -0
  522. package/react/hooks/useSuspenseCache.js.map +1 -0
  523. package/react/hooks/useSuspenseQuery.d.ts +12 -0
  524. package/react/hooks/useSuspenseQuery.d.ts.map +1 -0
  525. package/react/hooks/useSuspenseQuery.js +181 -0
  526. package/react/hooks/useSuspenseQuery.js.map +1 -0
  527. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  528. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  529. package/react/hooks/useSyncExternalStore.js +48 -0
  530. package/react/hooks/useSyncExternalStore.js.map +1 -0
  531. package/react/index.d.ts +7 -0
  532. package/react/index.d.ts.map +1 -0
  533. package/react/index.js +7 -0
  534. package/react/index.js.map +1 -0
  535. package/react/package.json +8 -0
  536. package/react/parser/index.d.ts +15 -0
  537. package/react/parser/index.d.ts.map +1 -0
  538. package/react/parser/index.js +94 -0
  539. package/react/parser/index.js.map +1 -0
  540. package/react/parser/package.json +8 -0
  541. package/react/parser/parser.cjs +103 -0
  542. package/react/parser/parser.cjs.map +1 -0
  543. package/react/parser/parser.cjs.native.js +103 -0
  544. package/react/react.cjs +69 -0
  545. package/react/react.cjs.map +1 -0
  546. package/react/react.cjs.native.js +69 -0
  547. package/react/ssr/RenderPromises.d.ts +22 -0
  548. package/react/ssr/RenderPromises.d.ts.map +1 -0
  549. package/react/ssr/RenderPromises.js +90 -0
  550. package/react/ssr/RenderPromises.js.map +1 -0
  551. package/react/ssr/getDataFromTree.d.ts +13 -0
  552. package/react/ssr/getDataFromTree.d.ts.map +1 -0
  553. package/react/ssr/getDataFromTree.js +32 -0
  554. package/react/ssr/getDataFromTree.js.map +1 -0
  555. package/react/ssr/index.d.ts +4 -0
  556. package/react/ssr/index.d.ts.map +1 -0
  557. package/react/ssr/index.js +4 -0
  558. package/react/ssr/index.js.map +1 -0
  559. package/react/ssr/package.json +8 -0
  560. package/react/ssr/renderToStringWithData.d.ts +3 -0
  561. package/react/ssr/renderToStringWithData.d.ts.map +1 -0
  562. package/react/ssr/renderToStringWithData.js +9 -0
  563. package/react/ssr/renderToStringWithData.js.map +1 -0
  564. package/react/ssr/ssr.cjs +151 -0
  565. package/react/ssr/ssr.cjs.map +1 -0
  566. package/react/ssr/ssr.cjs.native.js +151 -0
  567. package/react/types/types.d.ts +130 -0
  568. package/react/types/types.d.ts.map +1 -0
  569. package/react/types/types.js +2 -0
  570. package/react/types/types.js.map +1 -0
  571. package/testing/core/core.cjs +315 -0
  572. package/testing/core/core.cjs.map +1 -0
  573. package/testing/core/core.cjs.native.js +315 -0
  574. package/testing/core/index.d.ts +8 -0
  575. package/testing/core/index.d.ts.map +1 -0
  576. package/testing/core/index.js +8 -0
  577. package/testing/core/index.js.map +1 -0
  578. package/testing/core/itAsync.d.ts +6 -0
  579. package/testing/core/itAsync.d.ts.map +1 -0
  580. package/testing/core/itAsync.js +19 -0
  581. package/testing/core/itAsync.js.map +1 -0
  582. package/testing/core/mocking/mockClient.d.ts +5 -0
  583. package/testing/core/mocking/mockClient.d.ts.map +1 -0
  584. package/testing/core/mocking/mockClient.js +14 -0
  585. package/testing/core/mocking/mockClient.js.map +1 -0
  586. package/testing/core/mocking/mockFetch.d.ts +24 -0
  587. package/testing/core/mocking/mockFetch.d.ts.map +1 -0
  588. package/testing/core/mocking/mockFetch.js +83 -0
  589. package/testing/core/mocking/mockFetch.js.map +1 -0
  590. package/testing/core/mocking/mockLink.d.ts +28 -0
  591. package/testing/core/mocking/mockLink.d.ts.map +1 -0
  592. package/testing/core/mocking/mockLink.js +139 -0
  593. package/testing/core/mocking/mockLink.js.map +1 -0
  594. package/testing/core/mocking/mockQueryManager.d.ts +5 -0
  595. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
  596. package/testing/core/mocking/mockQueryManager.js +14 -0
  597. package/testing/core/mocking/mockQueryManager.js.map +1 -0
  598. package/testing/core/mocking/mockSubscriptionLink.d.ts +24 -0
  599. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
  600. package/testing/core/mocking/mockSubscriptionLink.js +62 -0
  601. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
  602. package/testing/core/mocking/mockWatchQuery.d.ts +5 -0
  603. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
  604. package/testing/core/mocking/mockWatchQuery.js +15 -0
  605. package/testing/core/mocking/mockWatchQuery.js.map +1 -0
  606. package/testing/core/observableToPromise.d.ts +15 -0
  607. package/testing/core/observableToPromise.d.ts.map +1 -0
  608. package/testing/core/observableToPromise.js +65 -0
  609. package/testing/core/observableToPromise.js.map +1 -0
  610. package/testing/core/package.json +8 -0
  611. package/testing/core/subscribeAndCount.d.ts +3 -0
  612. package/testing/core/subscribeAndCount.d.ts.map +1 -0
  613. package/testing/core/subscribeAndCount.js +16 -0
  614. package/testing/core/subscribeAndCount.js.map +1 -0
  615. package/testing/core/wait.d.ts +3 -0
  616. package/testing/core/wait.d.ts.map +1 -0
  617. package/testing/core/wait.js +16 -0
  618. package/testing/core/wait.js.map +1 -0
  619. package/testing/core/withConsoleSpy.d.ts +4 -0
  620. package/testing/core/withConsoleSpy.d.ts.map +1 -0
  621. package/testing/core/withConsoleSpy.js +39 -0
  622. package/testing/core/withConsoleSpy.js.map +1 -0
  623. package/testing/core/wrap.d.ts +4 -0
  624. package/testing/core/wrap.d.ts.map +1 -0
  625. package/testing/core/wrap.js +26 -0
  626. package/testing/core/wrap.js.map +1 -0
  627. package/testing/index.d.ts +4 -0
  628. package/testing/index.d.ts.map +1 -0
  629. package/testing/index.js +4 -0
  630. package/testing/index.js.map +1 -0
  631. package/testing/package.json +8 -0
  632. package/testing/react/MockedProvider.d.ts +30 -0
  633. package/testing/react/MockedProvider.d.ts.map +1 -0
  634. package/testing/react/MockedProvider.js +39 -0
  635. package/testing/react/MockedProvider.js.map +1 -0
  636. package/testing/testing.cjs +109 -0
  637. package/testing/testing.cjs.map +1 -0
  638. package/testing/testing.cjs.native.js +109 -0
  639. package/utilities/common/arrays.d.ts +2 -0
  640. package/utilities/common/arrays.d.ts.map +1 -0
  641. package/utilities/common/arrays.js +4 -0
  642. package/utilities/common/arrays.js.map +1 -0
  643. package/utilities/common/canUse.d.ts +7 -0
  644. package/utilities/common/canUse.d.ts.map +1 -0
  645. package/utilities/common/canUse.js +11 -0
  646. package/utilities/common/canUse.js.map +1 -0
  647. package/utilities/common/cloneDeep.d.ts +2 -0
  648. package/utilities/common/cloneDeep.d.ts.map +1 -0
  649. package/utilities/common/cloneDeep.js +33 -0
  650. package/utilities/common/cloneDeep.js.map +1 -0
  651. package/utilities/common/compact.d.ts +3 -0
  652. package/utilities/common/compact.d.ts.map +1 -0
  653. package/utilities/common/compact.js +19 -0
  654. package/utilities/common/compact.js.map +1 -0
  655. package/utilities/common/errorHandling.d.ts +4 -0
  656. package/utilities/common/errorHandling.d.ts.map +1 -0
  657. package/utilities/common/errorHandling.js +21 -0
  658. package/utilities/common/errorHandling.js.map +1 -0
  659. package/utilities/common/filterInPlace.d.ts +2 -0
  660. package/utilities/common/filterInPlace.d.ts.map +1 -0
  661. package/utilities/common/filterInPlace.js +11 -0
  662. package/utilities/common/filterInPlace.js.map +1 -0
  663. package/utilities/common/incrementalResult.d.ts +6 -0
  664. package/utilities/common/incrementalResult.d.ts.map +1 -0
  665. package/utilities/common/incrementalResult.js +32 -0
  666. package/utilities/common/incrementalResult.js.map +1 -0
  667. package/utilities/common/makeUniqueId.d.ts +2 -0
  668. package/utilities/common/makeUniqueId.d.ts.map +1 -0
  669. package/utilities/common/makeUniqueId.js +7 -0
  670. package/utilities/common/makeUniqueId.js.map +1 -0
  671. package/utilities/common/maybeDeepFreeze.d.ts +2 -0
  672. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -0
  673. package/utilities/common/maybeDeepFreeze.js +34 -0
  674. package/utilities/common/maybeDeepFreeze.js.map +1 -0
  675. package/utilities/common/mergeDeep.d.ts +14 -0
  676. package/utilities/common/mergeDeep.d.ts.map +1 -0
  677. package/utilities/common/mergeDeep.js +76 -0
  678. package/utilities/common/mergeDeep.js.map +1 -0
  679. package/utilities/common/mergeOptions.d.ts +5 -0
  680. package/utilities/common/mergeOptions.d.ts.map +1 -0
  681. package/utilities/common/mergeOptions.js +8 -0
  682. package/utilities/common/mergeOptions.js.map +1 -0
  683. package/utilities/common/objects.d.ts +2 -0
  684. package/utilities/common/objects.d.ts.map +1 -0
  685. package/utilities/common/objects.js +4 -0
  686. package/utilities/common/objects.js.map +1 -0
  687. package/utilities/common/responseIterator.d.ts +10 -0
  688. package/utilities/common/responseIterator.d.ts.map +1 -0
  689. package/utilities/common/responseIterator.js +21 -0
  690. package/utilities/common/responseIterator.js.map +1 -0
  691. package/utilities/common/stringifyForDisplay.d.ts +2 -0
  692. package/utilities/common/stringifyForDisplay.d.ts.map +1 -0
  693. package/utilities/common/stringifyForDisplay.js +8 -0
  694. package/utilities/common/stringifyForDisplay.js.map +1 -0
  695. package/utilities/globals/DEV.d.ts +3 -0
  696. package/utilities/globals/DEV.d.ts.map +1 -0
  697. package/utilities/globals/DEV.js +9 -0
  698. package/utilities/globals/DEV.js.map +1 -0
  699. package/utilities/globals/fix-graphql.d.ts +2 -0
  700. package/utilities/globals/fix-graphql.d.ts.map +1 -0
  701. package/utilities/globals/fix-graphql.js +6 -0
  702. package/utilities/globals/fix-graphql.js.map +1 -0
  703. package/utilities/globals/global.d.ts +5 -0
  704. package/utilities/globals/global.d.ts.map +1 -0
  705. package/utilities/globals/global.js +6 -0
  706. package/utilities/globals/global.js.map +1 -0
  707. package/utilities/globals/globals.cjs +42 -0
  708. package/utilities/globals/globals.cjs.map +1 -0
  709. package/utilities/globals/globals.cjs.native.js +42 -0
  710. package/utilities/globals/index.d.ts +8 -0
  711. package/utilities/globals/index.d.ts.map +1 -0
  712. package/utilities/globals/index.js +10 -0
  713. package/utilities/globals/index.js.map +1 -0
  714. package/utilities/globals/maybe.d.ts +2 -0
  715. package/utilities/globals/maybe.d.ts.map +1 -0
  716. package/utilities/globals/maybe.js +7 -0
  717. package/utilities/globals/maybe.js.map +1 -0
  718. package/utilities/globals/package.json +8 -0
  719. package/utilities/graphql/directives.d.ts +18 -0
  720. package/utilities/graphql/directives.d.ts.map +1 -0
  721. package/utilities/graphql/directives.js +72 -0
  722. package/utilities/graphql/directives.js.map +1 -0
  723. package/utilities/graphql/fragments.d.ts +9 -0
  724. package/utilities/graphql/fragments.d.ts.map +1 -0
  725. package/utilities/graphql/fragments.js +64 -0
  726. package/utilities/graphql/fragments.js.map +1 -0
  727. package/utilities/graphql/getFromAST.d.ts +10 -0
  728. package/utilities/graphql/getFromAST.d.ts.map +1 -0
  729. package/utilities/graphql/getFromAST.js +76 -0
  730. package/utilities/graphql/getFromAST.js.map +1 -0
  731. package/utilities/graphql/storeUtils.d.ts +32 -0
  732. package/utilities/graphql/storeUtils.d.ts.map +1 -0
  733. package/utilities/graphql/storeUtils.js +208 -0
  734. package/utilities/graphql/storeUtils.js.map +1 -0
  735. package/utilities/graphql/transform.d.ts +27 -0
  736. package/utilities/graphql/transform.d.ts.map +1 -0
  737. package/utilities/graphql/transform.js +281 -0
  738. package/utilities/graphql/transform.js.map +1 -0
  739. package/utilities/index.d.ts +27 -0
  740. package/utilities/index.d.ts.map +1 -0
  741. package/utilities/index.js +27 -0
  742. package/utilities/index.js.map +1 -0
  743. package/utilities/observables/Concast.d.ts +27 -0
  744. package/utilities/observables/Concast.d.ts.map +1 -0
  745. package/utilities/observables/Concast.js +137 -0
  746. package/utilities/observables/Concast.js.map +1 -0
  747. package/utilities/observables/Observable.d.ts +5 -0
  748. package/utilities/observables/Observable.d.ts.map +1 -0
  749. package/utilities/observables/Observable.js +9 -0
  750. package/utilities/observables/Observable.js.map +1 -0
  751. package/utilities/observables/asyncMap.d.ts +3 -0
  752. package/utilities/observables/asyncMap.d.ts.map +1 -0
  753. package/utilities/observables/asyncMap.js +49 -0
  754. package/utilities/observables/asyncMap.js.map +1 -0
  755. package/utilities/observables/iteration.d.ts +3 -0
  756. package/utilities/observables/iteration.d.ts.map +1 -0
  757. package/utilities/observables/iteration.js +6 -0
  758. package/utilities/observables/iteration.js.map +1 -0
  759. package/utilities/observables/subclassing.d.ts +3 -0
  760. package/utilities/observables/subclassing.d.ts.map +1 -0
  761. package/utilities/observables/subclassing.js +13 -0
  762. package/utilities/observables/subclassing.js.map +1 -0
  763. package/utilities/package.json +8 -0
  764. package/utilities/policies/pagination.d.ts +28 -0
  765. package/utilities/policies/pagination.d.ts.map +1 -0
  766. package/utilities/policies/pagination.js +151 -0
  767. package/utilities/policies/pagination.js.map +1 -0
  768. package/utilities/types/IsStrictlyAny.d.ts +5 -0
  769. package/utilities/types/IsStrictlyAny.d.ts.map +1 -0
  770. package/utilities/types/IsStrictlyAny.js +2 -0
  771. package/utilities/types/IsStrictlyAny.js.map +1 -0
  772. package/utilities/utilities.cjs +1371 -0
  773. package/utilities/utilities.cjs.map +1 -0
  774. package/utilities/utilities.cjs.native.js +1371 -0
  775. package/version.d.ts +2 -0
  776. package/version.d.ts.map +1 -0
  777. package/version.js +2 -0
  778. package/version.js.map +1 -0
@@ -0,0 +1,2349 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var globals = require('../utilities/globals');
6
+ var tslib = require('tslib');
7
+ var core = require('../link/core');
8
+ var http = require('../link/http');
9
+ var equality = require('@wry/equality');
10
+ var utilities = require('../utilities');
11
+ var cache = require('../cache');
12
+ var errors = require('../errors');
13
+ var graphql = require('graphql');
14
+ var utils = require('../link/utils');
15
+ var tsInvariant = require('ts-invariant');
16
+ var graphqlTag = require('graphql-tag');
17
+
18
+ var version = '0.0.0-pr-10521-20230206180228';
19
+
20
+ function isNonEmptyArray(value) {
21
+ return Array.isArray(value) && value.length > 0;
22
+ }
23
+
24
+ function isNonNullObject(obj) {
25
+ return obj !== null && typeof obj === 'object';
26
+ }
27
+
28
+ var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
29
+ var defaultReconciler = function (target, source, property) {
30
+ return this.merge(target[property], source[property]);
31
+ };
32
+ var DeepMerger = (function () {
33
+ function DeepMerger(reconciler) {
34
+ if (reconciler === void 0) { reconciler = defaultReconciler; }
35
+ this.reconciler = reconciler;
36
+ this.isObject = isNonNullObject;
37
+ this.pastCopies = new Set();
38
+ }
39
+ DeepMerger.prototype.merge = function (target, source) {
40
+ var _this = this;
41
+ var context = [];
42
+ for (var _i = 2; _i < arguments.length; _i++) {
43
+ context[_i - 2] = arguments[_i];
44
+ }
45
+ if (isNonNullObject(source) && isNonNullObject(target)) {
46
+ Object.keys(source).forEach(function (sourceKey) {
47
+ if (hasOwnProperty$2.call(target, sourceKey)) {
48
+ var targetValue = target[sourceKey];
49
+ if (source[sourceKey] !== targetValue) {
50
+ var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
51
+ if (result !== targetValue) {
52
+ target = _this.shallowCopyForMerge(target);
53
+ target[sourceKey] = result;
54
+ }
55
+ }
56
+ }
57
+ else {
58
+ target = _this.shallowCopyForMerge(target);
59
+ target[sourceKey] = source[sourceKey];
60
+ }
61
+ });
62
+ return target;
63
+ }
64
+ return source;
65
+ };
66
+ DeepMerger.prototype.shallowCopyForMerge = function (value) {
67
+ if (isNonNullObject(value)) {
68
+ if (!this.pastCopies.has(value)) {
69
+ if (Array.isArray(value)) {
70
+ value = value.slice(0);
71
+ }
72
+ else {
73
+ value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
74
+ }
75
+ this.pastCopies.add(value);
76
+ }
77
+ }
78
+ return value;
79
+ };
80
+ return DeepMerger;
81
+ }());
82
+
83
+ function isExecutionPatchIncrementalResult(value) {
84
+ return "incremental" in value;
85
+ }
86
+ function mergeIncrementalData(prevResult, result) {
87
+ var mergedData = prevResult;
88
+ var merger = new DeepMerger();
89
+ if (isExecutionPatchIncrementalResult(result) &&
90
+ isNonEmptyArray(result.incremental)) {
91
+ result.incremental.forEach(function (_a) {
92
+ var data = _a.data, path = _a.path;
93
+ for (var i = path.length - 1; i >= 0; --i) {
94
+ var key = path[i];
95
+ var isNumericKey = !isNaN(+key);
96
+ var parent_1 = isNumericKey ? [] : {};
97
+ parent_1[key] = data;
98
+ data = parent_1;
99
+ }
100
+ mergedData = merger.merge(mergedData, data);
101
+ });
102
+ }
103
+ return mergedData;
104
+ }
105
+
106
+ exports.NetworkStatus = void 0;
107
+ (function (NetworkStatus) {
108
+ NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
109
+ NetworkStatus[NetworkStatus["setVariables"] = 2] = "setVariables";
110
+ NetworkStatus[NetworkStatus["fetchMore"] = 3] = "fetchMore";
111
+ NetworkStatus[NetworkStatus["refetch"] = 4] = "refetch";
112
+ NetworkStatus[NetworkStatus["poll"] = 6] = "poll";
113
+ NetworkStatus[NetworkStatus["ready"] = 7] = "ready";
114
+ NetworkStatus[NetworkStatus["error"] = 8] = "error";
115
+ })(exports.NetworkStatus || (exports.NetworkStatus = {}));
116
+ function isNetworkRequestInFlight(networkStatus) {
117
+ return networkStatus ? networkStatus < 7 : false;
118
+ }
119
+
120
+ var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
121
+ var ObservableQuery = (function (_super) {
122
+ tslib.__extends(ObservableQuery, _super);
123
+ function ObservableQuery(_a) {
124
+ var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
125
+ var _this = _super.call(this, function (observer) {
126
+ var _a = options.fetchOnFirstSubscribe, fetchOnFirstSubscribe = _a === void 0 ? true : _a;
127
+ try {
128
+ var subObserver = observer._subscription._observer;
129
+ if (subObserver && !subObserver.error) {
130
+ subObserver.error = defaultSubscriptionObserverErrorCallback;
131
+ }
132
+ }
133
+ catch (_b) { }
134
+ var first = !_this.observers.size;
135
+ _this.observers.add(observer);
136
+ var last = _this.last;
137
+ if (last && last.error) {
138
+ observer.error && observer.error(last.error);
139
+ }
140
+ else if (last && last.result) {
141
+ observer.next && observer.next(last.result);
142
+ }
143
+ if (first && fetchOnFirstSubscribe) {
144
+ _this.reobserve().catch(function () { });
145
+ }
146
+ return function () {
147
+ if (_this.observers.delete(observer) && !_this.observers.size) {
148
+ _this.tearDownQuery();
149
+ }
150
+ };
151
+ }) || this;
152
+ _this.observers = new Set();
153
+ _this.subscriptions = new Set();
154
+ _this.queryInfo = queryInfo;
155
+ _this.queryManager = queryManager;
156
+ _this.isTornDown = false;
157
+ var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
158
+ var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
159
+ _this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
160
+ _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
161
+ var opDef = utilities.getOperationDefinition(_this.query);
162
+ _this.queryName = opDef && opDef.name && opDef.name.value;
163
+ return _this;
164
+ }
165
+ Object.defineProperty(ObservableQuery.prototype, "query", {
166
+ get: function () {
167
+ return this.queryManager.transform(this.options.query).document;
168
+ },
169
+ enumerable: false,
170
+ configurable: true
171
+ });
172
+ Object.defineProperty(ObservableQuery.prototype, "variables", {
173
+ get: function () {
174
+ return this.options.variables;
175
+ },
176
+ enumerable: false,
177
+ configurable: true
178
+ });
179
+ ObservableQuery.prototype.result = function () {
180
+ var _this = this;
181
+ return new Promise(function (resolve, reject) {
182
+ var observer = {
183
+ next: function (result) {
184
+ resolve(result);
185
+ _this.observers.delete(observer);
186
+ if (!_this.observers.size) {
187
+ _this.queryManager.removeQuery(_this.queryId);
188
+ }
189
+ setTimeout(function () {
190
+ subscription.unsubscribe();
191
+ }, 0);
192
+ },
193
+ error: reject,
194
+ };
195
+ var subscription = _this.subscribe(observer);
196
+ });
197
+ };
198
+ ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
199
+ if (saveAsLastResult === void 0) { saveAsLastResult = true; }
200
+ var lastResult = this.getLastResult(true);
201
+ var networkStatus = this.queryInfo.networkStatus ||
202
+ (lastResult && lastResult.networkStatus) ||
203
+ exports.NetworkStatus.ready;
204
+ var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
205
+ var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
206
+ if (fetchPolicy === 'network-only' ||
207
+ fetchPolicy === 'no-cache' ||
208
+ fetchPolicy === 'standby' ||
209
+ this.queryManager.transform(this.options.query).hasForcedResolvers) ;
210
+ else {
211
+ var diff = this.queryInfo.getDiff();
212
+ if (diff.complete || this.options.returnPartialData) {
213
+ result.data = diff.result;
214
+ }
215
+ if (equality.equal(result.data, {})) {
216
+ result.data = void 0;
217
+ }
218
+ if (diff.complete) {
219
+ delete result.partial;
220
+ if (diff.complete &&
221
+ result.networkStatus === exports.NetworkStatus.loading &&
222
+ (fetchPolicy === 'cache-first' ||
223
+ fetchPolicy === 'cache-only')) {
224
+ result.networkStatus = exports.NetworkStatus.ready;
225
+ result.loading = false;
226
+ }
227
+ }
228
+ else {
229
+ result.partial = true;
230
+ }
231
+ if (globals.__DEV__ &&
232
+ !diff.complete &&
233
+ !this.options.partialRefetch &&
234
+ !result.loading &&
235
+ !result.data &&
236
+ !result.error) {
237
+ logMissingFieldErrors(diff.missing);
238
+ }
239
+ }
240
+ if (saveAsLastResult) {
241
+ this.updateLastResult(result);
242
+ }
243
+ return result;
244
+ };
245
+ ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
246
+ return (!this.last ||
247
+ !equality.equal(this.last.result, newResult) ||
248
+ (variables && !equality.equal(this.last.variables, variables)));
249
+ };
250
+ ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
251
+ var last = this.last;
252
+ if (last &&
253
+ last[key] &&
254
+ (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
255
+ return last[key];
256
+ }
257
+ };
258
+ ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
259
+ return this.getLast("result", variablesMustMatch);
260
+ };
261
+ ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
262
+ return this.getLast("error", variablesMustMatch);
263
+ };
264
+ ObservableQuery.prototype.resetLastResults = function () {
265
+ delete this.last;
266
+ this.isTornDown = false;
267
+ };
268
+ ObservableQuery.prototype.resetQueryStoreErrors = function () {
269
+ this.queryManager.resetErrors(this.queryId);
270
+ };
271
+ ObservableQuery.prototype.refetch = function (variables) {
272
+ var _a;
273
+ var reobserveOptions = {
274
+ pollInterval: 0,
275
+ };
276
+ var fetchPolicy = this.options.fetchPolicy;
277
+ if (fetchPolicy === 'cache-and-network') {
278
+ reobserveOptions.fetchPolicy = fetchPolicy;
279
+ }
280
+ else if (fetchPolicy === 'no-cache') {
281
+ reobserveOptions.fetchPolicy = 'no-cache';
282
+ }
283
+ else {
284
+ reobserveOptions.fetchPolicy = 'network-only';
285
+ }
286
+ if (globals.__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
287
+ var queryDef = utilities.getQueryDefinition(this.query);
288
+ var vars = queryDef.variableDefinitions;
289
+ if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
290
+ globals.__DEV__ && globals.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 })?"));
291
+ }
292
+ }
293
+ if (variables && !equality.equal(this.options.variables, variables)) {
294
+ reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
295
+ }
296
+ this.queryInfo.resetLastWrite();
297
+ return this.reobserve(reobserveOptions, exports.NetworkStatus.refetch);
298
+ };
299
+ ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
300
+ var _this = this;
301
+ var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
302
+ var qid = this.queryManager.generateQueryId();
303
+ var queryInfo = this.queryInfo;
304
+ var originalNetworkStatus = queryInfo.networkStatus;
305
+ queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
306
+ if (combinedOptions.notifyOnNetworkStatusChange) {
307
+ this.observe();
308
+ }
309
+ var updatedQuerySet = new Set();
310
+ return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
311
+ _this.queryManager.removeQuery(qid);
312
+ if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
313
+ queryInfo.networkStatus = originalNetworkStatus;
314
+ }
315
+ _this.queryManager.cache.batch({
316
+ update: function (cache) {
317
+ var updateQuery = fetchMoreOptions.updateQuery;
318
+ if (updateQuery) {
319
+ cache.updateQuery({
320
+ query: _this.query,
321
+ variables: _this.variables,
322
+ returnPartialData: true,
323
+ optimistic: false,
324
+ }, function (previous) { return updateQuery(previous, {
325
+ fetchMoreResult: fetchMoreResult.data,
326
+ variables: combinedOptions.variables,
327
+ }); });
328
+ }
329
+ else {
330
+ cache.writeQuery({
331
+ query: combinedOptions.query,
332
+ variables: combinedOptions.variables,
333
+ data: fetchMoreResult.data,
334
+ });
335
+ }
336
+ },
337
+ onWatchUpdated: function (watch) {
338
+ updatedQuerySet.add(watch.query);
339
+ },
340
+ });
341
+ return fetchMoreResult;
342
+ }).finally(function () {
343
+ if (!updatedQuerySet.has(_this.query)) {
344
+ reobserveCacheFirst(_this);
345
+ }
346
+ });
347
+ };
348
+ ObservableQuery.prototype.subscribeToMore = function (options) {
349
+ var _this = this;
350
+ var subscription = this.queryManager
351
+ .startGraphQLSubscription({
352
+ query: options.document,
353
+ variables: options.variables,
354
+ context: options.context,
355
+ })
356
+ .subscribe({
357
+ next: function (subscriptionData) {
358
+ var updateQuery = options.updateQuery;
359
+ if (updateQuery) {
360
+ _this.updateQuery(function (previous, _a) {
361
+ var variables = _a.variables;
362
+ return updateQuery(previous, {
363
+ subscriptionData: subscriptionData,
364
+ variables: variables,
365
+ });
366
+ });
367
+ }
368
+ },
369
+ error: function (err) {
370
+ if (options.onError) {
371
+ options.onError(err);
372
+ return;
373
+ }
374
+ globals.__DEV__ && globals.invariant.error('Unhandled GraphQL subscription error', err);
375
+ },
376
+ });
377
+ this.subscriptions.add(subscription);
378
+ return function () {
379
+ if (_this.subscriptions.delete(subscription)) {
380
+ subscription.unsubscribe();
381
+ }
382
+ };
383
+ };
384
+ ObservableQuery.prototype.setOptions = function (newOptions) {
385
+ return this.reobserve(newOptions);
386
+ };
387
+ ObservableQuery.prototype.setVariables = function (variables) {
388
+ if (equality.equal(this.variables, variables)) {
389
+ return this.observers.size
390
+ ? this.result()
391
+ : Promise.resolve();
392
+ }
393
+ this.options.variables = variables;
394
+ if (!this.observers.size) {
395
+ return Promise.resolve();
396
+ }
397
+ return this.reobserve({
398
+ fetchPolicy: this.options.initialFetchPolicy,
399
+ variables: variables,
400
+ }, exports.NetworkStatus.setVariables);
401
+ };
402
+ ObservableQuery.prototype.updateQuery = function (mapFn) {
403
+ var queryManager = this.queryManager;
404
+ var result = queryManager.cache.diff({
405
+ query: this.options.query,
406
+ variables: this.variables,
407
+ returnPartialData: true,
408
+ optimistic: false,
409
+ }).result;
410
+ var newResult = mapFn(result, {
411
+ variables: this.variables,
412
+ });
413
+ if (newResult) {
414
+ queryManager.cache.writeQuery({
415
+ query: this.options.query,
416
+ data: newResult,
417
+ variables: this.variables,
418
+ });
419
+ queryManager.broadcastQueries();
420
+ }
421
+ };
422
+ ObservableQuery.prototype.startPolling = function (pollInterval) {
423
+ this.options.pollInterval = pollInterval;
424
+ this.updatePolling();
425
+ };
426
+ ObservableQuery.prototype.stopPolling = function () {
427
+ this.options.pollInterval = 0;
428
+ this.updatePolling();
429
+ };
430
+ ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
431
+ if (options.nextFetchPolicy) {
432
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
433
+ if (fetchPolicy === "standby") ;
434
+ else if (typeof options.nextFetchPolicy === "function") {
435
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
436
+ reason: reason,
437
+ options: options,
438
+ observable: this,
439
+ initialFetchPolicy: initialFetchPolicy,
440
+ });
441
+ }
442
+ else if (reason === "variables-changed") {
443
+ options.fetchPolicy = initialFetchPolicy;
444
+ }
445
+ else {
446
+ options.fetchPolicy = options.nextFetchPolicy;
447
+ }
448
+ }
449
+ return options.fetchPolicy;
450
+ };
451
+ ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
452
+ this.queryManager.setObservableQuery(this);
453
+ return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
454
+ };
455
+ ObservableQuery.prototype.updatePolling = function () {
456
+ var _this = this;
457
+ if (this.queryManager.ssrMode) {
458
+ return;
459
+ }
460
+ var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
461
+ if (!pollInterval) {
462
+ if (pollingInfo) {
463
+ clearTimeout(pollingInfo.timeout);
464
+ delete this.pollingInfo;
465
+ }
466
+ return;
467
+ }
468
+ if (pollingInfo &&
469
+ pollingInfo.interval === pollInterval) {
470
+ return;
471
+ }
472
+ globals.__DEV__ ? globals.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : globals.invariant(pollInterval, 13);
473
+ var info = pollingInfo || (this.pollingInfo = {});
474
+ info.interval = pollInterval;
475
+ var maybeFetch = function () {
476
+ if (_this.pollingInfo) {
477
+ if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus)) {
478
+ _this.reobserve({
479
+ fetchPolicy: _this.options.initialFetchPolicy === 'no-cache' ? 'no-cache' : 'network-only',
480
+ }, exports.NetworkStatus.poll).then(poll, poll);
481
+ }
482
+ else {
483
+ poll();
484
+ }
485
+ }
486
+ };
487
+ var poll = function () {
488
+ var info = _this.pollingInfo;
489
+ if (info) {
490
+ clearTimeout(info.timeout);
491
+ info.timeout = setTimeout(maybeFetch, info.interval);
492
+ }
493
+ };
494
+ poll();
495
+ };
496
+ ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
497
+ if (variables === void 0) { variables = this.variables; }
498
+ this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
499
+ ? newResult
500
+ : utilities.cloneDeep(newResult), variables: variables });
501
+ if (!utilities.isNonEmptyArray(newResult.errors)) {
502
+ delete this.last.error;
503
+ }
504
+ return this.last;
505
+ };
506
+ ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
507
+ var _this = this;
508
+ this.isTornDown = false;
509
+ var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
510
+ newNetworkStatus === exports.NetworkStatus.fetchMore ||
511
+ newNetworkStatus === exports.NetworkStatus.poll;
512
+ var oldVariables = this.options.variables;
513
+ var oldFetchPolicy = this.options.fetchPolicy;
514
+ var mergedOptions = utilities.compact(this.options, newOptions || {});
515
+ var options = useDisposableConcast
516
+ ? mergedOptions
517
+ : assign(this.options, mergedOptions);
518
+ if (!useDisposableConcast) {
519
+ this.updatePolling();
520
+ if (newOptions &&
521
+ newOptions.variables &&
522
+ !equality.equal(newOptions.variables, oldVariables) &&
523
+ options.fetchPolicy !== "standby" &&
524
+ options.fetchPolicy === oldFetchPolicy) {
525
+ this.applyNextFetchPolicy("variables-changed", options);
526
+ if (newNetworkStatus === void 0) {
527
+ newNetworkStatus = exports.NetworkStatus.setVariables;
528
+ }
529
+ }
530
+ }
531
+ var variables = options.variables && tslib.__assign({}, options.variables);
532
+ var concast = this.fetch(options, newNetworkStatus);
533
+ var observer = {
534
+ next: function (result) {
535
+ _this.reportResult(result, variables);
536
+ },
537
+ error: function (error) {
538
+ _this.reportError(error, variables);
539
+ },
540
+ };
541
+ if (!useDisposableConcast) {
542
+ if (this.concast && this.observer) {
543
+ this.concast.removeObserver(this.observer);
544
+ }
545
+ this.concast = concast;
546
+ this.observer = observer;
547
+ }
548
+ concast.addObserver(observer);
549
+ return concast;
550
+ };
551
+ ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
552
+ return this.reobserveAsConcast(newOptions, newNetworkStatus).promise;
553
+ };
554
+ ObservableQuery.prototype.observe = function () {
555
+ this.reportResult(this.getCurrentResult(false), this.variables);
556
+ };
557
+ ObservableQuery.prototype.reportResult = function (result, variables) {
558
+ var lastError = this.getLastError();
559
+ if (lastError || this.isDifferentFromLastResult(result, variables)) {
560
+ if (lastError || !result.partial || this.options.returnPartialData) {
561
+ this.updateLastResult(result, variables);
562
+ }
563
+ utilities.iterateObserversSafely(this.observers, 'next', result);
564
+ }
565
+ };
566
+ ObservableQuery.prototype.reportError = function (error, variables) {
567
+ var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
568
+ this.updateLastResult(errorResult, variables);
569
+ utilities.iterateObserversSafely(this.observers, 'error', this.last.error = error);
570
+ };
571
+ ObservableQuery.prototype.hasObservers = function () {
572
+ return this.observers.size > 0;
573
+ };
574
+ ObservableQuery.prototype.tearDownQuery = function () {
575
+ if (this.isTornDown)
576
+ return;
577
+ if (this.concast && this.observer) {
578
+ this.concast.removeObserver(this.observer);
579
+ delete this.concast;
580
+ delete this.observer;
581
+ }
582
+ this.stopPolling();
583
+ this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
584
+ this.subscriptions.clear();
585
+ this.queryManager.stopQuery(this.queryId);
586
+ this.observers.clear();
587
+ this.isTornDown = true;
588
+ };
589
+ return ObservableQuery;
590
+ }(utilities.Observable));
591
+ utilities.fixObservableSubclass(ObservableQuery);
592
+ function reobserveCacheFirst(obsQuery) {
593
+ var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
594
+ if (fetchPolicy === "cache-and-network" ||
595
+ fetchPolicy === "network-only") {
596
+ return obsQuery.reobserve({
597
+ fetchPolicy: "cache-first",
598
+ nextFetchPolicy: function () {
599
+ this.nextFetchPolicy = nextFetchPolicy;
600
+ if (typeof nextFetchPolicy === "function") {
601
+ return nextFetchPolicy.apply(this, arguments);
602
+ }
603
+ return fetchPolicy;
604
+ },
605
+ });
606
+ }
607
+ return obsQuery.reobserve();
608
+ }
609
+ function defaultSubscriptionObserverErrorCallback(error) {
610
+ globals.__DEV__ && globals.invariant.error('Unhandled error', error.message, error.stack);
611
+ }
612
+ function logMissingFieldErrors(missing) {
613
+ if (globals.__DEV__ && missing) {
614
+ globals.__DEV__ && globals.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
615
+ }
616
+ }
617
+
618
+ var LocalState = (function () {
619
+ function LocalState(_a) {
620
+ var cache = _a.cache, client = _a.client, resolvers = _a.resolvers, fragmentMatcher = _a.fragmentMatcher;
621
+ this.selectionsToResolveCache = new WeakMap();
622
+ this.cache = cache;
623
+ if (client) {
624
+ this.client = client;
625
+ }
626
+ if (resolvers) {
627
+ this.addResolvers(resolvers);
628
+ }
629
+ if (fragmentMatcher) {
630
+ this.setFragmentMatcher(fragmentMatcher);
631
+ }
632
+ }
633
+ LocalState.prototype.addResolvers = function (resolvers) {
634
+ var _this = this;
635
+ this.resolvers = this.resolvers || {};
636
+ if (Array.isArray(resolvers)) {
637
+ resolvers.forEach(function (resolverGroup) {
638
+ _this.resolvers = utilities.mergeDeep(_this.resolvers, resolverGroup);
639
+ });
640
+ }
641
+ else {
642
+ this.resolvers = utilities.mergeDeep(this.resolvers, resolvers);
643
+ }
644
+ };
645
+ LocalState.prototype.setResolvers = function (resolvers) {
646
+ this.resolvers = {};
647
+ this.addResolvers(resolvers);
648
+ };
649
+ LocalState.prototype.getResolvers = function () {
650
+ return this.resolvers || {};
651
+ };
652
+ LocalState.prototype.runResolvers = function (_a) {
653
+ var document = _a.document, remoteResult = _a.remoteResult, context = _a.context, variables = _a.variables, _b = _a.onlyRunForcedResolvers, onlyRunForcedResolvers = _b === void 0 ? false : _b;
654
+ return tslib.__awaiter(this, void 0, void 0, function () {
655
+ return tslib.__generator(this, function (_c) {
656
+ if (document) {
657
+ return [2, this.resolveDocument(document, remoteResult.data, context, variables, this.fragmentMatcher, onlyRunForcedResolvers).then(function (localResult) { return (tslib.__assign(tslib.__assign({}, remoteResult), { data: localResult.result })); })];
658
+ }
659
+ return [2, remoteResult];
660
+ });
661
+ });
662
+ };
663
+ LocalState.prototype.setFragmentMatcher = function (fragmentMatcher) {
664
+ this.fragmentMatcher = fragmentMatcher;
665
+ };
666
+ LocalState.prototype.getFragmentMatcher = function () {
667
+ return this.fragmentMatcher;
668
+ };
669
+ LocalState.prototype.clientQuery = function (document) {
670
+ if (utilities.hasDirectives(['client'], document)) {
671
+ if (this.resolvers) {
672
+ return document;
673
+ }
674
+ }
675
+ return null;
676
+ };
677
+ LocalState.prototype.serverQuery = function (document, options) {
678
+ if (options === void 0) { options = Object.create(null); }
679
+ var _a = options.removeClientFields, removeClientFields = _a === void 0 ? true : _a;
680
+ return removeClientFields
681
+ ? utilities.removeClientSetsFromDocument(document)
682
+ : document;
683
+ };
684
+ LocalState.prototype.prepareContext = function (context) {
685
+ var cache = this.cache;
686
+ return tslib.__assign(tslib.__assign({}, context), { cache: cache, getCacheKey: function (obj) {
687
+ return cache.identify(obj);
688
+ } });
689
+ };
690
+ LocalState.prototype.addExportedVariables = function (document, variables, context) {
691
+ if (variables === void 0) { variables = {}; }
692
+ if (context === void 0) { context = {}; }
693
+ return tslib.__awaiter(this, void 0, void 0, function () {
694
+ return tslib.__generator(this, function (_a) {
695
+ if (document) {
696
+ return [2, this.resolveDocument(document, this.buildRootValueFromCache(document, variables) || {}, this.prepareContext(context), variables).then(function (data) { return (tslib.__assign(tslib.__assign({}, variables), data.exportedVariables)); })];
697
+ }
698
+ return [2, tslib.__assign({}, variables)];
699
+ });
700
+ });
701
+ };
702
+ LocalState.prototype.shouldForceResolvers = function (document) {
703
+ var forceResolvers = false;
704
+ graphql.visit(document, {
705
+ Directive: {
706
+ enter: function (node) {
707
+ if (node.name.value === 'client' && node.arguments) {
708
+ forceResolvers = node.arguments.some(function (arg) {
709
+ return arg.name.value === 'always' &&
710
+ arg.value.kind === 'BooleanValue' &&
711
+ arg.value.value === true;
712
+ });
713
+ if (forceResolvers) {
714
+ return graphql.BREAK;
715
+ }
716
+ }
717
+ },
718
+ },
719
+ });
720
+ return forceResolvers;
721
+ };
722
+ LocalState.prototype.buildRootValueFromCache = function (document, variables) {
723
+ return this.cache.diff({
724
+ query: utilities.buildQueryFromSelectionSet(document),
725
+ variables: variables,
726
+ returnPartialData: true,
727
+ optimistic: false,
728
+ }).result;
729
+ };
730
+ LocalState.prototype.resolveDocument = function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
731
+ if (context === void 0) { context = {}; }
732
+ if (variables === void 0) { variables = {}; }
733
+ if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
734
+ if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
735
+ return tslib.__awaiter(this, void 0, void 0, function () {
736
+ var mainDefinition, fragments, fragmentMap, selectionsToResolve, definitionOperation, defaultOperationType, _a, cache, client, execContext, isClientFieldDescendant;
737
+ return tslib.__generator(this, function (_b) {
738
+ mainDefinition = utilities.getMainDefinition(document);
739
+ fragments = utilities.getFragmentDefinitions(document);
740
+ fragmentMap = utilities.createFragmentMap(fragments);
741
+ selectionsToResolve = this.collectSelectionsToResolve(mainDefinition, fragmentMap);
742
+ definitionOperation = mainDefinition.operation;
743
+ defaultOperationType = definitionOperation
744
+ ? definitionOperation.charAt(0).toUpperCase() +
745
+ definitionOperation.slice(1)
746
+ : 'Query';
747
+ _a = this, cache = _a.cache, client = _a.client;
748
+ execContext = {
749
+ fragmentMap: fragmentMap,
750
+ context: tslib.__assign(tslib.__assign({}, context), { cache: cache, client: client }),
751
+ variables: variables,
752
+ fragmentMatcher: fragmentMatcher,
753
+ defaultOperationType: defaultOperationType,
754
+ exportedVariables: {},
755
+ selectionsToResolve: selectionsToResolve,
756
+ onlyRunForcedResolvers: onlyRunForcedResolvers,
757
+ };
758
+ isClientFieldDescendant = false;
759
+ return [2, this.resolveSelectionSet(mainDefinition.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (result) { return ({
760
+ result: result,
761
+ exportedVariables: execContext.exportedVariables,
762
+ }); })];
763
+ });
764
+ });
765
+ };
766
+ LocalState.prototype.resolveSelectionSet = function (selectionSet, isClientFieldDescendant, rootValue, execContext) {
767
+ return tslib.__awaiter(this, void 0, void 0, function () {
768
+ var fragmentMap, context, variables, resultsToMerge, execute;
769
+ var _this = this;
770
+ return tslib.__generator(this, function (_a) {
771
+ fragmentMap = execContext.fragmentMap, context = execContext.context, variables = execContext.variables;
772
+ resultsToMerge = [rootValue];
773
+ execute = function (selection) { return tslib.__awaiter(_this, void 0, void 0, function () {
774
+ var fragment, typeCondition;
775
+ return tslib.__generator(this, function (_a) {
776
+ if (!isClientFieldDescendant && !execContext.selectionsToResolve.has(selection)) {
777
+ return [2];
778
+ }
779
+ if (!utilities.shouldInclude(selection, variables)) {
780
+ return [2];
781
+ }
782
+ if (utilities.isField(selection)) {
783
+ return [2, this.resolveField(selection, isClientFieldDescendant, rootValue, execContext).then(function (fieldResult) {
784
+ var _a;
785
+ if (typeof fieldResult !== 'undefined') {
786
+ resultsToMerge.push((_a = {},
787
+ _a[utilities.resultKeyNameFromField(selection)] = fieldResult,
788
+ _a));
789
+ }
790
+ })];
791
+ }
792
+ if (utilities.isInlineFragment(selection)) {
793
+ fragment = selection;
794
+ }
795
+ else {
796
+ fragment = fragmentMap[selection.name.value];
797
+ globals.__DEV__ ? globals.invariant(fragment, "No fragment named ".concat(selection.name.value)) : globals.invariant(fragment, 11);
798
+ }
799
+ if (fragment && fragment.typeCondition) {
800
+ typeCondition = fragment.typeCondition.name.value;
801
+ if (execContext.fragmentMatcher(rootValue, typeCondition, context)) {
802
+ return [2, this.resolveSelectionSet(fragment.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (fragmentResult) {
803
+ resultsToMerge.push(fragmentResult);
804
+ })];
805
+ }
806
+ }
807
+ return [2];
808
+ });
809
+ }); };
810
+ return [2, Promise.all(selectionSet.selections.map(execute)).then(function () {
811
+ return utilities.mergeDeepArray(resultsToMerge);
812
+ })];
813
+ });
814
+ });
815
+ };
816
+ LocalState.prototype.resolveField = function (field, isClientFieldDescendant, rootValue, execContext) {
817
+ return tslib.__awaiter(this, void 0, void 0, function () {
818
+ var variables, fieldName, aliasedFieldName, aliasUsed, defaultResult, resultPromise, resolverType, resolverMap, resolve;
819
+ var _this = this;
820
+ return tslib.__generator(this, function (_a) {
821
+ if (!rootValue) {
822
+ return [2, null];
823
+ }
824
+ variables = execContext.variables;
825
+ fieldName = field.name.value;
826
+ aliasedFieldName = utilities.resultKeyNameFromField(field);
827
+ aliasUsed = fieldName !== aliasedFieldName;
828
+ defaultResult = rootValue[aliasedFieldName] || rootValue[fieldName];
829
+ resultPromise = Promise.resolve(defaultResult);
830
+ if (!execContext.onlyRunForcedResolvers ||
831
+ this.shouldForceResolvers(field)) {
832
+ resolverType = rootValue.__typename || execContext.defaultOperationType;
833
+ resolverMap = this.resolvers && this.resolvers[resolverType];
834
+ if (resolverMap) {
835
+ resolve = resolverMap[aliasUsed ? fieldName : aliasedFieldName];
836
+ if (resolve) {
837
+ resultPromise = Promise.resolve(cache.cacheSlot.withValue(this.cache, resolve, [
838
+ rootValue,
839
+ utilities.argumentsObjectFromField(field, variables),
840
+ execContext.context,
841
+ { field: field, fragmentMap: execContext.fragmentMap },
842
+ ]));
843
+ }
844
+ }
845
+ }
846
+ return [2, resultPromise.then(function (result) {
847
+ var _a, _b;
848
+ if (result === void 0) { result = defaultResult; }
849
+ if (field.directives) {
850
+ field.directives.forEach(function (directive) {
851
+ if (directive.name.value === 'export' && directive.arguments) {
852
+ directive.arguments.forEach(function (arg) {
853
+ if (arg.name.value === 'as' && arg.value.kind === 'StringValue') {
854
+ execContext.exportedVariables[arg.value.value] = result;
855
+ }
856
+ });
857
+ }
858
+ });
859
+ }
860
+ if (!field.selectionSet) {
861
+ return result;
862
+ }
863
+ if (result == null) {
864
+ return result;
865
+ }
866
+ var isClientField = (_b = (_a = field.directives) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d.name.value === 'client'; })) !== null && _b !== void 0 ? _b : false;
867
+ if (Array.isArray(result)) {
868
+ return _this.resolveSubSelectedArray(field, isClientFieldDescendant || isClientField, result, execContext);
869
+ }
870
+ if (field.selectionSet) {
871
+ return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant || isClientField, result, execContext);
872
+ }
873
+ })];
874
+ });
875
+ });
876
+ };
877
+ LocalState.prototype.resolveSubSelectedArray = function (field, isClientFieldDescendant, result, execContext) {
878
+ var _this = this;
879
+ return Promise.all(result.map(function (item) {
880
+ if (item === null) {
881
+ return null;
882
+ }
883
+ if (Array.isArray(item)) {
884
+ return _this.resolveSubSelectedArray(field, isClientFieldDescendant, item, execContext);
885
+ }
886
+ if (field.selectionSet) {
887
+ return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant, item, execContext);
888
+ }
889
+ }));
890
+ };
891
+ LocalState.prototype.collectSelectionsToResolve = function (mainDefinition, fragmentMap) {
892
+ var isSingleASTNode = function (node) { return !Array.isArray(node); };
893
+ var selectionsToResolveCache = this.selectionsToResolveCache;
894
+ function collectByDefinition(definitionNode) {
895
+ if (!selectionsToResolveCache.has(definitionNode)) {
896
+ var matches_1 = new Set();
897
+ selectionsToResolveCache.set(definitionNode, matches_1);
898
+ graphql.visit(definitionNode, {
899
+ Directive: function (node, _, __, ___, ancestors) {
900
+ if (node.name.value === 'client') {
901
+ ancestors.forEach(function (node) {
902
+ if (isSingleASTNode(node) && graphql.isSelectionNode(node)) {
903
+ matches_1.add(node);
904
+ }
905
+ });
906
+ }
907
+ },
908
+ FragmentSpread: function (spread, _, __, ___, ancestors) {
909
+ var fragment = fragmentMap[spread.name.value];
910
+ globals.__DEV__ ? globals.invariant(fragment, "No fragment named ".concat(spread.name.value)) : globals.invariant(fragment, 12);
911
+ var fragmentSelections = collectByDefinition(fragment);
912
+ if (fragmentSelections.size > 0) {
913
+ ancestors.forEach(function (node) {
914
+ if (isSingleASTNode(node) && graphql.isSelectionNode(node)) {
915
+ matches_1.add(node);
916
+ }
917
+ });
918
+ matches_1.add(spread);
919
+ fragmentSelections.forEach(function (selection) {
920
+ matches_1.add(selection);
921
+ });
922
+ }
923
+ }
924
+ });
925
+ }
926
+ return selectionsToResolveCache.get(definitionNode);
927
+ }
928
+ return collectByDefinition(mainDefinition);
929
+ };
930
+ return LocalState;
931
+ }());
932
+
933
+ var destructiveMethodCounts = new (utilities.canUseWeakMap ? WeakMap : Map)();
934
+ function wrapDestructiveCacheMethod(cache, methodName) {
935
+ var original = cache[methodName];
936
+ if (typeof original === "function") {
937
+ cache[methodName] = function () {
938
+ destructiveMethodCounts.set(cache, (destructiveMethodCounts.get(cache) + 1) % 1e15);
939
+ return original.apply(this, arguments);
940
+ };
941
+ }
942
+ }
943
+ function cancelNotifyTimeout(info) {
944
+ if (info["notifyTimeout"]) {
945
+ clearTimeout(info["notifyTimeout"]);
946
+ info["notifyTimeout"] = void 0;
947
+ }
948
+ }
949
+ var QueryInfo = (function () {
950
+ function QueryInfo(queryManager, queryId) {
951
+ if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
952
+ this.queryId = queryId;
953
+ this.listeners = new Set();
954
+ this.document = null;
955
+ this.lastRequestId = 1;
956
+ this.subscriptions = new Set();
957
+ this.stopped = false;
958
+ this.dirty = false;
959
+ this.observableQuery = null;
960
+ var cache = this.cache = queryManager.cache;
961
+ if (!destructiveMethodCounts.has(cache)) {
962
+ destructiveMethodCounts.set(cache, 0);
963
+ wrapDestructiveCacheMethod(cache, "evict");
964
+ wrapDestructiveCacheMethod(cache, "modify");
965
+ wrapDestructiveCacheMethod(cache, "reset");
966
+ }
967
+ }
968
+ QueryInfo.prototype.init = function (query) {
969
+ var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
970
+ if (this.variables &&
971
+ this.networkStatus !== exports.NetworkStatus.loading &&
972
+ !equality.equal(this.variables, query.variables)) {
973
+ networkStatus = exports.NetworkStatus.setVariables;
974
+ }
975
+ if (!equality.equal(query.variables, this.variables)) {
976
+ this.lastDiff = void 0;
977
+ }
978
+ Object.assign(this, {
979
+ document: query.document,
980
+ variables: query.variables,
981
+ networkError: null,
982
+ graphQLErrors: this.graphQLErrors || [],
983
+ networkStatus: networkStatus,
984
+ });
985
+ if (query.observableQuery) {
986
+ this.setObservableQuery(query.observableQuery);
987
+ }
988
+ if (query.lastRequestId) {
989
+ this.lastRequestId = query.lastRequestId;
990
+ }
991
+ return this;
992
+ };
993
+ QueryInfo.prototype.reset = function () {
994
+ cancelNotifyTimeout(this);
995
+ this.dirty = false;
996
+ };
997
+ QueryInfo.prototype.getDiff = function (variables) {
998
+ if (variables === void 0) { variables = this.variables; }
999
+ var options = this.getDiffOptions(variables);
1000
+ if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
1001
+ return this.lastDiff.diff;
1002
+ }
1003
+ this.updateWatch(this.variables = variables);
1004
+ var oq = this.observableQuery;
1005
+ if (oq && oq.options.fetchPolicy === "no-cache") {
1006
+ return { complete: false };
1007
+ }
1008
+ var diff = this.cache.diff(options);
1009
+ this.updateLastDiff(diff, options);
1010
+ return diff;
1011
+ };
1012
+ QueryInfo.prototype.updateLastDiff = function (diff, options) {
1013
+ this.lastDiff = diff ? {
1014
+ diff: diff,
1015
+ options: options || this.getDiffOptions(),
1016
+ } : void 0;
1017
+ };
1018
+ QueryInfo.prototype.getDiffOptions = function (variables) {
1019
+ var _a;
1020
+ if (variables === void 0) { variables = this.variables; }
1021
+ return {
1022
+ query: this.document,
1023
+ variables: variables,
1024
+ returnPartialData: true,
1025
+ optimistic: true,
1026
+ canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
1027
+ };
1028
+ };
1029
+ QueryInfo.prototype.setDiff = function (diff) {
1030
+ var _this = this;
1031
+ var oldDiff = this.lastDiff && this.lastDiff.diff;
1032
+ this.updateLastDiff(diff);
1033
+ if (!this.dirty &&
1034
+ !equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
1035
+ this.dirty = true;
1036
+ if (!this.notifyTimeout) {
1037
+ this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
1038
+ }
1039
+ }
1040
+ };
1041
+ QueryInfo.prototype.setObservableQuery = function (oq) {
1042
+ var _this = this;
1043
+ if (oq === this.observableQuery)
1044
+ return;
1045
+ if (this.oqListener) {
1046
+ this.listeners.delete(this.oqListener);
1047
+ }
1048
+ this.observableQuery = oq;
1049
+ if (oq) {
1050
+ oq["queryInfo"] = this;
1051
+ this.listeners.add(this.oqListener = function () {
1052
+ var diff = _this.getDiff();
1053
+ if (diff.fromOptimisticTransaction) {
1054
+ oq["observe"]();
1055
+ }
1056
+ else {
1057
+ reobserveCacheFirst(oq);
1058
+ }
1059
+ });
1060
+ }
1061
+ else {
1062
+ delete this.oqListener;
1063
+ }
1064
+ };
1065
+ QueryInfo.prototype.notify = function () {
1066
+ var _this = this;
1067
+ cancelNotifyTimeout(this);
1068
+ if (this.shouldNotify()) {
1069
+ this.listeners.forEach(function (listener) { return listener(_this); });
1070
+ }
1071
+ this.dirty = false;
1072
+ };
1073
+ QueryInfo.prototype.shouldNotify = function () {
1074
+ if (!this.dirty || !this.listeners.size) {
1075
+ return false;
1076
+ }
1077
+ if (isNetworkRequestInFlight(this.networkStatus) &&
1078
+ this.observableQuery) {
1079
+ var fetchPolicy = this.observableQuery.options.fetchPolicy;
1080
+ if (fetchPolicy !== "cache-only" &&
1081
+ fetchPolicy !== "cache-and-network") {
1082
+ return false;
1083
+ }
1084
+ }
1085
+ return true;
1086
+ };
1087
+ QueryInfo.prototype.stop = function () {
1088
+ if (!this.stopped) {
1089
+ this.stopped = true;
1090
+ this.reset();
1091
+ this.cancel();
1092
+ this.cancel = QueryInfo.prototype.cancel;
1093
+ this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
1094
+ var oq = this.observableQuery;
1095
+ if (oq)
1096
+ oq.stopPolling();
1097
+ }
1098
+ };
1099
+ QueryInfo.prototype.cancel = function () { };
1100
+ QueryInfo.prototype.updateWatch = function (variables) {
1101
+ var _this = this;
1102
+ if (variables === void 0) { variables = this.variables; }
1103
+ var oq = this.observableQuery;
1104
+ if (oq && oq.options.fetchPolicy === "no-cache") {
1105
+ return;
1106
+ }
1107
+ var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
1108
+ if (!this.lastWatch ||
1109
+ !equality.equal(watchOptions, this.lastWatch)) {
1110
+ this.cancel();
1111
+ this.cancel = this.cache.watch(this.lastWatch = watchOptions);
1112
+ }
1113
+ };
1114
+ QueryInfo.prototype.resetLastWrite = function () {
1115
+ this.lastWrite = void 0;
1116
+ };
1117
+ QueryInfo.prototype.shouldWrite = function (result, variables) {
1118
+ var lastWrite = this.lastWrite;
1119
+ return !(lastWrite &&
1120
+ lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
1121
+ equality.equal(variables, lastWrite.variables) &&
1122
+ equality.equal(result.data, lastWrite.result.data));
1123
+ };
1124
+ QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
1125
+ var _this = this;
1126
+ var merger = new utilities.DeepMerger();
1127
+ var graphQLErrors = utilities.isNonEmptyArray(result.errors)
1128
+ ? result.errors.slice(0)
1129
+ : [];
1130
+ this.reset();
1131
+ if ('incremental' in result && utilities.isNonEmptyArray(result.incremental)) {
1132
+ var mergedData = utilities.mergeIncrementalData(this.getDiff().result, result);
1133
+ result.data = mergedData;
1134
+ }
1135
+ else if ('hasNext' in result && result.hasNext) {
1136
+ var diff = this.getDiff();
1137
+ result.data = merger.merge(diff.result, result.data);
1138
+ }
1139
+ this.graphQLErrors = graphQLErrors;
1140
+ if (options.fetchPolicy === 'no-cache') {
1141
+ this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
1142
+ }
1143
+ else if (cacheWriteBehavior !== 0) {
1144
+ if (shouldWriteResult(result, options.errorPolicy)) {
1145
+ this.cache.performTransaction(function (cache) {
1146
+ if (_this.shouldWrite(result, options.variables)) {
1147
+ cache.writeQuery({
1148
+ query: document,
1149
+ data: result.data,
1150
+ variables: options.variables,
1151
+ overwrite: cacheWriteBehavior === 1,
1152
+ });
1153
+ _this.lastWrite = {
1154
+ result: result,
1155
+ variables: options.variables,
1156
+ dmCount: destructiveMethodCounts.get(_this.cache),
1157
+ };
1158
+ }
1159
+ else {
1160
+ if (_this.lastDiff &&
1161
+ _this.lastDiff.diff.complete) {
1162
+ result.data = _this.lastDiff.diff.result;
1163
+ return;
1164
+ }
1165
+ }
1166
+ var diffOptions = _this.getDiffOptions(options.variables);
1167
+ var diff = cache.diff(diffOptions);
1168
+ if (!_this.stopped) {
1169
+ _this.updateWatch(options.variables);
1170
+ }
1171
+ _this.updateLastDiff(diff, diffOptions);
1172
+ if (diff.complete) {
1173
+ result.data = diff.result;
1174
+ }
1175
+ });
1176
+ }
1177
+ else {
1178
+ this.lastWrite = void 0;
1179
+ }
1180
+ }
1181
+ };
1182
+ QueryInfo.prototype.markReady = function () {
1183
+ this.networkError = null;
1184
+ return this.networkStatus = exports.NetworkStatus.ready;
1185
+ };
1186
+ QueryInfo.prototype.markError = function (error) {
1187
+ this.networkStatus = exports.NetworkStatus.error;
1188
+ this.lastWrite = void 0;
1189
+ this.reset();
1190
+ if (error.graphQLErrors) {
1191
+ this.graphQLErrors = error.graphQLErrors;
1192
+ }
1193
+ if (error.networkError) {
1194
+ this.networkError = error.networkError;
1195
+ }
1196
+ return error;
1197
+ };
1198
+ return QueryInfo;
1199
+ }());
1200
+ function shouldWriteResult(result, errorPolicy) {
1201
+ if (errorPolicy === void 0) { errorPolicy = "none"; }
1202
+ var ignoreErrors = errorPolicy === "ignore" ||
1203
+ errorPolicy === "all";
1204
+ var writeWithErrors = !utilities.graphQLResultHasError(result);
1205
+ if (!writeWithErrors && ignoreErrors && result.data) {
1206
+ writeWithErrors = true;
1207
+ }
1208
+ return writeWithErrors;
1209
+ }
1210
+
1211
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
1212
+ var QueryManager = (function () {
1213
+ function QueryManager(_a) {
1214
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
1215
+ this.clientAwareness = {};
1216
+ this.queries = new Map();
1217
+ this.fetchCancelFns = new Map();
1218
+ this.transformCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
1219
+ this.queryIdCounter = 1;
1220
+ this.requestIdCounter = 1;
1221
+ this.mutationIdCounter = 1;
1222
+ this.inFlightLinkObservables = new Map();
1223
+ this.cache = cache;
1224
+ this.link = link;
1225
+ this.defaultOptions = defaultOptions || Object.create(null);
1226
+ this.queryDeduplication = queryDeduplication;
1227
+ this.clientAwareness = clientAwareness;
1228
+ this.localState = localState || new LocalState({ cache: cache });
1229
+ this.ssrMode = ssrMode;
1230
+ this.assumeImmutableResults = !!assumeImmutableResults;
1231
+ if ((this.onBroadcast = onBroadcast)) {
1232
+ this.mutationStore = Object.create(null);
1233
+ }
1234
+ }
1235
+ QueryManager.prototype.stop = function () {
1236
+ var _this = this;
1237
+ this.queries.forEach(function (_info, queryId) {
1238
+ _this.stopQueryNoBroadcast(queryId);
1239
+ });
1240
+ this.cancelPendingFetches(globals.__DEV__ ? new globals.InvariantError('QueryManager stopped while query was in flight') : new globals.InvariantError(14));
1241
+ };
1242
+ QueryManager.prototype.cancelPendingFetches = function (error) {
1243
+ this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
1244
+ this.fetchCancelFns.clear();
1245
+ };
1246
+ QueryManager.prototype.mutate = function (_a) {
1247
+ var _b, _c;
1248
+ var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
1249
+ return tslib.__awaiter(this, void 0, void 0, function () {
1250
+ var mutationId, _h, document, hasClientExports, mutationStoreValue, self;
1251
+ return tslib.__generator(this, function (_j) {
1252
+ switch (_j.label) {
1253
+ case 0:
1254
+ globals.__DEV__ ? globals.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : globals.invariant(mutation, 15);
1255
+ globals.__DEV__ ? globals.invariant(fetchPolicy === 'network-only' ||
1256
+ 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.") : globals.invariant(fetchPolicy === 'network-only' ||
1257
+ fetchPolicy === 'no-cache', 16);
1258
+ mutationId = this.generateMutationId();
1259
+ _h = this.transform(mutation), document = _h.document, hasClientExports = _h.hasClientExports;
1260
+ mutation = this.cache.transformForLink(document);
1261
+ variables = this.getVariables(mutation, variables);
1262
+ if (!hasClientExports) return [3, 2];
1263
+ return [4, this.localState.addExportedVariables(mutation, variables, context)];
1264
+ case 1:
1265
+ variables = (_j.sent());
1266
+ _j.label = 2;
1267
+ case 2:
1268
+ mutationStoreValue = this.mutationStore &&
1269
+ (this.mutationStore[mutationId] = {
1270
+ mutation: mutation,
1271
+ variables: variables,
1272
+ loading: true,
1273
+ error: null,
1274
+ });
1275
+ if (optimisticResponse) {
1276
+ this.markMutationOptimistic(optimisticResponse, {
1277
+ mutationId: mutationId,
1278
+ document: mutation,
1279
+ variables: variables,
1280
+ fetchPolicy: fetchPolicy,
1281
+ errorPolicy: errorPolicy,
1282
+ context: context,
1283
+ updateQueries: updateQueries,
1284
+ update: updateWithProxyFn,
1285
+ keepRootFields: keepRootFields,
1286
+ });
1287
+ }
1288
+ this.broadcastQueries();
1289
+ self = this;
1290
+ return [2, new Promise(function (resolve, reject) {
1291
+ return utilities.asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: optimisticResponse }), variables, false), function (result) {
1292
+ if (utilities.graphQLResultHasError(result) && errorPolicy === 'none') {
1293
+ throw new errors.ApolloError({
1294
+ graphQLErrors: utilities.getGraphQLErrorsFromResult(result),
1295
+ });
1296
+ }
1297
+ if (mutationStoreValue) {
1298
+ mutationStoreValue.loading = false;
1299
+ mutationStoreValue.error = null;
1300
+ }
1301
+ var storeResult = tslib.__assign({}, result);
1302
+ if (typeof refetchQueries === "function") {
1303
+ refetchQueries = refetchQueries(storeResult);
1304
+ }
1305
+ if (errorPolicy === 'ignore' &&
1306
+ utilities.graphQLResultHasError(storeResult)) {
1307
+ delete storeResult.errors;
1308
+ }
1309
+ return self.markMutationResult({
1310
+ mutationId: mutationId,
1311
+ result: storeResult,
1312
+ document: mutation,
1313
+ variables: variables,
1314
+ fetchPolicy: fetchPolicy,
1315
+ errorPolicy: errorPolicy,
1316
+ context: context,
1317
+ update: updateWithProxyFn,
1318
+ updateQueries: updateQueries,
1319
+ awaitRefetchQueries: awaitRefetchQueries,
1320
+ refetchQueries: refetchQueries,
1321
+ removeOptimistic: optimisticResponse ? mutationId : void 0,
1322
+ onQueryUpdated: onQueryUpdated,
1323
+ keepRootFields: keepRootFields,
1324
+ });
1325
+ }).subscribe({
1326
+ next: function (storeResult) {
1327
+ self.broadcastQueries();
1328
+ if (!('hasNext' in storeResult) || storeResult.hasNext === false) {
1329
+ resolve(storeResult);
1330
+ }
1331
+ },
1332
+ error: function (err) {
1333
+ if (mutationStoreValue) {
1334
+ mutationStoreValue.loading = false;
1335
+ mutationStoreValue.error = err;
1336
+ }
1337
+ if (optimisticResponse) {
1338
+ self.cache.removeOptimistic(mutationId);
1339
+ }
1340
+ self.broadcastQueries();
1341
+ reject(err instanceof errors.ApolloError ? err : new errors.ApolloError({
1342
+ networkError: err,
1343
+ }));
1344
+ },
1345
+ });
1346
+ })];
1347
+ }
1348
+ });
1349
+ });
1350
+ };
1351
+ QueryManager.prototype.markMutationResult = function (mutation, cache) {
1352
+ var _this = this;
1353
+ if (cache === void 0) { cache = this.cache; }
1354
+ var result = mutation.result;
1355
+ var cacheWrites = [];
1356
+ var skipCache = mutation.fetchPolicy === "no-cache";
1357
+ if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
1358
+ if (!utilities.isExecutionPatchIncrementalResult(result)) {
1359
+ cacheWrites.push({
1360
+ result: result.data,
1361
+ dataId: 'ROOT_MUTATION',
1362
+ query: mutation.document,
1363
+ variables: mutation.variables,
1364
+ });
1365
+ }
1366
+ if (utilities.isExecutionPatchIncrementalResult(result) && utilities.isNonEmptyArray(result.incremental)) {
1367
+ var diff = cache.diff({
1368
+ id: "ROOT_MUTATION",
1369
+ query: this.transform(mutation.document).asQuery,
1370
+ variables: mutation.variables,
1371
+ optimistic: false,
1372
+ returnPartialData: true,
1373
+ });
1374
+ var mergedData = void 0;
1375
+ if (diff.result) {
1376
+ mergedData = mergeIncrementalData(diff.result, result);
1377
+ }
1378
+ if (typeof mergedData !== 'undefined') {
1379
+ result.data = mergedData;
1380
+ cacheWrites.push({
1381
+ result: mergedData,
1382
+ dataId: 'ROOT_MUTATION',
1383
+ query: mutation.document,
1384
+ variables: mutation.variables,
1385
+ });
1386
+ }
1387
+ }
1388
+ var updateQueries_1 = mutation.updateQueries;
1389
+ if (updateQueries_1) {
1390
+ this.queries.forEach(function (_a, queryId) {
1391
+ var observableQuery = _a.observableQuery;
1392
+ var queryName = observableQuery && observableQuery.queryName;
1393
+ if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
1394
+ return;
1395
+ }
1396
+ var updater = updateQueries_1[queryName];
1397
+ var _b = _this.queries.get(queryId), document = _b.document, variables = _b.variables;
1398
+ var _c = cache.diff({
1399
+ query: document,
1400
+ variables: variables,
1401
+ returnPartialData: true,
1402
+ optimistic: false,
1403
+ }), currentQueryResult = _c.result, complete = _c.complete;
1404
+ if (complete && currentQueryResult) {
1405
+ var nextQueryResult = updater(currentQueryResult, {
1406
+ mutationResult: result,
1407
+ queryName: document && utilities.getOperationName(document) || void 0,
1408
+ queryVariables: variables,
1409
+ });
1410
+ if (nextQueryResult) {
1411
+ cacheWrites.push({
1412
+ result: nextQueryResult,
1413
+ dataId: 'ROOT_QUERY',
1414
+ query: document,
1415
+ variables: variables,
1416
+ });
1417
+ }
1418
+ }
1419
+ });
1420
+ }
1421
+ }
1422
+ if (cacheWrites.length > 0 ||
1423
+ mutation.refetchQueries ||
1424
+ mutation.update ||
1425
+ mutation.onQueryUpdated ||
1426
+ mutation.removeOptimistic) {
1427
+ var results_1 = [];
1428
+ this.refetchQueries({
1429
+ updateCache: function (cache) {
1430
+ if (!skipCache) {
1431
+ cacheWrites.forEach(function (write) { return cache.write(write); });
1432
+ }
1433
+ var update = mutation.update;
1434
+ var isFinalResult = !utilities.isExecutionPatchResult(result) ||
1435
+ (utilities.isExecutionPatchIncrementalResult(result) && !result.hasNext);
1436
+ if (update) {
1437
+ if (!skipCache) {
1438
+ var diff = cache.diff({
1439
+ id: "ROOT_MUTATION",
1440
+ query: _this.transform(mutation.document).asQuery,
1441
+ variables: mutation.variables,
1442
+ optimistic: false,
1443
+ returnPartialData: true,
1444
+ });
1445
+ if (diff.complete) {
1446
+ result = tslib.__assign(tslib.__assign({}, result), { data: diff.result });
1447
+ if ('incremental' in result) {
1448
+ delete result.incremental;
1449
+ }
1450
+ if ('hasNext' in result) {
1451
+ delete result.hasNext;
1452
+ }
1453
+ }
1454
+ }
1455
+ if (isFinalResult) {
1456
+ update(cache, result, {
1457
+ context: mutation.context,
1458
+ variables: mutation.variables,
1459
+ });
1460
+ }
1461
+ }
1462
+ if (!skipCache && !mutation.keepRootFields && isFinalResult) {
1463
+ cache.modify({
1464
+ id: 'ROOT_MUTATION',
1465
+ fields: function (value, _a) {
1466
+ var fieldName = _a.fieldName, DELETE = _a.DELETE;
1467
+ return fieldName === "__typename" ? value : DELETE;
1468
+ },
1469
+ });
1470
+ }
1471
+ },
1472
+ include: mutation.refetchQueries,
1473
+ optimistic: false,
1474
+ removeOptimistic: mutation.removeOptimistic,
1475
+ onQueryUpdated: mutation.onQueryUpdated || null,
1476
+ }).forEach(function (result) { return results_1.push(result); });
1477
+ if (mutation.awaitRefetchQueries || mutation.onQueryUpdated) {
1478
+ return Promise.all(results_1).then(function () { return result; });
1479
+ }
1480
+ }
1481
+ return Promise.resolve(result);
1482
+ };
1483
+ QueryManager.prototype.markMutationOptimistic = function (optimisticResponse, mutation) {
1484
+ var _this = this;
1485
+ var data = typeof optimisticResponse === "function"
1486
+ ? optimisticResponse(mutation.variables)
1487
+ : optimisticResponse;
1488
+ return this.cache.recordOptimisticTransaction(function (cache) {
1489
+ try {
1490
+ _this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
1491
+ }
1492
+ catch (error) {
1493
+ globals.__DEV__ && globals.invariant.error(error);
1494
+ }
1495
+ }, mutation.mutationId);
1496
+ };
1497
+ QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
1498
+ return this.fetchQueryObservable(queryId, options, networkStatus).promise;
1499
+ };
1500
+ QueryManager.prototype.getQueryStore = function () {
1501
+ var store = Object.create(null);
1502
+ this.queries.forEach(function (info, queryId) {
1503
+ store[queryId] = {
1504
+ variables: info.variables,
1505
+ networkStatus: info.networkStatus,
1506
+ networkError: info.networkError,
1507
+ graphQLErrors: info.graphQLErrors,
1508
+ };
1509
+ });
1510
+ return store;
1511
+ };
1512
+ QueryManager.prototype.resetErrors = function (queryId) {
1513
+ var queryInfo = this.queries.get(queryId);
1514
+ if (queryInfo) {
1515
+ queryInfo.networkError = undefined;
1516
+ queryInfo.graphQLErrors = [];
1517
+ }
1518
+ };
1519
+ QueryManager.prototype.transform = function (document) {
1520
+ var transformCache = this.transformCache;
1521
+ var _a = (this.defaultOptions.transformQuery || Object.create(null)).removeClientFields, removeClientFields = _a === void 0 ? true : _a;
1522
+ if (!transformCache.has(document)) {
1523
+ var transformed = this.cache.transformDocument(document);
1524
+ var noConnection = utilities.removeConnectionDirectiveFromDocument(transformed);
1525
+ var clientQuery = this.localState.clientQuery(transformed);
1526
+ var serverQuery = noConnection &&
1527
+ this.localState.serverQuery(noConnection, { removeClientFields: removeClientFields });
1528
+ var cacheEntry_1 = {
1529
+ document: transformed,
1530
+ hasClientExports: utilities.hasClientExports(transformed),
1531
+ hasForcedResolvers: this.localState.shouldForceResolvers(transformed),
1532
+ clientQuery: clientQuery,
1533
+ serverQuery: serverQuery,
1534
+ defaultVars: utilities.getDefaultValues(utilities.getOperationDefinition(transformed)),
1535
+ asQuery: tslib.__assign(tslib.__assign({}, transformed), { definitions: transformed.definitions.map(function (def) {
1536
+ if (def.kind === "OperationDefinition" &&
1537
+ def.operation !== "query") {
1538
+ return tslib.__assign(tslib.__assign({}, def), { operation: "query" });
1539
+ }
1540
+ return def;
1541
+ }) })
1542
+ };
1543
+ var add = function (doc) {
1544
+ if (doc && !transformCache.has(doc)) {
1545
+ transformCache.set(doc, cacheEntry_1);
1546
+ }
1547
+ };
1548
+ add(document);
1549
+ add(transformed);
1550
+ add(clientQuery);
1551
+ add(serverQuery);
1552
+ }
1553
+ return transformCache.get(document);
1554
+ };
1555
+ QueryManager.prototype.getVariables = function (document, variables) {
1556
+ return tslib.__assign(tslib.__assign({}, this.transform(document).defaultVars), variables);
1557
+ };
1558
+ QueryManager.prototype.watchQuery = function (options) {
1559
+ options = tslib.__assign(tslib.__assign({}, options), { variables: this.getVariables(options.query, options.variables) });
1560
+ if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
1561
+ options.notifyOnNetworkStatusChange = false;
1562
+ }
1563
+ var queryInfo = new QueryInfo(this);
1564
+ var observable = new ObservableQuery({
1565
+ queryManager: this,
1566
+ queryInfo: queryInfo,
1567
+ options: options,
1568
+ });
1569
+ this.queries.set(observable.queryId, queryInfo);
1570
+ queryInfo.init({
1571
+ document: observable.query,
1572
+ observableQuery: observable,
1573
+ variables: observable.variables,
1574
+ });
1575
+ return observable;
1576
+ };
1577
+ QueryManager.prototype.query = function (options, queryId) {
1578
+ var _this = this;
1579
+ if (queryId === void 0) { queryId = this.generateQueryId(); }
1580
+ globals.__DEV__ ? globals.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
1581
+ 'in the query option.') : globals.invariant(options.query, 17);
1582
+ globals.__DEV__ ? globals.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : globals.invariant(options.query.kind === 'Document', 18);
1583
+ globals.__DEV__ ? globals.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : globals.invariant(!options.returnPartialData, 19);
1584
+ globals.__DEV__ ? globals.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : globals.invariant(!options.pollInterval, 20);
1585
+ return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
1586
+ };
1587
+ QueryManager.prototype.generateQueryId = function () {
1588
+ return String(this.queryIdCounter++);
1589
+ };
1590
+ QueryManager.prototype.generateRequestId = function () {
1591
+ return this.requestIdCounter++;
1592
+ };
1593
+ QueryManager.prototype.generateMutationId = function () {
1594
+ return String(this.mutationIdCounter++);
1595
+ };
1596
+ QueryManager.prototype.stopQueryInStore = function (queryId) {
1597
+ this.stopQueryInStoreNoBroadcast(queryId);
1598
+ this.broadcastQueries();
1599
+ };
1600
+ QueryManager.prototype.stopQueryInStoreNoBroadcast = function (queryId) {
1601
+ var queryInfo = this.queries.get(queryId);
1602
+ if (queryInfo)
1603
+ queryInfo.stop();
1604
+ };
1605
+ QueryManager.prototype.clearStore = function (options) {
1606
+ if (options === void 0) { options = {
1607
+ discardWatches: true,
1608
+ }; }
1609
+ this.cancelPendingFetches(globals.__DEV__ ? new globals.InvariantError('Store reset while query was in flight (not completed in link chain)') : new globals.InvariantError(21));
1610
+ this.queries.forEach(function (queryInfo) {
1611
+ if (queryInfo.observableQuery) {
1612
+ queryInfo.networkStatus = exports.NetworkStatus.loading;
1613
+ }
1614
+ else {
1615
+ queryInfo.stop();
1616
+ }
1617
+ });
1618
+ if (this.mutationStore) {
1619
+ this.mutationStore = Object.create(null);
1620
+ }
1621
+ return this.cache.reset(options);
1622
+ };
1623
+ QueryManager.prototype.getObservableQueries = function (include) {
1624
+ var _this = this;
1625
+ if (include === void 0) { include = "active"; }
1626
+ var queries = new Map();
1627
+ var queryNamesAndDocs = new Map();
1628
+ var legacyQueryOptions = new Set();
1629
+ if (Array.isArray(include)) {
1630
+ include.forEach(function (desc) {
1631
+ if (typeof desc === "string") {
1632
+ queryNamesAndDocs.set(desc, false);
1633
+ }
1634
+ else if (utilities.isDocumentNode(desc)) {
1635
+ queryNamesAndDocs.set(_this.transform(desc).document, false);
1636
+ }
1637
+ else if (utilities.isNonNullObject(desc) && desc.query) {
1638
+ legacyQueryOptions.add(desc);
1639
+ }
1640
+ });
1641
+ }
1642
+ this.queries.forEach(function (_a, queryId) {
1643
+ var oq = _a.observableQuery, document = _a.document;
1644
+ if (oq) {
1645
+ if (include === "all") {
1646
+ queries.set(queryId, oq);
1647
+ return;
1648
+ }
1649
+ var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
1650
+ if (fetchPolicy === "standby" ||
1651
+ (include === "active" && !oq.hasObservers())) {
1652
+ return;
1653
+ }
1654
+ if (include === "active" ||
1655
+ (queryName && queryNamesAndDocs.has(queryName)) ||
1656
+ (document && queryNamesAndDocs.has(document))) {
1657
+ queries.set(queryId, oq);
1658
+ if (queryName)
1659
+ queryNamesAndDocs.set(queryName, true);
1660
+ if (document)
1661
+ queryNamesAndDocs.set(document, true);
1662
+ }
1663
+ }
1664
+ });
1665
+ if (legacyQueryOptions.size) {
1666
+ legacyQueryOptions.forEach(function (options) {
1667
+ var queryId = utilities.makeUniqueId("legacyOneTimeQuery");
1668
+ var queryInfo = _this.getQuery(queryId).init({
1669
+ document: options.query,
1670
+ variables: options.variables,
1671
+ });
1672
+ var oq = new ObservableQuery({
1673
+ queryManager: _this,
1674
+ queryInfo: queryInfo,
1675
+ options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
1676
+ });
1677
+ globals.invariant(oq.queryId === queryId);
1678
+ queryInfo.setObservableQuery(oq);
1679
+ queries.set(queryId, oq);
1680
+ });
1681
+ }
1682
+ if (globals.__DEV__ && queryNamesAndDocs.size) {
1683
+ queryNamesAndDocs.forEach(function (included, nameOrDoc) {
1684
+ if (!included) {
1685
+ globals.__DEV__ && globals.invariant.warn("Unknown query ".concat(typeof nameOrDoc === "string" ? "named " : "").concat(JSON.stringify(nameOrDoc, null, 2), " requested in refetchQueries options.include array"));
1686
+ }
1687
+ });
1688
+ }
1689
+ return queries;
1690
+ };
1691
+ QueryManager.prototype.reFetchObservableQueries = function (includeStandby) {
1692
+ var _this = this;
1693
+ if (includeStandby === void 0) { includeStandby = false; }
1694
+ var observableQueryPromises = [];
1695
+ this.getObservableQueries(includeStandby ? "all" : "active").forEach(function (observableQuery, queryId) {
1696
+ var fetchPolicy = observableQuery.options.fetchPolicy;
1697
+ observableQuery.resetLastResults();
1698
+ if (includeStandby ||
1699
+ (fetchPolicy !== "standby" &&
1700
+ fetchPolicy !== "cache-only")) {
1701
+ observableQueryPromises.push(observableQuery.refetch());
1702
+ }
1703
+ _this.getQuery(queryId).setDiff(null);
1704
+ });
1705
+ this.broadcastQueries();
1706
+ return Promise.all(observableQueryPromises);
1707
+ };
1708
+ QueryManager.prototype.setObservableQuery = function (observableQuery) {
1709
+ this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
1710
+ };
1711
+ QueryManager.prototype.startGraphQLSubscription = function (_a) {
1712
+ var _this = this;
1713
+ var query = _a.query, fetchPolicy = _a.fetchPolicy, errorPolicy = _a.errorPolicy, variables = _a.variables, _b = _a.context, context = _b === void 0 ? {} : _b;
1714
+ query = this.transform(query).document;
1715
+ variables = this.getVariables(query, variables);
1716
+ var makeObservable = function (variables) {
1717
+ return _this.getObservableFromLink(query, context, variables).map(function (result) {
1718
+ if (fetchPolicy !== 'no-cache') {
1719
+ if (shouldWriteResult(result, errorPolicy)) {
1720
+ _this.cache.write({
1721
+ query: query,
1722
+ result: result.data,
1723
+ dataId: 'ROOT_SUBSCRIPTION',
1724
+ variables: variables,
1725
+ });
1726
+ }
1727
+ _this.broadcastQueries();
1728
+ }
1729
+ if (utilities.graphQLResultHasError(result)) {
1730
+ throw new errors.ApolloError({
1731
+ graphQLErrors: result.errors,
1732
+ });
1733
+ }
1734
+ return result;
1735
+ });
1736
+ };
1737
+ if (this.transform(query).hasClientExports) {
1738
+ var observablePromise_1 = this.localState.addExportedVariables(query, variables, context).then(makeObservable);
1739
+ return new utilities.Observable(function (observer) {
1740
+ var sub = null;
1741
+ observablePromise_1.then(function (observable) { return sub = observable.subscribe(observer); }, observer.error);
1742
+ return function () { return sub && sub.unsubscribe(); };
1743
+ });
1744
+ }
1745
+ return makeObservable(variables);
1746
+ };
1747
+ QueryManager.prototype.stopQuery = function (queryId) {
1748
+ this.stopQueryNoBroadcast(queryId);
1749
+ this.broadcastQueries();
1750
+ };
1751
+ QueryManager.prototype.stopQueryNoBroadcast = function (queryId) {
1752
+ this.stopQueryInStoreNoBroadcast(queryId);
1753
+ this.removeQuery(queryId);
1754
+ };
1755
+ QueryManager.prototype.removeQuery = function (queryId) {
1756
+ this.fetchCancelFns.delete(queryId);
1757
+ if (this.queries.has(queryId)) {
1758
+ this.getQuery(queryId).stop();
1759
+ this.queries.delete(queryId);
1760
+ }
1761
+ };
1762
+ QueryManager.prototype.broadcastQueries = function () {
1763
+ if (this.onBroadcast)
1764
+ this.onBroadcast();
1765
+ this.queries.forEach(function (info) { return info.notify(); });
1766
+ };
1767
+ QueryManager.prototype.getLocalState = function () {
1768
+ return this.localState;
1769
+ };
1770
+ QueryManager.prototype.getObservableFromLink = function (query, context, variables, deduplication) {
1771
+ var _this = this;
1772
+ var _a;
1773
+ if (deduplication === void 0) { deduplication = (_a = context === null || context === void 0 ? void 0 : context.queryDeduplication) !== null && _a !== void 0 ? _a : this.queryDeduplication; }
1774
+ var observable;
1775
+ var serverQuery = this.transform(query).serverQuery;
1776
+ if (serverQuery) {
1777
+ var _b = this, inFlightLinkObservables_1 = _b.inFlightLinkObservables, link = _b.link;
1778
+ var operation = {
1779
+ query: serverQuery,
1780
+ variables: variables,
1781
+ operationName: utilities.getOperationName(serverQuery) || void 0,
1782
+ context: this.prepareContext(tslib.__assign(tslib.__assign({}, context), { forceFetch: !deduplication })),
1783
+ };
1784
+ context = operation.context;
1785
+ if (deduplication) {
1786
+ var byVariables_1 = inFlightLinkObservables_1.get(serverQuery) || new Map();
1787
+ inFlightLinkObservables_1.set(serverQuery, byVariables_1);
1788
+ var varJson_1 = cache.canonicalStringify(variables);
1789
+ observable = byVariables_1.get(varJson_1);
1790
+ if (!observable) {
1791
+ var concast = new utilities.Concast([
1792
+ core.execute(link, operation)
1793
+ ]);
1794
+ byVariables_1.set(varJson_1, observable = concast);
1795
+ concast.beforeNext(function () {
1796
+ if (byVariables_1.delete(varJson_1) &&
1797
+ byVariables_1.size < 1) {
1798
+ inFlightLinkObservables_1.delete(serverQuery);
1799
+ }
1800
+ });
1801
+ }
1802
+ }
1803
+ else {
1804
+ observable = new utilities.Concast([
1805
+ core.execute(link, operation)
1806
+ ]);
1807
+ }
1808
+ }
1809
+ else {
1810
+ observable = new utilities.Concast([
1811
+ utilities.Observable.of({ data: {} })
1812
+ ]);
1813
+ context = this.prepareContext(context);
1814
+ }
1815
+ var clientQuery = this.transform(query).clientQuery;
1816
+ if (clientQuery) {
1817
+ observable = utilities.asyncMap(observable, function (result) {
1818
+ return _this.localState.runResolvers({
1819
+ document: clientQuery,
1820
+ remoteResult: result,
1821
+ context: context,
1822
+ variables: variables,
1823
+ });
1824
+ });
1825
+ }
1826
+ return observable;
1827
+ };
1828
+ QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
1829
+ var requestId = queryInfo.lastRequestId = this.generateRequestId();
1830
+ var linkDocument = this.cache.transformForLink(this.transform(queryInfo.document).document);
1831
+ return utilities.asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
1832
+ var graphQLErrors = utilities.getGraphQLErrorsFromResult(result);
1833
+ var hasErrors = graphQLErrors.length > 0;
1834
+ if (requestId >= queryInfo.lastRequestId) {
1835
+ if (hasErrors && options.errorPolicy === "none") {
1836
+ throw queryInfo.markError(new errors.ApolloError({
1837
+ graphQLErrors: graphQLErrors,
1838
+ }));
1839
+ }
1840
+ queryInfo.markResult(result, linkDocument, options, cacheWriteBehavior);
1841
+ queryInfo.markReady();
1842
+ }
1843
+ var aqr = {
1844
+ data: result.data,
1845
+ loading: false,
1846
+ networkStatus: exports.NetworkStatus.ready,
1847
+ };
1848
+ if (hasErrors && options.errorPolicy !== "ignore") {
1849
+ aqr.errors = graphQLErrors;
1850
+ aqr.networkStatus = exports.NetworkStatus.error;
1851
+ }
1852
+ return aqr;
1853
+ }, function (networkError) {
1854
+ var error = errors.isApolloError(networkError)
1855
+ ? networkError
1856
+ : new errors.ApolloError({ networkError: networkError });
1857
+ if (requestId >= queryInfo.lastRequestId) {
1858
+ queryInfo.markError(error);
1859
+ }
1860
+ throw error;
1861
+ });
1862
+ };
1863
+ QueryManager.prototype.fetchQueryObservable = function (queryId, options, networkStatus) {
1864
+ var _this = this;
1865
+ if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
1866
+ var query = this.transform(options.query).document;
1867
+ var variables = this.getVariables(query, options.variables);
1868
+ var queryInfo = this.getQuery(queryId);
1869
+ var defaults = this.defaultOptions.watchQuery;
1870
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? defaults && defaults.fetchPolicy || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? defaults && defaults.errorPolicy || "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
1871
+ var normalized = Object.assign({}, options, {
1872
+ query: query,
1873
+ variables: variables,
1874
+ fetchPolicy: fetchPolicy,
1875
+ errorPolicy: errorPolicy,
1876
+ returnPartialData: returnPartialData,
1877
+ notifyOnNetworkStatusChange: notifyOnNetworkStatusChange,
1878
+ context: context,
1879
+ });
1880
+ var fromVariables = function (variables) {
1881
+ normalized.variables = variables;
1882
+ var concastSources = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
1883
+ if (normalized.fetchPolicy !== "standby" &&
1884
+ concastSources.length > 0 &&
1885
+ queryInfo.observableQuery) {
1886
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
1887
+ }
1888
+ return concastSources;
1889
+ };
1890
+ var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
1891
+ this.fetchCancelFns.set(queryId, function (reason) {
1892
+ cleanupCancelFn();
1893
+ setTimeout(function () { return concast.cancel(reason); });
1894
+ });
1895
+ var concast = new utilities.Concast(this.transform(normalized.query).hasClientExports
1896
+ ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
1897
+ : fromVariables(normalized.variables));
1898
+ concast.promise.then(cleanupCancelFn, cleanupCancelFn);
1899
+ return concast;
1900
+ };
1901
+ QueryManager.prototype.refetchQueries = function (_a) {
1902
+ var _this = this;
1903
+ var updateCache = _a.updateCache, include = _a.include, _b = _a.optimistic, optimistic = _b === void 0 ? false : _b, _c = _a.removeOptimistic, removeOptimistic = _c === void 0 ? optimistic ? utilities.makeUniqueId("refetchQueries") : void 0 : _c, onQueryUpdated = _a.onQueryUpdated;
1904
+ var includedQueriesById = new Map();
1905
+ if (include) {
1906
+ this.getObservableQueries(include).forEach(function (oq, queryId) {
1907
+ includedQueriesById.set(queryId, {
1908
+ oq: oq,
1909
+ lastDiff: _this.getQuery(queryId).getDiff(),
1910
+ });
1911
+ });
1912
+ }
1913
+ var results = new Map;
1914
+ if (updateCache) {
1915
+ this.cache.batch({
1916
+ update: updateCache,
1917
+ optimistic: optimistic && removeOptimistic || false,
1918
+ removeOptimistic: removeOptimistic,
1919
+ onWatchUpdated: function (watch, diff, lastDiff) {
1920
+ var oq = watch.watcher instanceof QueryInfo &&
1921
+ watch.watcher.observableQuery;
1922
+ if (oq) {
1923
+ if (onQueryUpdated) {
1924
+ includedQueriesById.delete(oq.queryId);
1925
+ var result = onQueryUpdated(oq, diff, lastDiff);
1926
+ if (result === true) {
1927
+ result = oq.refetch();
1928
+ }
1929
+ if (result !== false) {
1930
+ results.set(oq, result);
1931
+ }
1932
+ return result;
1933
+ }
1934
+ if (onQueryUpdated !== null) {
1935
+ includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
1936
+ }
1937
+ }
1938
+ },
1939
+ });
1940
+ }
1941
+ if (includedQueriesById.size) {
1942
+ includedQueriesById.forEach(function (_a, queryId) {
1943
+ var oq = _a.oq, lastDiff = _a.lastDiff, diff = _a.diff;
1944
+ var result;
1945
+ if (onQueryUpdated) {
1946
+ if (!diff) {
1947
+ var info = oq["queryInfo"];
1948
+ info.reset();
1949
+ diff = info.getDiff();
1950
+ }
1951
+ result = onQueryUpdated(oq, diff, lastDiff);
1952
+ }
1953
+ if (!onQueryUpdated || result === true) {
1954
+ result = oq.refetch();
1955
+ }
1956
+ if (result !== false) {
1957
+ results.set(oq, result);
1958
+ }
1959
+ if (queryId.indexOf("legacyOneTimeQuery") >= 0) {
1960
+ _this.stopQueryNoBroadcast(queryId);
1961
+ }
1962
+ });
1963
+ }
1964
+ if (removeOptimistic) {
1965
+ this.cache.removeOptimistic(removeOptimistic);
1966
+ }
1967
+ return results;
1968
+ };
1969
+ QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a, networkStatus) {
1970
+ var _this = this;
1971
+ var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
1972
+ var oldNetworkStatus = queryInfo.networkStatus;
1973
+ queryInfo.init({
1974
+ document: this.transform(query).document,
1975
+ variables: variables,
1976
+ networkStatus: networkStatus,
1977
+ });
1978
+ var readCache = function () { return queryInfo.getDiff(variables); };
1979
+ var resultsFromCache = function (diff, networkStatus) {
1980
+ if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
1981
+ var data = diff.result;
1982
+ if (globals.__DEV__ &&
1983
+ !returnPartialData &&
1984
+ !equality.equal(data, {})) {
1985
+ logMissingFieldErrors(diff.missing);
1986
+ }
1987
+ var fromData = function (data) { return utilities.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
1988
+ if (data && _this.transform(query).hasForcedResolvers) {
1989
+ return _this.localState.runResolvers({
1990
+ document: query,
1991
+ remoteResult: { data: data },
1992
+ context: context,
1993
+ variables: variables,
1994
+ onlyRunForcedResolvers: true,
1995
+ }).then(function (resolved) { return fromData(resolved.data || void 0); });
1996
+ }
1997
+ if (errorPolicy === 'none' &&
1998
+ networkStatus === exports.NetworkStatus.refetch &&
1999
+ Array.isArray(diff.missing)) {
2000
+ return fromData(void 0);
2001
+ }
2002
+ return fromData(data);
2003
+ };
2004
+ var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0 :
2005
+ (networkStatus === exports.NetworkStatus.refetch &&
2006
+ refetchWritePolicy !== "merge") ? 1
2007
+ : 2;
2008
+ var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
2009
+ variables: variables,
2010
+ context: context,
2011
+ fetchPolicy: fetchPolicy,
2012
+ errorPolicy: errorPolicy,
2013
+ }); };
2014
+ var shouldNotify = notifyOnNetworkStatusChange &&
2015
+ typeof oldNetworkStatus === "number" &&
2016
+ oldNetworkStatus !== networkStatus &&
2017
+ isNetworkRequestInFlight(networkStatus);
2018
+ switch (fetchPolicy) {
2019
+ default:
2020
+ case "cache-first": {
2021
+ var diff = readCache();
2022
+ if (diff.complete) {
2023
+ return [
2024
+ resultsFromCache(diff, queryInfo.markReady()),
2025
+ ];
2026
+ }
2027
+ if (returnPartialData || shouldNotify) {
2028
+ return [
2029
+ resultsFromCache(diff),
2030
+ resultsFromLink(),
2031
+ ];
2032
+ }
2033
+ return [
2034
+ resultsFromLink(),
2035
+ ];
2036
+ }
2037
+ case "cache-and-network": {
2038
+ var diff = readCache();
2039
+ if (diff.complete || returnPartialData || shouldNotify) {
2040
+ return [
2041
+ resultsFromCache(diff),
2042
+ resultsFromLink(),
2043
+ ];
2044
+ }
2045
+ return [
2046
+ resultsFromLink(),
2047
+ ];
2048
+ }
2049
+ case "cache-only":
2050
+ return [
2051
+ resultsFromCache(readCache(), queryInfo.markReady()),
2052
+ ];
2053
+ case "network-only":
2054
+ if (shouldNotify) {
2055
+ return [
2056
+ resultsFromCache(readCache()),
2057
+ resultsFromLink(),
2058
+ ];
2059
+ }
2060
+ return [resultsFromLink()];
2061
+ case "no-cache":
2062
+ if (shouldNotify) {
2063
+ return [
2064
+ resultsFromCache(queryInfo.getDiff()),
2065
+ resultsFromLink(),
2066
+ ];
2067
+ }
2068
+ return [resultsFromLink()];
2069
+ case "standby":
2070
+ return [];
2071
+ }
2072
+ };
2073
+ QueryManager.prototype.getQuery = function (queryId) {
2074
+ if (queryId && !this.queries.has(queryId)) {
2075
+ this.queries.set(queryId, new QueryInfo(this, queryId));
2076
+ }
2077
+ return this.queries.get(queryId);
2078
+ };
2079
+ QueryManager.prototype.prepareContext = function (context) {
2080
+ if (context === void 0) { context = {}; }
2081
+ var newContext = this.localState.prepareContext(context);
2082
+ return tslib.__assign(tslib.__assign({}, newContext), { clientAwareness: this.clientAwareness });
2083
+ };
2084
+ return QueryManager;
2085
+ }());
2086
+
2087
+ var hasSuggestedDevtools = false;
2088
+ var ApolloClient = (function () {
2089
+ function ApolloClient(options) {
2090
+ var _this = this;
2091
+ this.resetStoreCallbacks = [];
2092
+ this.clearStoreCallbacks = [];
2093
+ var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
2094
+ !window.__APOLLO_CLIENT__ &&
2095
+ globals.__DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? false : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
2096
+ var link = options.link;
2097
+ if (!link) {
2098
+ link = uri
2099
+ ? new http.HttpLink({ uri: uri, credentials: credentials, headers: headers })
2100
+ : core.ApolloLink.empty();
2101
+ }
2102
+ if (!cache) {
2103
+ throw globals.__DEV__ ? new globals.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
2104
+ "in the options object. \n" +
2105
+ "For more information, please visit: https://go.apollo.dev/c/docs") : new globals.InvariantError(9);
2106
+ }
2107
+ this.link = link;
2108
+ this.cache = cache;
2109
+ this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
2110
+ this.queryDeduplication = queryDeduplication;
2111
+ this.defaultOptions = defaultOptions || Object.create(null);
2112
+ this.typeDefs = typeDefs;
2113
+ if (ssrForceFetchDelay) {
2114
+ setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
2115
+ }
2116
+ this.watchQuery = this.watchQuery.bind(this);
2117
+ this.query = this.query.bind(this);
2118
+ this.mutate = this.mutate.bind(this);
2119
+ this.resetStore = this.resetStore.bind(this);
2120
+ this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this);
2121
+ if (connectToDevTools && typeof window === 'object') {
2122
+ window.__APOLLO_CLIENT__ = this;
2123
+ }
2124
+ if (!hasSuggestedDevtools && connectToDevTools && globals.__DEV__) {
2125
+ hasSuggestedDevtools = true;
2126
+ if (typeof window !== 'undefined' &&
2127
+ window.document &&
2128
+ window.top === window.self &&
2129
+ !window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__) {
2130
+ var nav = window.navigator;
2131
+ var ua = nav && nav.userAgent;
2132
+ var url = void 0;
2133
+ if (typeof ua === "string") {
2134
+ if (ua.indexOf("Chrome/") > -1) {
2135
+ url = "https://chrome.google.com/webstore/detail/" +
2136
+ "apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
2137
+ }
2138
+ else if (ua.indexOf("Firefox/") > -1) {
2139
+ url = "https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
2140
+ }
2141
+ }
2142
+ if (url) {
2143
+ globals.__DEV__ && globals.invariant.log("Download the Apollo DevTools for a better development " +
2144
+ "experience: " + url);
2145
+ }
2146
+ }
2147
+ }
2148
+ this.version = version;
2149
+ this.localState = new LocalState({
2150
+ cache: cache,
2151
+ client: this,
2152
+ resolvers: resolvers,
2153
+ fragmentMatcher: fragmentMatcher,
2154
+ });
2155
+ this.queryManager = new QueryManager({
2156
+ cache: this.cache,
2157
+ link: this.link,
2158
+ defaultOptions: this.defaultOptions,
2159
+ queryDeduplication: queryDeduplication,
2160
+ ssrMode: ssrMode,
2161
+ clientAwareness: {
2162
+ name: clientAwarenessName,
2163
+ version: clientAwarenessVersion,
2164
+ },
2165
+ localState: this.localState,
2166
+ assumeImmutableResults: assumeImmutableResults,
2167
+ onBroadcast: connectToDevTools ? function () {
2168
+ if (_this.devToolsHookCb) {
2169
+ _this.devToolsHookCb({
2170
+ action: {},
2171
+ state: {
2172
+ queries: _this.queryManager.getQueryStore(),
2173
+ mutations: _this.queryManager.mutationStore || {},
2174
+ },
2175
+ dataWithOptimisticResults: _this.cache.extract(true),
2176
+ });
2177
+ }
2178
+ } : void 0,
2179
+ });
2180
+ }
2181
+ ApolloClient.prototype.stop = function () {
2182
+ this.queryManager.stop();
2183
+ };
2184
+ ApolloClient.prototype.watchQuery = function (options) {
2185
+ if (this.defaultOptions.watchQuery) {
2186
+ options = utilities.mergeOptions(this.defaultOptions.watchQuery, options);
2187
+ }
2188
+ if (this.disableNetworkFetches &&
2189
+ (options.fetchPolicy === 'network-only' ||
2190
+ options.fetchPolicy === 'cache-and-network')) {
2191
+ options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
2192
+ }
2193
+ return this.queryManager.watchQuery(options);
2194
+ };
2195
+ ApolloClient.prototype.query = function (options) {
2196
+ if (this.defaultOptions.query) {
2197
+ options = utilities.mergeOptions(this.defaultOptions.query, options);
2198
+ }
2199
+ globals.__DEV__ ? globals.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
2200
+ 'client.query can only return a single result. Please use client.watchQuery ' +
2201
+ 'to receive multiple results from the cache and the network, or consider ' +
2202
+ 'using a different fetchPolicy, such as cache-first or network-only.') : globals.invariant(options.fetchPolicy !== 'cache-and-network', 10);
2203
+ if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
2204
+ options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
2205
+ }
2206
+ return this.queryManager.query(options);
2207
+ };
2208
+ ApolloClient.prototype.mutate = function (options) {
2209
+ if (this.defaultOptions.mutate) {
2210
+ options = utilities.mergeOptions(this.defaultOptions.mutate, options);
2211
+ }
2212
+ return this.queryManager.mutate(options);
2213
+ };
2214
+ ApolloClient.prototype.subscribe = function (options) {
2215
+ return this.queryManager.startGraphQLSubscription(options);
2216
+ };
2217
+ ApolloClient.prototype.readQuery = function (options, optimistic) {
2218
+ if (optimistic === void 0) { optimistic = false; }
2219
+ return this.cache.readQuery(options, optimistic);
2220
+ };
2221
+ ApolloClient.prototype.readFragment = function (options, optimistic) {
2222
+ if (optimistic === void 0) { optimistic = false; }
2223
+ return this.cache.readFragment(options, optimistic);
2224
+ };
2225
+ ApolloClient.prototype.writeQuery = function (options) {
2226
+ this.cache.writeQuery(options);
2227
+ this.queryManager.broadcastQueries();
2228
+ };
2229
+ ApolloClient.prototype.writeFragment = function (options) {
2230
+ this.cache.writeFragment(options);
2231
+ this.queryManager.broadcastQueries();
2232
+ };
2233
+ ApolloClient.prototype.__actionHookForDevTools = function (cb) {
2234
+ this.devToolsHookCb = cb;
2235
+ };
2236
+ ApolloClient.prototype.__requestRaw = function (payload) {
2237
+ return core.execute(this.link, payload);
2238
+ };
2239
+ ApolloClient.prototype.resetStore = function () {
2240
+ var _this = this;
2241
+ return Promise.resolve()
2242
+ .then(function () { return _this.queryManager.clearStore({
2243
+ discardWatches: false,
2244
+ }); })
2245
+ .then(function () { return Promise.all(_this.resetStoreCallbacks.map(function (fn) { return fn(); })); })
2246
+ .then(function () { return _this.reFetchObservableQueries(); });
2247
+ };
2248
+ ApolloClient.prototype.clearStore = function () {
2249
+ var _this = this;
2250
+ return Promise.resolve()
2251
+ .then(function () { return _this.queryManager.clearStore({
2252
+ discardWatches: true,
2253
+ }); })
2254
+ .then(function () { return Promise.all(_this.clearStoreCallbacks.map(function (fn) { return fn(); })); });
2255
+ };
2256
+ ApolloClient.prototype.onResetStore = function (cb) {
2257
+ var _this = this;
2258
+ this.resetStoreCallbacks.push(cb);
2259
+ return function () {
2260
+ _this.resetStoreCallbacks = _this.resetStoreCallbacks.filter(function (c) { return c !== cb; });
2261
+ };
2262
+ };
2263
+ ApolloClient.prototype.onClearStore = function (cb) {
2264
+ var _this = this;
2265
+ this.clearStoreCallbacks.push(cb);
2266
+ return function () {
2267
+ _this.clearStoreCallbacks = _this.clearStoreCallbacks.filter(function (c) { return c !== cb; });
2268
+ };
2269
+ };
2270
+ ApolloClient.prototype.reFetchObservableQueries = function (includeStandby) {
2271
+ return this.queryManager.reFetchObservableQueries(includeStandby);
2272
+ };
2273
+ ApolloClient.prototype.refetchQueries = function (options) {
2274
+ var map = this.queryManager.refetchQueries(options);
2275
+ var queries = [];
2276
+ var results = [];
2277
+ map.forEach(function (result, obsQuery) {
2278
+ queries.push(obsQuery);
2279
+ results.push(result);
2280
+ });
2281
+ var result = Promise.all(results);
2282
+ result.queries = queries;
2283
+ result.results = results;
2284
+ result.catch(function (error) {
2285
+ globals.__DEV__ && globals.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error ".concat(error));
2286
+ });
2287
+ return result;
2288
+ };
2289
+ ApolloClient.prototype.getObservableQueries = function (include) {
2290
+ if (include === void 0) { include = "active"; }
2291
+ return this.queryManager.getObservableQueries(include);
2292
+ };
2293
+ ApolloClient.prototype.extract = function (optimistic) {
2294
+ return this.cache.extract(optimistic);
2295
+ };
2296
+ ApolloClient.prototype.restore = function (serializedState) {
2297
+ return this.cache.restore(serializedState);
2298
+ };
2299
+ ApolloClient.prototype.addResolvers = function (resolvers) {
2300
+ this.localState.addResolvers(resolvers);
2301
+ };
2302
+ ApolloClient.prototype.setResolvers = function (resolvers) {
2303
+ this.localState.setResolvers(resolvers);
2304
+ };
2305
+ ApolloClient.prototype.getResolvers = function () {
2306
+ return this.localState.getResolvers();
2307
+ };
2308
+ ApolloClient.prototype.setLocalStateFragmentMatcher = function (fragmentMatcher) {
2309
+ this.localState.setFragmentMatcher(fragmentMatcher);
2310
+ };
2311
+ ApolloClient.prototype.setLink = function (newLink) {
2312
+ this.link = this.queryManager.link = newLink;
2313
+ };
2314
+ return ApolloClient;
2315
+ }());
2316
+
2317
+ tsInvariant.setVerbosity(globals.__DEV__ ? "log" : "silent");
2318
+
2319
+ exports.Observable = utilities.Observable;
2320
+ exports.isReference = utilities.isReference;
2321
+ exports.makeReference = utilities.makeReference;
2322
+ exports.mergeOptions = utilities.mergeOptions;
2323
+ exports.ApolloCache = cache.ApolloCache;
2324
+ exports.Cache = cache.Cache;
2325
+ exports.InMemoryCache = cache.InMemoryCache;
2326
+ exports.MissingFieldError = cache.MissingFieldError;
2327
+ exports.defaultDataIdFromObject = cache.defaultDataIdFromObject;
2328
+ exports.makeVar = cache.makeVar;
2329
+ exports.ApolloError = errors.ApolloError;
2330
+ exports.isApolloError = errors.isApolloError;
2331
+ exports.fromError = utils.fromError;
2332
+ exports.fromPromise = utils.fromPromise;
2333
+ exports.throwServerError = utils.throwServerError;
2334
+ exports.toPromise = utils.toPromise;
2335
+ exports.setLogVerbosity = tsInvariant.setVerbosity;
2336
+ exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
2337
+ exports.disableFragmentWarnings = graphqlTag.disableFragmentWarnings;
2338
+ exports.enableExperimentalFragmentVariables = graphqlTag.enableExperimentalFragmentVariables;
2339
+ exports.gql = graphqlTag.gql;
2340
+ exports.resetCaches = graphqlTag.resetCaches;
2341
+ exports.ApolloClient = ApolloClient;
2342
+ exports.ObservableQuery = ObservableQuery;
2343
+ for (var k in core) {
2344
+ if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
2345
+ }
2346
+ for (var k in http) {
2347
+ if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = http[k];
2348
+ }
2349
+ //# sourceMappingURL=core.cjs.map