@apollo/client 3.8.0-alpha.9 → 3.8.0-beta.0

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 (582) hide show
  1. package/apollo-client.cjs +1030 -673
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +35 -31
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +35 -31
  7. package/cache/core/cache.d.ts +5 -4
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js +1 -0
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/core/types/Cache.d.ts +2 -2
  12. package/cache/core/types/Cache.d.ts.map +1 -1
  13. package/cache/core/types/Cache.js.map +1 -1
  14. package/cache/core/types/DataProxy.d.ts +4 -4
  15. package/cache/core/types/DataProxy.d.ts.map +1 -1
  16. package/cache/core/types/DataProxy.js.map +1 -1
  17. package/cache/core/types/common.d.ts +3 -3
  18. package/cache/core/types/common.d.ts.map +1 -1
  19. package/cache/core/types/common.js.map +1 -1
  20. package/cache/inmemory/entityStore.d.ts +5 -5
  21. package/cache/inmemory/entityStore.d.ts.map +1 -1
  22. package/cache/inmemory/entityStore.js +2 -2
  23. package/cache/inmemory/entityStore.js.map +1 -1
  24. package/cache/inmemory/fragmentRegistry.d.ts +1 -1
  25. package/cache/inmemory/fragmentRegistry.d.ts.map +1 -1
  26. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  27. package/cache/inmemory/helpers.d.ts +6 -5
  28. package/cache/inmemory/helpers.d.ts.map +1 -1
  29. package/cache/inmemory/helpers.js.map +1 -1
  30. package/cache/inmemory/inMemoryCache.d.ts +9 -7
  31. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  32. package/cache/inmemory/inMemoryCache.js +14 -15
  33. package/cache/inmemory/inMemoryCache.js.map +1 -1
  34. package/cache/inmemory/key-extractor.d.ts +1 -1
  35. package/cache/inmemory/key-extractor.d.ts.map +1 -1
  36. package/cache/inmemory/key-extractor.js +2 -2
  37. package/cache/inmemory/key-extractor.js.map +1 -1
  38. package/cache/inmemory/policies.d.ts +7 -6
  39. package/cache/inmemory/policies.d.ts.map +1 -1
  40. package/cache/inmemory/policies.js +6 -6
  41. package/cache/inmemory/policies.js.map +1 -1
  42. package/cache/inmemory/reactiveVars.d.ts +1 -1
  43. package/cache/inmemory/reactiveVars.d.ts.map +1 -1
  44. package/cache/inmemory/reactiveVars.js.map +1 -1
  45. package/cache/inmemory/readFromStore.d.ts +6 -6
  46. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  47. package/cache/inmemory/readFromStore.js +10 -5
  48. package/cache/inmemory/readFromStore.js.map +1 -1
  49. package/cache/inmemory/types.d.ts +6 -6
  50. package/cache/inmemory/types.d.ts.map +1 -1
  51. package/cache/inmemory/types.js.map +1 -1
  52. package/cache/inmemory/writeToStore.d.ts +6 -6
  53. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  54. package/cache/inmemory/writeToStore.js +7 -8
  55. package/cache/inmemory/writeToStore.js.map +1 -1
  56. package/config/jest/setup.d.ts +1 -0
  57. package/config/jest/setup.d.ts.map +1 -1
  58. package/config/jest/setup.js +3 -0
  59. package/config/jest/setup.js.map +1 -1
  60. package/core/ApolloClient.d.ts +13 -10
  61. package/core/ApolloClient.d.ts.map +1 -1
  62. package/core/ApolloClient.js +18 -16
  63. package/core/ApolloClient.js.map +1 -1
  64. package/core/DocumentTransform.d.ts +24 -0
  65. package/core/DocumentTransform.d.ts.map +1 -0
  66. package/core/DocumentTransform.js +68 -0
  67. package/core/DocumentTransform.js.map +1 -0
  68. package/core/LocalState.d.ts +7 -9
  69. package/core/LocalState.d.ts.map +1 -1
  70. package/core/LocalState.js +6 -10
  71. package/core/LocalState.js.map +1 -1
  72. package/core/ObservableQuery.d.ts +11 -8
  73. package/core/ObservableQuery.d.ts.map +1 -1
  74. package/core/ObservableQuery.js +48 -28
  75. package/core/ObservableQuery.js.map +1 -1
  76. package/core/QueryInfo.d.ts +9 -9
  77. package/core/QueryInfo.d.ts.map +1 -1
  78. package/core/QueryInfo.js.map +1 -1
  79. package/core/QueryManager.d.ts +15 -11
  80. package/core/QueryManager.d.ts.map +1 -1
  81. package/core/QueryManager.js +115 -108
  82. package/core/QueryManager.js.map +1 -1
  83. package/core/core.cjs +332 -172
  84. package/core/core.cjs.map +1 -1
  85. package/core/core.cjs.native.js +332 -172
  86. package/core/equalByQuery.d.ts +4 -0
  87. package/core/equalByQuery.d.ts.map +1 -0
  88. package/{react/hooks/compareResults.js → core/equalByQuery.js} +14 -10
  89. package/core/equalByQuery.js.map +1 -0
  90. package/core/index.d.ts +2 -1
  91. package/core/index.d.ts.map +1 -1
  92. package/core/index.js +2 -1
  93. package/core/index.js.map +1 -1
  94. package/core/networkStatus.d.ts +1 -0
  95. package/core/networkStatus.d.ts.map +1 -1
  96. package/core/networkStatus.js +3 -0
  97. package/core/networkStatus.js.map +1 -1
  98. package/core/types.d.ts +14 -14
  99. package/core/types.d.ts.map +1 -1
  100. package/core/types.js.map +1 -1
  101. package/core/watchQueryOptions.d.ts +6 -7
  102. package/core/watchQueryOptions.d.ts.map +1 -1
  103. package/core/watchQueryOptions.js.map +1 -1
  104. package/dev/dev.cjs +642 -0
  105. package/dev/dev.cjs.map +1 -0
  106. package/dev/dev.cjs.native.js +642 -0
  107. package/dev/index.d.ts +4 -0
  108. package/dev/index.d.ts.map +1 -0
  109. package/dev/index.js +4 -0
  110. package/dev/index.js.map +1 -0
  111. package/dev/loadDevMessages.d.ts +2 -0
  112. package/dev/loadDevMessages.d.ts.map +1 -0
  113. package/dev/loadDevMessages.js +6 -0
  114. package/dev/loadDevMessages.js.map +1 -0
  115. package/dev/loadErrorMessageHandler.d.ts +3 -0
  116. package/dev/loadErrorMessageHandler.d.ts.map +1 -0
  117. package/dev/loadErrorMessageHandler.js +26 -0
  118. package/dev/loadErrorMessageHandler.js.map +1 -0
  119. package/dev/loadErrorMessages.d.ts +2 -0
  120. package/dev/loadErrorMessages.d.ts.map +1 -0
  121. package/dev/loadErrorMessages.js +6 -0
  122. package/dev/loadErrorMessages.js.map +1 -0
  123. package/dev/package.json +8 -0
  124. package/errors/errors.cjs +17 -17
  125. package/errors/errors.cjs.map +1 -1
  126. package/errors/errors.cjs.native.js +17 -17
  127. package/errors/index.d.ts +26 -10
  128. package/errors/index.d.ts.map +1 -1
  129. package/errors/index.js +17 -19
  130. package/errors/index.js.map +1 -1
  131. package/invariantErrorCodes.d.ts +13 -0
  132. package/invariantErrorCodes.d.ts.map +1 -0
  133. package/invariantErrorCodes.js +331 -144
  134. package/invariantErrorCodes.js.map +1 -0
  135. package/link/batch/batchLink.d.ts +4 -3
  136. package/link/batch/batchLink.d.ts.map +1 -1
  137. package/link/batch/batchLink.js.map +1 -1
  138. package/link/batch/batching.d.ts +1 -1
  139. package/link/batch/batching.d.ts.map +1 -1
  140. package/link/batch/batching.js.map +1 -1
  141. package/link/batch-http/batch-http.cjs +23 -2
  142. package/link/batch-http/batch-http.cjs.map +1 -1
  143. package/link/batch-http/batch-http.cjs.native.js +23 -2
  144. package/link/batch-http/batchHttpLink.d.ts +3 -2
  145. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  146. package/link/batch-http/batchHttpLink.js +7 -2
  147. package/link/batch-http/batchHttpLink.js.map +1 -1
  148. package/link/context/index.d.ts +3 -2
  149. package/link/context/index.d.ts.map +1 -1
  150. package/link/context/index.js.map +1 -1
  151. package/link/core/ApolloLink.d.ts +3 -2
  152. package/link/core/ApolloLink.d.ts.map +1 -1
  153. package/link/core/ApolloLink.js +3 -13
  154. package/link/core/ApolloLink.js.map +1 -1
  155. package/link/core/core.cjs +2 -12
  156. package/link/core/core.cjs.map +1 -1
  157. package/link/core/core.cjs.native.js +2 -12
  158. package/link/core/types.d.ts +8 -3
  159. package/link/core/types.d.ts.map +1 -1
  160. package/link/core/types.js.map +1 -1
  161. package/link/error/index.d.ts +4 -3
  162. package/link/error/index.d.ts.map +1 -1
  163. package/link/error/index.js.map +1 -1
  164. package/link/http/HttpLink.d.ts +3 -2
  165. package/link/http/HttpLink.d.ts.map +1 -1
  166. package/link/http/HttpLink.js.map +1 -1
  167. package/link/http/checkFetcher.js +2 -2
  168. package/link/http/checkFetcher.js.map +1 -1
  169. package/link/http/createHttpLink.d.ts +1 -1
  170. package/link/http/createHttpLink.d.ts.map +1 -1
  171. package/link/http/createHttpLink.js +21 -20
  172. package/link/http/createHttpLink.js.map +1 -1
  173. package/link/http/http.cjs +73 -43
  174. package/link/http/http.cjs.map +1 -1
  175. package/link/http/http.cjs.native.js +73 -43
  176. package/link/http/iterators/nodeStream.d.ts +1 -1
  177. package/link/http/iterators/nodeStream.d.ts.map +1 -1
  178. package/link/http/iterators/nodeStream.js.map +1 -1
  179. package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
  180. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  181. package/link/http/parseAndCheckHttpResponse.js +47 -26
  182. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  183. package/link/http/responseIterator.d.ts +1 -1
  184. package/link/http/responseIterator.d.ts.map +1 -1
  185. package/link/http/responseIterator.js.map +1 -1
  186. package/link/http/rewriteURIForGET.d.ts +1 -1
  187. package/link/http/rewriteURIForGET.d.ts.map +1 -1
  188. package/link/http/rewriteURIForGET.js.map +1 -1
  189. package/link/http/selectHttpOptionsAndBody.d.ts +3 -2
  190. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  191. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  192. package/link/http/selectURI.d.ts +1 -1
  193. package/link/http/selectURI.d.ts.map +1 -1
  194. package/link/http/selectURI.js.map +1 -1
  195. package/link/http/serializeFetchParameter.d.ts +1 -1
  196. package/link/http/serializeFetchParameter.d.ts.map +1 -1
  197. package/link/http/serializeFetchParameter.js +2 -2
  198. package/link/http/serializeFetchParameter.js.map +1 -1
  199. package/link/persisted-queries/index.d.ts +4 -3
  200. package/link/persisted-queries/index.d.ts.map +1 -1
  201. package/link/persisted-queries/index.js +16 -20
  202. package/link/persisted-queries/index.js.map +1 -1
  203. package/link/persisted-queries/persisted-queries.cjs +15 -19
  204. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  205. package/link/persisted-queries/persisted-queries.cjs.native.js +15 -19
  206. package/link/remove-typename/index.d.ts +2 -0
  207. package/link/remove-typename/index.d.ts.map +1 -0
  208. package/link/remove-typename/index.js +2 -0
  209. package/link/remove-typename/index.js.map +1 -0
  210. package/link/remove-typename/package.json +8 -0
  211. package/link/remove-typename/remove-typename.cjs +82 -0
  212. package/link/remove-typename/remove-typename.cjs.map +1 -0
  213. package/link/remove-typename/remove-typename.cjs.native.js +82 -0
  214. package/link/remove-typename/removeTypenameFromVariables.d.ts +11 -0
  215. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +1 -0
  216. package/link/remove-typename/removeTypenameFromVariables.js +74 -0
  217. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -0
  218. package/link/retry/delayFunction.d.ts +1 -1
  219. package/link/retry/delayFunction.d.ts.map +1 -1
  220. package/link/retry/delayFunction.js.map +1 -1
  221. package/link/retry/retryFunction.d.ts +1 -1
  222. package/link/retry/retryFunction.d.ts.map +1 -1
  223. package/link/retry/retryFunction.js.map +1 -1
  224. package/link/retry/retryLink.d.ts +4 -3
  225. package/link/retry/retryLink.d.ts.map +1 -1
  226. package/link/retry/retryLink.js.map +1 -1
  227. package/link/schema/index.d.ts +3 -2
  228. package/link/schema/index.d.ts.map +1 -1
  229. package/link/schema/index.js.map +1 -1
  230. package/link/subscriptions/index.d.ts +2 -1
  231. package/link/subscriptions/index.d.ts.map +1 -1
  232. package/link/subscriptions/index.js +8 -3
  233. package/link/subscriptions/index.js.map +1 -1
  234. package/link/subscriptions/subscriptions.cjs +8 -3
  235. package/link/subscriptions/subscriptions.cjs.map +1 -1
  236. package/link/subscriptions/subscriptions.cjs.native.js +8 -3
  237. package/link/utils/createOperation.d.ts +1 -1
  238. package/link/utils/createOperation.d.ts.map +1 -1
  239. package/link/utils/createOperation.js.map +1 -1
  240. package/link/utils/filterOperationVariables.d.ts +5 -0
  241. package/link/utils/filterOperationVariables.d.ts.map +1 -0
  242. package/link/utils/filterOperationVariables.js +18 -0
  243. package/link/utils/filterOperationVariables.js.map +1 -0
  244. package/link/utils/index.d.ts +1 -0
  245. package/link/utils/index.d.ts.map +1 -1
  246. package/link/utils/index.js +1 -0
  247. package/link/utils/index.js.map +1 -1
  248. package/link/utils/throwServerError.d.ts +1 -1
  249. package/link/utils/throwServerError.d.ts.map +1 -1
  250. package/link/utils/throwServerError.js.map +1 -1
  251. package/link/utils/toPromise.d.ts +1 -1
  252. package/link/utils/toPromise.d.ts.map +1 -1
  253. package/link/utils/toPromise.js +1 -1
  254. package/link/utils/toPromise.js.map +1 -1
  255. package/link/utils/transformOperation.d.ts +1 -1
  256. package/link/utils/transformOperation.d.ts.map +1 -1
  257. package/link/utils/transformOperation.js.map +1 -1
  258. package/link/utils/utils.cjs +20 -2
  259. package/link/utils/utils.cjs.map +1 -1
  260. package/link/utils/utils.cjs.native.js +20 -2
  261. package/link/utils/validateOperation.d.ts +1 -1
  262. package/link/utils/validateOperation.d.ts.map +1 -1
  263. package/link/utils/validateOperation.js +2 -2
  264. package/link/utils/validateOperation.js.map +1 -1
  265. package/link/ws/index.d.ts +5 -3
  266. package/link/ws/index.d.ts.map +1 -1
  267. package/link/ws/index.js.map +1 -1
  268. package/package.json +36 -32
  269. package/react/cache/QueryReference.d.ts +34 -0
  270. package/react/cache/QueryReference.d.ts.map +1 -0
  271. package/react/cache/QueryReference.js +107 -0
  272. package/react/cache/QueryReference.js.map +1 -0
  273. package/react/cache/SuspenseCache.d.ts +10 -13
  274. package/react/cache/SuspenseCache.d.ts.map +1 -1
  275. package/react/cache/SuspenseCache.js +18 -41
  276. package/react/cache/SuspenseCache.js.map +1 -1
  277. package/react/cache/types.d.ts +2 -0
  278. package/react/cache/types.d.ts.map +1 -0
  279. package/react/cache/types.js +2 -0
  280. package/react/cache/types.js.map +1 -0
  281. package/react/components/Mutation.d.ts +2 -2
  282. package/react/components/Mutation.d.ts.map +1 -1
  283. package/react/components/Mutation.js.map +1 -1
  284. package/react/components/Query.d.ts +2 -2
  285. package/react/components/Query.d.ts.map +1 -1
  286. package/react/components/Query.js.map +1 -1
  287. package/react/components/Subscription.d.ts +2 -2
  288. package/react/components/Subscription.d.ts.map +1 -1
  289. package/react/components/Subscription.js.map +1 -1
  290. package/react/components/types.d.ts +4 -4
  291. package/react/components/types.d.ts.map +1 -1
  292. package/react/components/types.js.map +1 -1
  293. package/react/context/ApolloConsumer.d.ts +1 -1
  294. package/react/context/ApolloConsumer.d.ts.map +1 -1
  295. package/react/context/ApolloConsumer.js +2 -3
  296. package/react/context/ApolloConsumer.js.map +1 -1
  297. package/react/context/ApolloContext.d.ts +10 -3
  298. package/react/context/ApolloContext.d.ts.map +1 -1
  299. package/react/context/ApolloContext.js +10 -8
  300. package/react/context/ApolloContext.js.map +1 -1
  301. package/react/context/ApolloProvider.d.ts +2 -2
  302. package/react/context/ApolloProvider.d.ts.map +1 -1
  303. package/react/context/ApolloProvider.js +8 -13
  304. package/react/context/ApolloProvider.js.map +1 -1
  305. package/react/context/context.cjs +18 -22
  306. package/react/context/context.cjs.map +1 -1
  307. package/react/context/context.cjs.native.js +18 -22
  308. package/react/context/index.d.ts +1 -1
  309. package/react/context/index.d.ts.map +1 -1
  310. package/react/context/index.js +1 -1
  311. package/react/context/index.js.map +1 -1
  312. package/react/hoc/graphql.d.ts +3 -3
  313. package/react/hoc/graphql.d.ts.map +1 -1
  314. package/react/hoc/graphql.js.map +1 -1
  315. package/react/hoc/hoc-utils.d.ts +2 -2
  316. package/react/hoc/hoc-utils.d.ts.map +1 -1
  317. package/react/hoc/hoc-utils.js +2 -3
  318. package/react/hoc/hoc-utils.js.map +1 -1
  319. package/react/hoc/hoc.cjs +2 -4
  320. package/react/hoc/hoc.cjs.map +1 -1
  321. package/react/hoc/hoc.cjs.native.js +2 -4
  322. package/react/hoc/mutation-hoc.d.ts +4 -4
  323. package/react/hoc/mutation-hoc.d.ts.map +1 -1
  324. package/react/hoc/mutation-hoc.js.map +1 -1
  325. package/react/hoc/query-hoc.d.ts +2 -2
  326. package/react/hoc/query-hoc.d.ts.map +1 -1
  327. package/react/hoc/query-hoc.js.map +1 -1
  328. package/react/hoc/subscription-hoc.d.ts +2 -2
  329. package/react/hoc/subscription-hoc.d.ts.map +1 -1
  330. package/react/hoc/subscription-hoc.js.map +1 -1
  331. package/react/hoc/types.d.ts +4 -4
  332. package/react/hoc/types.d.ts.map +1 -1
  333. package/react/hoc/types.js.map +1 -1
  334. package/react/hoc/withApollo.d.ts +1 -1
  335. package/react/hoc/withApollo.d.ts.map +1 -1
  336. package/react/hoc/withApollo.js +2 -3
  337. package/react/hoc/withApollo.js.map +1 -1
  338. package/react/hooks/hooks.cjs +223 -219
  339. package/react/hooks/hooks.cjs.map +1 -1
  340. package/react/hooks/hooks.cjs.native.js +223 -219
  341. package/react/hooks/index.d.ts +2 -1
  342. package/react/hooks/index.d.ts.map +1 -1
  343. package/react/hooks/index.js +2 -1
  344. package/react/hooks/index.js.map +1 -1
  345. package/react/hooks/internal/__use.d.ts +4 -0
  346. package/react/hooks/internal/__use.d.ts.map +1 -0
  347. package/react/hooks/internal/__use.js +17 -0
  348. package/react/hooks/internal/__use.js.map +1 -0
  349. package/react/hooks/internal/index.d.ts +2 -0
  350. package/react/hooks/internal/index.d.ts.map +1 -1
  351. package/react/hooks/internal/index.js +2 -0
  352. package/react/hooks/internal/index.js.map +1 -1
  353. package/react/hooks/internal/useDeepMemo.d.ts +1 -1
  354. package/react/hooks/internal/useDeepMemo.d.ts.map +1 -1
  355. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  356. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -1
  357. package/react/hooks/internal/useIsomorphicLayoutEffect.js +2 -2
  358. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  359. package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts +2 -0
  360. package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts.map +1 -0
  361. package/react/hooks/internal/useStrictModeSafeCleanupEffect.js +11 -0
  362. package/react/hooks/internal/useStrictModeSafeCleanupEffect.js.map +1 -0
  363. package/react/hooks/useApolloClient.d.ts +1 -1
  364. package/react/hooks/useApolloClient.d.ts.map +1 -1
  365. package/react/hooks/useApolloClient.js +2 -4
  366. package/react/hooks/useApolloClient.js.map +1 -1
  367. package/react/hooks/useBackgroundQuery.d.ts +18 -0
  368. package/react/hooks/useBackgroundQuery.d.ts.map +1 -0
  369. package/react/hooks/useBackgroundQuery.js +69 -0
  370. package/react/hooks/useBackgroundQuery.js.map +1 -0
  371. package/react/hooks/useFragment.d.ts +14 -9
  372. package/react/hooks/useFragment.d.ts.map +1 -1
  373. package/react/hooks/useFragment.js +2 -2
  374. package/react/hooks/useFragment.js.map +1 -1
  375. package/react/hooks/useLazyQuery.d.ts +4 -4
  376. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  377. package/react/hooks/useLazyQuery.js +13 -22
  378. package/react/hooks/useLazyQuery.js.map +1 -1
  379. package/react/hooks/useMutation.d.ts +4 -4
  380. package/react/hooks/useMutation.d.ts.map +1 -1
  381. package/react/hooks/useMutation.js +1 -1
  382. package/react/hooks/useMutation.js.map +1 -1
  383. package/react/hooks/useQuery.d.ts +6 -6
  384. package/react/hooks/useQuery.d.ts.map +1 -1
  385. package/react/hooks/useQuery.js +29 -28
  386. package/react/hooks/useQuery.js.map +1 -1
  387. package/react/hooks/useReactiveVar.d.ts +1 -1
  388. package/react/hooks/useReactiveVar.d.ts.map +1 -1
  389. package/react/hooks/useReactiveVar.js.map +1 -1
  390. package/react/hooks/useSubscription.d.ts +4 -4
  391. package/react/hooks/useSubscription.d.ts.map +1 -1
  392. package/react/hooks/useSubscription.js +27 -19
  393. package/react/hooks/useSubscription.js.map +1 -1
  394. package/react/hooks/useSuspenseCache.d.ts +1 -1
  395. package/react/hooks/useSuspenseCache.d.ts.map +1 -1
  396. package/react/hooks/useSuspenseCache.js +2 -4
  397. package/react/hooks/useSuspenseCache.js.map +1 -1
  398. package/react/hooks/useSuspenseQuery.d.ts +39 -7
  399. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  400. package/react/hooks/useSuspenseQuery.js +68 -149
  401. package/react/hooks/useSuspenseQuery.js.map +1 -1
  402. package/react/hooks/useSyncExternalStore.js +1 -1
  403. package/react/index.d.ts +1 -1
  404. package/react/index.d.ts.map +1 -1
  405. package/react/index.js +1 -1
  406. package/react/index.js.map +1 -1
  407. package/react/parser/index.d.ts +1 -1
  408. package/react/parser/index.d.ts.map +1 -1
  409. package/react/parser/index.js +20 -17
  410. package/react/parser/index.js.map +1 -1
  411. package/react/parser/parser.cjs +19 -16
  412. package/react/parser/parser.cjs.map +1 -1
  413. package/react/parser/parser.cjs.native.js +19 -16
  414. package/react/react.cjs +116 -35
  415. package/react/react.cjs.map +1 -1
  416. package/react/react.cjs.native.js +116 -35
  417. package/react/ssr/RenderPromises.d.ts +2 -2
  418. package/react/ssr/RenderPromises.d.ts.map +1 -1
  419. package/react/ssr/RenderPromises.js.map +1 -1
  420. package/react/ssr/renderToStringWithData.d.ts +1 -1
  421. package/react/ssr/renderToStringWithData.d.ts.map +1 -1
  422. package/react/ssr/renderToStringWithData.js.map +1 -1
  423. package/react/types/types.d.ts +10 -13
  424. package/react/types/types.d.ts.map +1 -1
  425. package/react/types/types.js.map +1 -1
  426. package/testing/core/core.cjs +1 -1
  427. package/testing/core/core.cjs.map +1 -1
  428. package/testing/core/core.cjs.native.js +1 -1
  429. package/testing/core/mocking/mockClient.d.ts +2 -2
  430. package/testing/core/mocking/mockClient.d.ts.map +1 -1
  431. package/testing/core/mocking/mockClient.js.map +1 -1
  432. package/testing/core/mocking/mockLink.d.ts +2 -1
  433. package/testing/core/mocking/mockLink.d.ts.map +1 -1
  434. package/testing/core/mocking/mockLink.js +3 -3
  435. package/testing/core/mocking/mockLink.js.map +1 -1
  436. package/testing/core/mocking/mockQueryManager.d.ts +1 -1
  437. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -1
  438. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  439. package/testing/core/mocking/mockSubscriptionLink.d.ts +3 -2
  440. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -1
  441. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  442. package/testing/core/mocking/mockWatchQuery.d.ts +2 -2
  443. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -1
  444. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  445. package/testing/core/observableToPromise.d.ts +2 -2
  446. package/testing/core/observableToPromise.d.ts.map +1 -1
  447. package/testing/core/observableToPromise.js.map +1 -1
  448. package/testing/core/subscribeAndCount.d.ts +1 -1
  449. package/testing/core/subscribeAndCount.d.ts.map +1 -1
  450. package/testing/core/subscribeAndCount.js.map +1 -1
  451. package/testing/matchers/index.d.ts +2 -0
  452. package/testing/matchers/index.d.ts.map +1 -0
  453. package/testing/matchers/index.js +6 -0
  454. package/testing/matchers/index.js.map +1 -0
  455. package/testing/matchers/toMatchDocument.d.ts +4 -0
  456. package/testing/matchers/toMatchDocument.d.ts.map +1 -0
  457. package/testing/matchers/toMatchDocument.js +34 -0
  458. package/testing/matchers/toMatchDocument.js.map +1 -0
  459. package/testing/react/MockedProvider.d.ts +8 -7
  460. package/testing/react/MockedProvider.d.ts.map +1 -1
  461. package/testing/react/MockedProvider.js +7 -6
  462. package/testing/react/MockedProvider.js.map +1 -1
  463. package/testing/testing.cjs +7 -51
  464. package/testing/testing.cjs.map +1 -1
  465. package/testing/testing.cjs.native.js +7 -51
  466. package/utilities/common/compact.d.ts +1 -1
  467. package/utilities/common/compact.d.ts.map +1 -1
  468. package/utilities/common/compact.js.map +1 -1
  469. package/utilities/common/errorHandling.d.ts +1 -1
  470. package/utilities/common/errorHandling.d.ts.map +1 -1
  471. package/utilities/common/errorHandling.js.map +1 -1
  472. package/utilities/common/incrementalResult.d.ts +2 -1
  473. package/utilities/common/incrementalResult.d.ts.map +1 -1
  474. package/utilities/common/incrementalResult.js +4 -0
  475. package/utilities/common/incrementalResult.js.map +1 -1
  476. package/utilities/common/mergeOptions.d.ts +1 -1
  477. package/utilities/common/mergeOptions.d.ts.map +1 -1
  478. package/utilities/common/mergeOptions.js +1 -1
  479. package/utilities/common/mergeOptions.js.map +1 -1
  480. package/utilities/common/objects.d.ts +1 -0
  481. package/utilities/common/objects.d.ts.map +1 -1
  482. package/utilities/common/objects.js +6 -0
  483. package/utilities/common/objects.js.map +1 -1
  484. package/utilities/common/omitDeep.d.ts +3 -0
  485. package/utilities/common/omitDeep.d.ts.map +1 -0
  486. package/utilities/common/omitDeep.js +41 -0
  487. package/utilities/common/omitDeep.js.map +1 -0
  488. package/utilities/common/responseIterator.d.ts +2 -2
  489. package/utilities/common/responseIterator.d.ts.map +1 -1
  490. package/utilities/common/responseIterator.js.map +1 -1
  491. package/utilities/common/stringifyForDisplay.d.ts +1 -1
  492. package/utilities/common/stringifyForDisplay.d.ts.map +1 -1
  493. package/utilities/common/stringifyForDisplay.js +3 -2
  494. package/utilities/common/stringifyForDisplay.js.map +1 -1
  495. package/utilities/common/stripTypename.d.ts +2 -0
  496. package/utilities/common/stripTypename.d.ts.map +1 -0
  497. package/utilities/common/stripTypename.js +5 -0
  498. package/utilities/common/stripTypename.js.map +1 -0
  499. package/utilities/globals/global.d.ts +6 -3
  500. package/utilities/globals/global.d.ts.map +1 -1
  501. package/utilities/globals/global.js.map +1 -1
  502. package/utilities/globals/globals.cjs +67 -1
  503. package/utilities/globals/globals.cjs.map +1 -1
  504. package/utilities/globals/globals.cjs.native.js +67 -1
  505. package/utilities/globals/index.d.ts +2 -2
  506. package/utilities/globals/index.d.ts.map +1 -1
  507. package/utilities/globals/index.js +2 -2
  508. package/utilities/globals/index.js.map +1 -1
  509. package/utilities/globals/invariantWrappers.d.ts +24 -0
  510. package/utilities/globals/invariantWrappers.d.ts.map +1 -0
  511. package/utilities/globals/invariantWrappers.js +53 -0
  512. package/utilities/globals/invariantWrappers.js.map +1 -0
  513. package/utilities/graphql/directives.d.ts +1 -1
  514. package/utilities/graphql/directives.d.ts.map +1 -1
  515. package/utilities/graphql/directives.js +6 -7
  516. package/utilities/graphql/directives.js.map +1 -1
  517. package/utilities/graphql/fragments.d.ts +1 -1
  518. package/utilities/graphql/fragments.d.ts.map +1 -1
  519. package/utilities/graphql/fragments.js +8 -5
  520. package/utilities/graphql/fragments.js.map +1 -1
  521. package/utilities/graphql/getFromAST.d.ts +1 -1
  522. package/utilities/graphql/getFromAST.d.ts.map +1 -1
  523. package/utilities/graphql/getFromAST.js +9 -9
  524. package/utilities/graphql/getFromAST.js.map +1 -1
  525. package/utilities/graphql/operations.d.ts +5 -0
  526. package/utilities/graphql/operations.d.ts.map +1 -0
  527. package/utilities/graphql/operations.js +16 -0
  528. package/utilities/graphql/operations.js.map +1 -0
  529. package/utilities/graphql/storeUtils.d.ts +2 -2
  530. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  531. package/utilities/graphql/storeUtils.js +16 -7
  532. package/utilities/graphql/storeUtils.js.map +1 -1
  533. package/utilities/graphql/transform.d.ts +1 -1
  534. package/utilities/graphql/transform.d.ts.map +1 -1
  535. package/utilities/graphql/transform.js +30 -21
  536. package/utilities/graphql/transform.js.map +1 -1
  537. package/utilities/index.d.ts +6 -0
  538. package/utilities/index.d.ts.map +1 -1
  539. package/utilities/index.js +4 -0
  540. package/utilities/index.js.map +1 -1
  541. package/utilities/observables/Concast.d.ts +2 -1
  542. package/utilities/observables/Concast.d.ts.map +1 -1
  543. package/utilities/observables/Concast.js.map +1 -1
  544. package/utilities/observables/Observable.d.ts +2 -1
  545. package/utilities/observables/Observable.d.ts.map +1 -1
  546. package/utilities/observables/Observable.js +1 -1
  547. package/utilities/observables/Observable.js.map +1 -1
  548. package/utilities/observables/asyncMap.d.ts.map +1 -1
  549. package/utilities/observables/asyncMap.js.map +1 -1
  550. package/utilities/observables/iteration.d.ts +1 -1
  551. package/utilities/observables/iteration.d.ts.map +1 -1
  552. package/utilities/observables/iteration.js.map +1 -1
  553. package/utilities/policies/pagination.d.ts +1 -1
  554. package/utilities/policies/pagination.d.ts.map +1 -1
  555. package/utilities/policies/pagination.js.map +1 -1
  556. package/utilities/promises/decoration.d.ts +17 -0
  557. package/utilities/promises/decoration.d.ts.map +1 -0
  558. package/utilities/promises/decoration.js +37 -0
  559. package/utilities/promises/decoration.js.map +1 -0
  560. package/utilities/types/DeepOmit.d.ts +10 -0
  561. package/utilities/types/DeepOmit.d.ts.map +1 -0
  562. package/utilities/types/DeepOmit.js +2 -0
  563. package/utilities/types/DeepOmit.js.map +1 -0
  564. package/utilities/types/DeepPartial.d.ts +12 -0
  565. package/utilities/types/DeepPartial.d.ts.map +1 -0
  566. package/utilities/types/DeepPartial.js +2 -0
  567. package/utilities/types/DeepPartial.js.map +1 -0
  568. package/utilities/types/Primitive.d.ts +2 -0
  569. package/utilities/types/Primitive.d.ts.map +1 -0
  570. package/utilities/types/Primitive.js +2 -0
  571. package/utilities/types/Primitive.js.map +1 -0
  572. package/utilities/utilities.cjs +181 -45
  573. package/utilities/utilities.cjs.map +1 -1
  574. package/utilities/utilities.cjs.native.js +181 -45
  575. package/version.js +1 -1
  576. package/cache/inmemory/__mocks__/optimism.d.ts +0 -2
  577. package/cache/inmemory/__mocks__/optimism.d.ts.map +0 -1
  578. package/cache/inmemory/__mocks__/optimism.js +0 -14
  579. package/cache/inmemory/__mocks__/optimism.js.map +0 -1
  580. package/react/hooks/compareResults.d.ts +0 -3
  581. package/react/hooks/compareResults.d.ts.map +0 -1
  582. package/react/hooks/compareResults.js.map +0 -1
package/apollo-client.cjs CHANGED
@@ -3,18 +3,20 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
- var tsInvariant = require('ts-invariant');
7
6
  var process$1 = require('ts-invariant/process');
8
7
  var graphql = require('graphql');
9
- var equality = require('@wry/equality');
8
+ var equal = require('@wry/equality');
9
+ var tsInvariant = require('ts-invariant');
10
10
  var zenObservableTs = require('zen-observable-ts');
11
11
  require('symbol-observable');
12
+ var trie = require('@wry/trie');
12
13
  var optimism = require('optimism');
13
14
  var context = require('@wry/context');
14
- var trie = require('@wry/trie');
15
15
  var graphqlTag = require('graphql-tag');
16
16
  var React = require('react');
17
17
 
18
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
19
+
18
20
  function _interopNamespace(e) {
19
21
  if (e && e.__esModule) return e;
20
22
  var n = Object.create(null);
@@ -27,7 +29,11 @@ function _interopNamespace(e) {
27
29
  return Object.freeze(n);
28
30
  }
29
31
 
32
+ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
30
33
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
35
+
36
+ var version = '3.8.0-beta.0';
31
37
 
32
38
  function maybe(thunk) {
33
39
  try {
@@ -42,6 +48,68 @@ var global$1 = (maybe(function () { return globalThis; }) ||
42
48
  maybe(function () { return global; }) ||
43
49
  maybe(function () { return maybe.constructor("return this")(); }));
44
50
 
51
+ var prefixCounts = new Map();
52
+ function makeUniqueId(prefix) {
53
+ var count = prefixCounts.get(prefix) || 1;
54
+ prefixCounts.set(prefix, count + 1);
55
+ return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
56
+ }
57
+
58
+ function stringifyForDisplay(value, space) {
59
+ if (space === void 0) { space = 0; }
60
+ var undefId = makeUniqueId("stringifyForDisplay");
61
+ return JSON.stringify(value, function (key, value) {
62
+ return value === void 0 ? undefId : value;
63
+ }, space).split(JSON.stringify(undefId)).join("<undefined>");
64
+ }
65
+
66
+ function wrap(fn) {
67
+ return function (message) {
68
+ var args = [];
69
+ for (var _i = 1; _i < arguments.length; _i++) {
70
+ args[_i - 1] = arguments[_i];
71
+ }
72
+ fn.apply(void 0, tslib.__spreadArray([typeof message === 'number' ? getErrorMsg(message) : message], args, false));
73
+ };
74
+ }
75
+ var invariant = Object.assign(function invariant(condition, message) {
76
+ var args = [];
77
+ for (var _i = 2; _i < arguments.length; _i++) {
78
+ args[_i - 2] = arguments[_i];
79
+ }
80
+ if (!condition) {
81
+ tsInvariant.invariant(condition, getErrorMsg(message, args));
82
+ }
83
+ }, {
84
+ debug: wrap(tsInvariant.invariant.debug),
85
+ log: wrap(tsInvariant.invariant.log),
86
+ warn: wrap(tsInvariant.invariant.warn),
87
+ error: wrap(tsInvariant.invariant.error),
88
+ });
89
+ function newInvariantError(message) {
90
+ var optionalParams = [];
91
+ for (var _i = 1; _i < arguments.length; _i++) {
92
+ optionalParams[_i - 1] = arguments[_i];
93
+ }
94
+ return new tsInvariant.InvariantError(getErrorMsg(message, optionalParams));
95
+ }
96
+ var ApolloErrorMessageHandler = Symbol.for('ApolloErrorMessageHandler_' + version);
97
+ function getErrorMsg(message, messageArgs) {
98
+ if (messageArgs === void 0) { messageArgs = []; }
99
+ if (!message)
100
+ return;
101
+ var args = messageArgs.map(function (arg) {
102
+ return typeof arg == 'string' ? arg : stringifyForDisplay(arg, 2).slice(0, 1000);
103
+ });
104
+ return ((global$1[ApolloErrorMessageHandler] &&
105
+ global$1[ApolloErrorMessageHandler](message, args)) ||
106
+ "An error occured! For more details, see the full error text at https://go.apollo.dev/c/err#".concat(encodeURIComponent(JSON.stringify({
107
+ version: version,
108
+ message: message,
109
+ args: args,
110
+ }))));
111
+ }
112
+
45
113
  var DEV = ("__DEV__" in global$1
46
114
  ? Boolean(global$1.__DEV__)
47
115
  : maybe(function () { return process.env.NODE_ENV; }) !== "production");
@@ -63,7 +131,7 @@ function shouldInclude(_a, variables) {
63
131
  var evaledValue = false;
64
132
  if (ifArgument.value.kind === 'Variable') {
65
133
  evaledValue = variables && variables[ifArgument.value.name.value];
66
- __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 41);
134
+ invariant(evaledValue !== void 0, 66, directive.name.value);
67
135
  }
68
136
  else {
69
137
  evaledValue = ifArgument.value.value;
@@ -99,13 +167,12 @@ function getInclusionDirectives(directives) {
99
167
  return;
100
168
  var directiveArguments = directive.arguments;
101
169
  var directiveName = directive.name.value;
102
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 42);
170
+ invariant(directiveArguments && directiveArguments.length === 1, 67, directiveName);
103
171
  var ifArgument = directiveArguments[0];
104
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 43);
172
+ invariant(ifArgument.name && ifArgument.name.value === 'if', 68, directiveName);
105
173
  var ifValue = ifArgument.value;
106
- __DEV__ ? tsInvariant.invariant(ifValue &&
107
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
108
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 44);
174
+ invariant(ifValue &&
175
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 69, directiveName);
109
176
  result.push({ directive: directive, ifArgument: ifArgument });
110
177
  });
111
178
  }
@@ -117,15 +184,18 @@ function getFragmentQueryDocument(document, fragmentName) {
117
184
  var fragments = [];
118
185
  document.definitions.forEach(function (definition) {
119
186
  if (definition.kind === 'OperationDefinition') {
120
- throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
121
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(45);
187
+ throw newInvariantError(
188
+ 70,
189
+ definition.operation,
190
+ definition.name ? " named '".concat(definition.name.value, "'") : ''
191
+ );
122
192
  }
123
193
  if (definition.kind === 'FragmentDefinition') {
124
194
  fragments.push(definition);
125
195
  }
126
196
  });
127
197
  if (typeof actualFragmentName === 'undefined') {
128
- __DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : tsInvariant.invariant(fragments.length === 1, 46);
198
+ invariant(fragments.length === 1, 71, fragments.length);
129
199
  actualFragmentName = fragments[0].name.value;
130
200
  }
131
201
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -166,7 +236,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
166
236
  return fragmentMap(fragmentName);
167
237
  }
168
238
  var fragment = fragmentMap && fragmentMap[fragmentName];
169
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 47);
239
+ invariant(fragment, 72, fragmentName);
170
240
  return fragment || null;
171
241
  }
172
242
  default:
@@ -248,9 +318,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
248
318
  argObj[name.value] = null;
249
319
  }
250
320
  else {
251
- throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
252
- 'is not supported. Use variables instead of inline arguments to ' +
253
- 'overcome this limitation.') : new tsInvariant.InvariantError(56);
321
+ throw newInvariantError(81, name.value, value.kind);
254
322
  }
255
323
  }
256
324
  function storeKeyNameFromField(field, variables) {
@@ -284,6 +352,7 @@ var KNOWN_DIRECTIVES = [
284
352
  'client',
285
353
  'rest',
286
354
  'export',
355
+ 'nonreactive',
287
356
  ];
288
357
  var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
289
358
  if (args &&
@@ -358,9 +427,7 @@ function resultKeyNameFromField(field) {
358
427
  return field.alias ? field.alias.value : field.name.value;
359
428
  }
360
429
  function getTypenameFromResult(result, selectionSet, fragmentMap) {
361
- if (typeof result.__typename === 'string') {
362
- return result.__typename;
363
- }
430
+ var fragments;
364
431
  for (var _i = 0, _a = selectionSet.selections; _i < _a.length; _i++) {
365
432
  var selection = _a[_i];
366
433
  if (isField(selection)) {
@@ -368,7 +435,19 @@ function getTypenameFromResult(result, selectionSet, fragmentMap) {
368
435
  return result[resultKeyNameFromField(selection)];
369
436
  }
370
437
  }
438
+ else if (fragments) {
439
+ fragments.push(selection);
440
+ }
371
441
  else {
442
+ fragments = [selection];
443
+ }
444
+ }
445
+ if (typeof result.__typename === 'string') {
446
+ return result.__typename;
447
+ }
448
+ if (fragments) {
449
+ for (var _b = 0, fragments_1 = fragments; _b < fragments_1.length; _b++) {
450
+ var selection = fragments_1[_b];
372
451
  var typename = getTypenameFromResult(result, getFragmentFromSelection(selection, fragmentMap).selectionSet, fragmentMap);
373
452
  if (typeof typename === 'string') {
374
453
  return typename;
@@ -384,16 +463,16 @@ function isInlineFragment(selection) {
384
463
  }
385
464
 
386
465
  function checkDocument(doc) {
387
- __DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 48);
466
+ invariant(doc && doc.kind === 'Document', 73);
388
467
  var operations = doc.definitions
389
468
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
390
469
  .map(function (definition) {
391
470
  if (definition.kind !== 'OperationDefinition') {
392
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(49);
471
+ throw newInvariantError(74, definition.kind);
393
472
  }
394
473
  return definition;
395
474
  });
396
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 50);
475
+ invariant(operations.length <= 1, 75, operations.length);
397
476
  return doc;
398
477
  }
399
478
  function getOperationDefinition(doc) {
@@ -416,14 +495,14 @@ function getFragmentDefinitions(doc) {
416
495
  }
417
496
  function getQueryDefinition(doc) {
418
497
  var queryDef = getOperationDefinition(doc);
419
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 51);
498
+ invariant(queryDef && queryDef.operation === 'query', 76);
420
499
  return queryDef;
421
500
  }
422
501
  function getFragmentDefinition(doc) {
423
- __DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 52);
424
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 53);
502
+ invariant(doc.kind === 'Document', 77);
503
+ invariant(doc.definitions.length <= 1, 78);
425
504
  var fragmentDef = doc.definitions[0];
426
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 54);
505
+ invariant(fragmentDef.kind === 'FragmentDefinition', 79);
427
506
  return fragmentDef;
428
507
  }
429
508
  function getMainDefinition(queryDoc) {
@@ -446,7 +525,7 @@ function getMainDefinition(queryDoc) {
446
525
  if (fragmentDefinition) {
447
526
  return fragmentDefinition;
448
527
  }
449
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(55);
528
+ throw newInvariantError(80);
450
529
  }
451
530
  function getDefaultValues(definition) {
452
531
  var defaultValues = Object.create(null);
@@ -482,19 +561,30 @@ function nullIfDocIsEmpty(doc) {
482
561
  ? null
483
562
  : doc;
484
563
  }
485
- function getDirectiveMatcher(directives) {
486
- var nameSet = new Set();
487
- var tests = [];
488
- directives.forEach(function (directive) {
489
- if (directive.name) {
490
- nameSet.add(directive.name);
491
- }
492
- else if (directive.test) {
493
- tests.push(directive.test);
564
+ function getDirectiveMatcher(configs) {
565
+ var names = new Map();
566
+ var tests = new Map();
567
+ configs.forEach(function (directive) {
568
+ if (directive) {
569
+ if (directive.name) {
570
+ names.set(directive.name, directive);
571
+ }
572
+ else if (directive.test) {
573
+ tests.set(directive.test, directive);
574
+ }
494
575
  }
495
576
  });
496
- return function (directive) { return (nameSet.has(directive.name.value) ||
497
- tests.some(function (test) { return test(directive); })); };
577
+ return function (directive) {
578
+ var config = names.get(directive.name.value);
579
+ if (!config && tests.size) {
580
+ tests.forEach(function (testConfig, test) {
581
+ if (test(directive)) {
582
+ config = testConfig;
583
+ }
584
+ });
585
+ }
586
+ return config;
587
+ };
498
588
  }
499
589
  function makeInUseGetterFunction(defaultKey) {
500
590
  var map = new Map();
@@ -511,6 +601,7 @@ function makeInUseGetterFunction(defaultKey) {
511
601
  };
512
602
  }
513
603
  function removeDirectivesFromDocument(directives, doc) {
604
+ checkDocument(doc);
514
605
  var getInUseByOperationName = makeInUseGetterFunction("");
515
606
  var getInUseByFragmentName = makeInUseGetterFunction("");
516
607
  var getInUse = function (ancestors) {
@@ -524,7 +615,7 @@ function removeDirectivesFromDocument(directives, doc) {
524
615
  return getInUseByFragmentName(ancestor.name.value);
525
616
  }
526
617
  }
527
- __DEV__ && tsInvariant.invariant.error("Could not find operation or fragment");
618
+ __DEV__ && invariant.error(82);
528
619
  return null;
529
620
  };
530
621
  var operationCount = 0;
@@ -534,10 +625,8 @@ function removeDirectivesFromDocument(directives, doc) {
534
625
  }
535
626
  }
536
627
  var directiveMatcher = getDirectiveMatcher(directives);
537
- var hasRemoveDirective = directives.some(function (directive) { return directive.remove; });
538
- var shouldRemoveField = function (nodeDirectives) { return (hasRemoveDirective &&
539
- nodeDirectives &&
540
- nodeDirectives.some(directiveMatcher)); };
628
+ var shouldRemoveField = function (nodeDirectives) { return (isNonEmptyArray(nodeDirectives) &&
629
+ nodeDirectives.map(directiveMatcher).some(function (config) { return config && config.remove; })); };
541
630
  var originalFragmentDefsByPath = new Map();
542
631
  var firstVisitMadeChanges = false;
543
632
  var fieldOrInlineFragmentVisitor = {
@@ -696,22 +785,6 @@ var addTypenameToDocument = Object.assign(function (doc) {
696
785
  return field === TYPENAME_FIELD;
697
786
  },
698
787
  });
699
- var connectionRemoveConfig = {
700
- test: function (directive) {
701
- var willRemove = directive.name.value === 'connection';
702
- if (willRemove) {
703
- if (!directive.arguments ||
704
- !directive.arguments.some(function (arg) { return arg.name.value === 'key'; })) {
705
- __DEV__ && tsInvariant.invariant.warn('Removing an @connection directive even though it does not have a key. ' +
706
- 'You may want to use the key parameter to specify a store key.');
707
- }
708
- }
709
- return willRemove;
710
- },
711
- };
712
- function removeConnectionDirectiveFromDocument(doc) {
713
- return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
714
- }
715
788
  function buildQueryFromSelectionSet(document) {
716
789
  var definition = getMainDefinition(document);
717
790
  var definitionOperation = definition.operation;
@@ -811,6 +884,43 @@ var DeepMerger = (function () {
811
884
  return DeepMerger;
812
885
  }());
813
886
 
887
+ function createFulfilledPromise(value) {
888
+ var promise = Promise.resolve(value);
889
+ promise.status = 'fulfilled';
890
+ promise.value = value;
891
+ return promise;
892
+ }
893
+ function createRejectedPromise(reason) {
894
+ var promise = Promise.reject(reason);
895
+ promise.status = 'rejected';
896
+ promise.reason = reason;
897
+ return promise;
898
+ }
899
+ function isStatefulPromise(promise) {
900
+ return 'status' in promise;
901
+ }
902
+ function wrapPromiseWithState(promise) {
903
+ if (isStatefulPromise(promise)) {
904
+ return promise;
905
+ }
906
+ var pendingPromise = promise;
907
+ pendingPromise.status = 'pending';
908
+ pendingPromise.then(function (value) {
909
+ if (pendingPromise.status === 'pending') {
910
+ var fulfilledPromise = pendingPromise;
911
+ fulfilledPromise.status = 'fulfilled';
912
+ fulfilledPromise.value = value;
913
+ }
914
+ }, function (reason) {
915
+ if (pendingPromise.status === 'pending') {
916
+ var rejectedPromise = pendingPromise;
917
+ rejectedPromise.status = 'rejected';
918
+ rejectedPromise.reason = reason;
919
+ }
920
+ });
921
+ return promise;
922
+ }
923
+
814
924
  var toString = Object.prototype.toString;
815
925
  function cloneDeep(value) {
816
926
  return cloneDeepHelper(value);
@@ -1093,6 +1203,9 @@ function isExecutionPatchResult(value) {
1093
1203
  return (isExecutionPatchIncrementalResult(value) ||
1094
1204
  isExecutionPatchInitialResult(value));
1095
1205
  }
1206
+ function isApolloPayloadResult(value) {
1207
+ return isNonNullObject(value) && "payload" in value;
1208
+ }
1096
1209
  function mergeIncrementalData(prevResult, result) {
1097
1210
  var mergedData = prevResult;
1098
1211
  var merger = new DeepMerger();
@@ -1151,23 +1264,9 @@ function compact() {
1151
1264
  return result;
1152
1265
  }
1153
1266
 
1154
- var prefixCounts = new Map();
1155
- function makeUniqueId(prefix) {
1156
- var count = prefixCounts.get(prefix) || 1;
1157
- prefixCounts.set(prefix, count + 1);
1158
- return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
1159
- }
1160
-
1161
- function stringifyForDisplay(value) {
1162
- var undefId = makeUniqueId("stringifyForDisplay");
1163
- return JSON.stringify(value, function (key, value) {
1164
- return value === void 0 ? undefId : value;
1165
- }).split(JSON.stringify(undefId)).join("<undefined>");
1166
- }
1167
-
1168
1267
  function mergeOptions(defaults, options) {
1169
1268
  return compact(defaults, options, options.variables && {
1170
- variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
1269
+ variables: compact(tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables)),
1171
1270
  });
1172
1271
  }
1173
1272
 
@@ -1203,7 +1302,7 @@ function toPromise(observable) {
1203
1302
  observable.subscribe({
1204
1303
  next: function (data) {
1205
1304
  if (completed) {
1206
- __DEV__ && tsInvariant.invariant.warn("Promise Wrapper does not support multiple results from Observable");
1305
+ __DEV__ && invariant.warn(42);
1207
1306
  }
1208
1307
  else {
1209
1308
  completed = true;
@@ -1246,7 +1345,7 @@ function validateOperation(operation) {
1246
1345
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1247
1346
  var key = _a[_i];
1248
1347
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1249
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: ".concat(key)) : new tsInvariant.InvariantError(27);
1348
+ throw newInvariantError(43, key);
1250
1349
  }
1251
1350
  }
1252
1351
  return operation;
@@ -1290,6 +1389,22 @@ function transformOperation(operation) {
1290
1389
  return transformedOperation;
1291
1390
  }
1292
1391
 
1392
+ function filterOperationVariables(variables, operation) {
1393
+ var result = tslib.__assign({}, variables);
1394
+ var unusedNames = new Set(Object.keys(variables));
1395
+ graphql.visit(operation.query, {
1396
+ Variable: function (node, _key, parent) {
1397
+ if (parent && parent.kind !== 'VariableDefinition') {
1398
+ unusedNames.delete(node.name.value);
1399
+ }
1400
+ },
1401
+ });
1402
+ unusedNames.forEach(function (name) {
1403
+ delete result[name];
1404
+ });
1405
+ return result;
1406
+ }
1407
+
1293
1408
  function passthrough(op, forward) {
1294
1409
  return (forward ? forward(op) : zenObservableTs.Observable.of());
1295
1410
  }
@@ -1299,15 +1414,6 @@ function toLink(handler) {
1299
1414
  function isTerminating(link) {
1300
1415
  return link.request.length <= 1;
1301
1416
  }
1302
- var LinkError = (function (_super) {
1303
- tslib.__extends(LinkError, _super);
1304
- function LinkError(message, link) {
1305
- var _this = _super.call(this, message) || this;
1306
- _this.link = link;
1307
- return _this;
1308
- }
1309
- return LinkError;
1310
- }(Error));
1311
1417
  var ApolloLink = (function () {
1312
1418
  function ApolloLink(request) {
1313
1419
  if (request)
@@ -1345,7 +1451,7 @@ var ApolloLink = (function () {
1345
1451
  ApolloLink.concat = function (first, second) {
1346
1452
  var firstLink = toLink(first);
1347
1453
  if (isTerminating(firstLink)) {
1348
- __DEV__ && tsInvariant.invariant.warn(new LinkError("You are calling concat on a terminating link, which will have no effect", firstLink));
1454
+ __DEV__ && invariant.warn(35, firstLink);
1349
1455
  return firstLink;
1350
1456
  }
1351
1457
  var nextLink = toLink(second);
@@ -1369,7 +1475,7 @@ var ApolloLink = (function () {
1369
1475
  return ApolloLink.concat(this, next);
1370
1476
  };
1371
1477
  ApolloLink.prototype.request = function (operation, forward) {
1372
- throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(22);
1478
+ throw newInvariantError(36);
1373
1479
  };
1374
1480
  ApolloLink.prototype.onError = function (error, observer) {
1375
1481
  if (observer && observer.error) {
@@ -1395,8 +1501,6 @@ var concat = ApolloLink.concat;
1395
1501
 
1396
1502
  var execute = ApolloLink.execute;
1397
1503
 
1398
- var version = '3.8.0-alpha.9';
1399
-
1400
1504
  function asyncIterator(source) {
1401
1505
  var _a;
1402
1506
  var iterator = source[Symbol.asyncIterator]();
@@ -1540,60 +1644,115 @@ function responseIterator(response) {
1540
1644
  throw new Error("Unknown body type for responseIterator. Please pass a streamable response.");
1541
1645
  }
1542
1646
 
1647
+ var PROTOCOL_ERRORS_SYMBOL = Symbol();
1648
+ function graphQLResultHasProtocolErrors(result) {
1649
+ if (result.extensions) {
1650
+ return Array.isArray(result.extensions[PROTOCOL_ERRORS_SYMBOL]);
1651
+ }
1652
+ return false;
1653
+ }
1654
+ function isApolloError(err) {
1655
+ return err.hasOwnProperty('graphQLErrors');
1656
+ }
1657
+ var generateErrorMessage = function (err) {
1658
+ var errors = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], err.graphQLErrors, true), err.clientErrors, true), err.protocolErrors, true);
1659
+ if (err.networkError)
1660
+ errors.push(err.networkError);
1661
+ return errors
1662
+ .map(function (err) { return isNonNullObject(err) && err.message || 'Error message not found.'; })
1663
+ .join('\n');
1664
+ };
1665
+ var ApolloError = (function (_super) {
1666
+ tslib.__extends(ApolloError, _super);
1667
+ function ApolloError(_a) {
1668
+ var graphQLErrors = _a.graphQLErrors, protocolErrors = _a.protocolErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
1669
+ var _this = _super.call(this, errorMessage) || this;
1670
+ _this.name = 'ApolloError';
1671
+ _this.graphQLErrors = graphQLErrors || [];
1672
+ _this.protocolErrors = protocolErrors || [];
1673
+ _this.clientErrors = clientErrors || [];
1674
+ _this.networkError = networkError || null;
1675
+ _this.message = errorMessage || generateErrorMessage(_this);
1676
+ _this.extraInfo = extraInfo;
1677
+ _this.__proto__ = ApolloError.prototype;
1678
+ return _this;
1679
+ }
1680
+ return ApolloError;
1681
+ }(Error));
1682
+
1543
1683
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1544
1684
  function readMultipartBody(response, observer) {
1545
- var _a, _b, _c;
1685
+ var _a, _b, _c, _d, _e;
1546
1686
  return tslib.__awaiter(this, void 0, void 0, function () {
1547
- var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _d, value, done, chunk, bi, message, i, headers, contentType_1, body, result;
1548
- var _e;
1549
- return tslib.__generator(this, function (_f) {
1550
- switch (_f.label) {
1687
+ var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _f, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
1688
+ var _g, _h;
1689
+ return tslib.__generator(this, function (_j) {
1690
+ switch (_j.label) {
1551
1691
  case 0:
1552
1692
  if (TextDecoder === undefined) {
1553
1693
  throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
1554
1694
  }
1555
1695
  decoder = new TextDecoder("utf-8");
1556
- contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get('content-type');
1696
+ contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
1557
1697
  delimiter = "boundary=";
1558
1698
  boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter))
1559
1699
  ? contentType === null || contentType === void 0 ? void 0 : contentType.substring((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(delimiter)) + delimiter.length).replace(/['"]/g, "").replace(/\;(.*)/gm, "").trim()
1560
1700
  : "-";
1561
- boundary = "--".concat(boundaryVal);
1701
+ boundary = "\r\n--".concat(boundaryVal);
1562
1702
  buffer = "";
1563
1703
  iterator = responseIterator(response);
1564
1704
  running = true;
1565
- _f.label = 1;
1705
+ _j.label = 1;
1566
1706
  case 1:
1567
1707
  if (!running) return [3, 3];
1568
1708
  return [4, iterator.next()];
1569
1709
  case 2:
1570
- _d = _f.sent(), value = _d.value, done = _d.done;
1710
+ _f = _j.sent(), value = _f.value, done = _f.done;
1571
1711
  chunk = typeof value === "string" ? value : decoder.decode(value);
1712
+ searchFrom = buffer.length - boundary.length + 1;
1572
1713
  running = !done;
1573
1714
  buffer += chunk;
1574
- bi = buffer.indexOf(boundary);
1715
+ bi = buffer.indexOf(boundary, searchFrom);
1575
1716
  while (bi > -1) {
1576
1717
  message = void 0;
1577
- _e = [
1718
+ _g = [
1578
1719
  buffer.slice(0, bi),
1579
1720
  buffer.slice(bi + boundary.length),
1580
- ], message = _e[0], buffer = _e[1];
1581
- if (message.trim()) {
1582
- i = message.indexOf("\r\n\r\n");
1583
- headers = parseHeaders(message.slice(0, i));
1584
- contentType_1 = headers["content-type"];
1585
- if (contentType_1 &&
1586
- contentType_1.toLowerCase().indexOf("application/json") === -1) {
1587
- throw new Error("Unsupported patch content type: application/json is required.");
1588
- }
1589
- body = message.slice(i);
1721
+ ], message = _g[0], buffer = _g[1];
1722
+ i = message.indexOf("\r\n\r\n");
1723
+ headers = parseHeaders(message.slice(0, i));
1724
+ contentType_1 = headers["content-type"];
1725
+ if (contentType_1 &&
1726
+ contentType_1.toLowerCase().indexOf("application/json") === -1) {
1727
+ throw new Error("Unsupported patch content type: application/json is required.");
1728
+ }
1729
+ body = message.slice(i);
1730
+ if (body) {
1590
1731
  try {
1591
- result = parseJsonBody(response, body.replace("\r\n", ""));
1732
+ result = parseJsonBody(response, body);
1592
1733
  if (Object.keys(result).length > 1 ||
1593
1734
  "data" in result ||
1594
1735
  "incremental" in result ||
1595
- "errors" in result) {
1596
- (_b = observer.next) === null || _b === void 0 ? void 0 : _b.call(observer, result);
1736
+ "errors" in result ||
1737
+ "payload" in result) {
1738
+ if (isApolloPayloadResult(result)) {
1739
+ next = {};
1740
+ if ("payload" in result) {
1741
+ next = tslib.__assign({}, result.payload);
1742
+ }
1743
+ if ("errors" in result) {
1744
+ next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_h = {}, _h[PROTOCOL_ERRORS_SYMBOL] = result.errors, _h)) });
1745
+ }
1746
+ (_b = observer.next) === null || _b === void 0 ? void 0 : _b.call(observer, next);
1747
+ }
1748
+ else {
1749
+ (_c = observer.next) === null || _c === void 0 ? void 0 : _c.call(observer, result);
1750
+ }
1751
+ }
1752
+ else if (Object.keys(result).length === 1 &&
1753
+ "hasNext" in result &&
1754
+ !result.hasNext) {
1755
+ (_d = observer.complete) === null || _d === void 0 ? void 0 : _d.call(observer);
1597
1756
  }
1598
1757
  }
1599
1758
  catch (err) {
@@ -1604,7 +1763,7 @@ function readMultipartBody(response, observer) {
1604
1763
  }
1605
1764
  return [3, 1];
1606
1765
  case 3:
1607
- (_c = observer.complete) === null || _c === void 0 ? void 0 : _c.call(observer);
1766
+ (_e = observer.complete) === null || _e === void 0 ? void 0 : _e.call(observer);
1608
1767
  return [2];
1609
1768
  }
1610
1769
  });
@@ -1691,7 +1850,7 @@ var serializeFetchParameter = function (p, label) {
1691
1850
  serialized = JSON.stringify(p);
1692
1851
  }
1693
1852
  catch (e) {
1694
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new tsInvariant.InvariantError(24);
1853
+ var parseError = newInvariantError(39, label, e.message);
1695
1854
  parseError.parseError = e;
1696
1855
  throw parseError;
1697
1856
  }
@@ -1774,7 +1933,7 @@ function removeDuplicateHeaders(headers, preserveHeaderCase) {
1774
1933
 
1775
1934
  var checkFetcher = function (fetcher) {
1776
1935
  if (!fetcher && typeof fetch === 'undefined') {
1777
- throw __DEV__ ? new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ") : new tsInvariant.InvariantError(23);
1936
+ throw newInvariantError(37);
1778
1937
  }
1779
1938
  };
1780
1939
 
@@ -1884,20 +2043,7 @@ var createHttpLink = function (linkOptions) {
1884
2043
  }
1885
2044
  var _b = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
1886
2045
  if (body.variables && !includeUnusedVariables) {
1887
- var unusedNames_1 = new Set(Object.keys(body.variables));
1888
- graphql.visit(operation.query, {
1889
- Variable: function (node, _key, parent) {
1890
- if (parent && parent.kind !== 'VariableDefinition') {
1891
- unusedNames_1.delete(node.name.value);
1892
- }
1893
- },
1894
- });
1895
- if (unusedNames_1.size) {
1896
- body.variables = tslib.__assign({}, body.variables);
1897
- unusedNames_1.forEach(function (name) {
1898
- delete body.variables[name];
1899
- });
1900
- }
2046
+ body.variables = filterOperationVariables(body.variables, operation);
1901
2047
  }
1902
2048
  var controller;
1903
2049
  if (!options.signal) {
@@ -1909,13 +2055,28 @@ var createHttpLink = function (linkOptions) {
1909
2055
  var definitionIsMutation = function (d) {
1910
2056
  return d.kind === 'OperationDefinition' && d.operation === 'mutation';
1911
2057
  };
2058
+ var definitionIsSubscription = function (d) {
2059
+ return d.kind === 'OperationDefinition' && d.operation === 'subscription';
2060
+ };
2061
+ var isSubscription = definitionIsSubscription(getMainDefinition(operation.query));
2062
+ var hasDefer = hasDirectives(['defer'], operation.query);
1912
2063
  if (useGETForQueries &&
1913
2064
  !operation.query.definitions.some(definitionIsMutation)) {
1914
2065
  options.method = 'GET';
1915
2066
  }
1916
- if (hasDirectives(['defer'], operation.query)) {
2067
+ if (hasDefer || isSubscription) {
1917
2068
  options.headers = options.headers || {};
1918
- options.headers.accept = "multipart/mixed; deferSpec=20220824, application/json";
2069
+ var acceptHeader = "multipart/mixed;";
2070
+ if (isSubscription && hasDefer) {
2071
+ __DEV__ && invariant.warn(38);
2072
+ }
2073
+ if (isSubscription) {
2074
+ acceptHeader += 'boundary=graphql;subscriptionSpec=1.0,application/json';
2075
+ }
2076
+ else if (hasDefer) {
2077
+ acceptHeader += 'deferSpec=20220824,application/json';
2078
+ }
2079
+ options.headers.accept = acceptHeader;
1919
2080
  }
1920
2081
  if (options.method === 'GET') {
1921
2082
  var _d = rewriteURIForGET(chosenURI, body), newURI = _d.newURI, parseError = _d.parseError;
@@ -1968,6 +2129,7 @@ var HttpLink = (function (_super) {
1968
2129
 
1969
2130
  var ApolloCache = (function () {
1970
2131
  function ApolloCache() {
2132
+ this.assumeImmutableResults = false;
1971
2133
  this.getFragmentDoc = optimism.wrap(getFragmentQueryDocument);
1972
2134
  }
1973
2135
  ApolloCache.prototype.batch = function (options) {
@@ -2243,7 +2405,7 @@ var EntityStore = (function () {
2243
2405
  : newer;
2244
2406
  if (!incoming)
2245
2407
  return;
2246
- __DEV__ ? tsInvariant.invariant(typeof dataId === "string", "store.merge expects a string ID") : tsInvariant.invariant(typeof dataId === "string", 1);
2408
+ invariant(typeof dataId === "string", 1);
2247
2409
  var merged = new DeepMerger(storeObjectReconciler).merge(existing, incoming);
2248
2410
  this.data[dataId] = merged;
2249
2411
  if (merged !== existing) {
@@ -2566,7 +2728,7 @@ var Layer = (function (_super) {
2566
2728
  }
2567
2729
  else if (ownStoreObject !== parentStoreObject) {
2568
2730
  Object.keys(ownStoreObject).forEach(function (storeFieldName) {
2569
- if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2731
+ if (!equal.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
2570
2732
  _this.group.dirty(dataId, storeFieldName);
2571
2733
  }
2572
2734
  });
@@ -2610,7 +2772,7 @@ var Stump = (function (_super) {
2610
2772
  function storeObjectReconciler(existingObject, incomingObject, property) {
2611
2773
  var existingValue = existingObject[property];
2612
2774
  var incomingValue = incomingObject[property];
2613
- return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2775
+ return equal.equal(existingValue, incomingValue) ? existingValue : incomingValue;
2614
2776
  }
2615
2777
  function supportsResultCaching(store) {
2616
2778
  return !!(store instanceof EntityStore && store.group.caching);
@@ -2898,7 +3060,7 @@ var StoreReader = (function () {
2898
3060
  else {
2899
3061
  var fragment = getFragmentFromSelection(selection, context.lookupFragment);
2900
3062
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
2901
- throw __DEV__ ? new tsInvariant.InvariantError("No fragment named ".concat(selection.name.value)) : new tsInvariant.InvariantError(5);
3063
+ throw newInvariantError(7, selection.name.value);
2902
3064
  }
2903
3065
  if (fragment && policies.fragmentMatches(fragment, typename)) {
2904
3066
  fragment.selectionSet.selections.forEach(workSet.add, workSet);
@@ -2979,7 +3141,12 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
2979
3141
  var workSet_1 = new Set([fieldValue]);
2980
3142
  workSet_1.forEach(function (value) {
2981
3143
  if (isNonNullObject(value)) {
2982
- __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : tsInvariant.invariant(!isReference(value), 6);
3144
+ invariant(
3145
+ !isReference(value),
3146
+ 8,
3147
+ getTypenameFromStoreObject(store, value),
3148
+ field.name.value
3149
+ );
2983
3150
  Object.values(value).forEach(workSet_1.add, workSet_1);
2984
3151
  }
2985
3152
  });
@@ -3066,7 +3233,7 @@ function keyFieldsFnFromSpecifier(specifier) {
3066
3233
  hasOwn.call(object, schemaKeyPath[0])) {
3067
3234
  extracted = extractKeyPath(object, schemaKeyPath, extractKey);
3068
3235
  }
3069
- __DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '".concat(schemaKeyPath.join('.'), "' while extracting keyFields from ").concat(JSON.stringify(object))) : tsInvariant.invariant(extracted !== void 0, 2);
3236
+ invariant(extracted !== void 0, 2, schemaKeyPath.join('.'), object);
3070
3237
  return extracted;
3071
3238
  });
3072
3239
  return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
@@ -3218,7 +3385,7 @@ var Policies = (function () {
3218
3385
  var policy = typename && this.getTypePolicy(typename);
3219
3386
  var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
3220
3387
  while (keyFn) {
3221
- var specifierOrId = keyFn(object, context);
3388
+ var specifierOrId = keyFn(tslib.__assign(tslib.__assign({}, object), storeObject), context);
3222
3389
  if (isArray(specifierOrId)) {
3223
3390
  keyFn = keyFieldsFnFromSpecifier(specifierOrId);
3224
3391
  }
@@ -3295,7 +3462,7 @@ var Policies = (function () {
3295
3462
  var rootId = "ROOT_" + which.toUpperCase();
3296
3463
  var old = this.rootTypenamesById[rootId];
3297
3464
  if (typename !== old) {
3298
- __DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root ".concat(which, " __typename more than once")) : tsInvariant.invariant(!old || old === which, 3);
3465
+ invariant(!old || old === which, 3, which);
3299
3466
  if (old)
3300
3467
  delete this.rootIdsByTypename[old];
3301
3468
  this.rootIdsByTypename[typename] = rootId;
@@ -3390,7 +3557,7 @@ var Policies = (function () {
3390
3557
  if (supertypeSet.has(supertype)) {
3391
3558
  if (!typenameSupertypeSet.has(supertype)) {
3392
3559
  if (checkingFuzzySubtypes) {
3393
- __DEV__ && tsInvariant.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
3560
+ __DEV__ && invariant.warn(4, typename, supertype);
3394
3561
  }
3395
3562
  typenameSupertypeSet.add(supertype);
3396
3563
  }
@@ -3544,7 +3711,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3544
3711
  }
3545
3712
  }
3546
3713
  if (__DEV__ && options.from === void 0) {
3547
- __DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments ".concat(stringifyForDisplay(Array.from(readFieldArgs))));
3714
+ __DEV__ && invariant.warn(5, stringifyForDisplay(Array.from(readFieldArgs)));
3548
3715
  }
3549
3716
  if (void 0 === options.variables) {
3550
3717
  options.variables = variables;
@@ -3554,7 +3721,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
3554
3721
  function makeMergeObjectsFunction(store) {
3555
3722
  return function mergeObjects(existing, incoming) {
3556
3723
  if (isArray(existing) || isArray(incoming)) {
3557
- throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
3724
+ throw newInvariantError(6);
3558
3725
  }
3559
3726
  if (isNonNullObject(existing) &&
3560
3727
  isNonNullObject(incoming)) {
@@ -3615,7 +3782,7 @@ var StoreWriter = (function () {
3615
3782
  context: context,
3616
3783
  });
3617
3784
  if (!isReference(ref)) {
3618
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new tsInvariant.InvariantError(7);
3785
+ throw newInvariantError(9, result);
3619
3786
  }
3620
3787
  context.incomingById.forEach(function (_a, dataId) {
3621
3788
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -3720,7 +3887,7 @@ var StoreWriter = (function () {
3720
3887
  !context.deferred &&
3721
3888
  !addTypenameToDocument.added(field) &&
3722
3889
  !policies.getReadFunction(typename, field.name.value)) {
3723
- __DEV__ && tsInvariant.invariant.error("Missing field '".concat(resultKeyNameFromField(field), "' while writing result ").concat(JSON.stringify(result, null, 2)).substring(0, 1000));
3890
+ __DEV__ && invariant.error(10, resultKeyNameFromField(field), result);
3724
3891
  }
3725
3892
  });
3726
3893
  try {
@@ -3824,7 +3991,7 @@ var StoreWriter = (function () {
3824
3991
  else {
3825
3992
  var fragment = getFragmentFromSelection(selection, context.lookupFragment);
3826
3993
  if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
3827
- throw __DEV__ ? new tsInvariant.InvariantError("No fragment named ".concat(selection.name.value)) : new tsInvariant.InvariantError(8);
3994
+ throw newInvariantError(11, selection.name.value);
3828
3995
  }
3829
3996
  if (fragment &&
3830
3997
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
@@ -3865,7 +4032,7 @@ var StoreWriter = (function () {
3865
4032
  changedFields_1.set(storeFieldName, aVal);
3866
4033
  }
3867
4034
  if (getStorageArgs) {
3868
- tsInvariant.invariant(getStorageArgs.pop() === storeFieldName);
4035
+ invariant(getStorageArgs.pop() === storeFieldName);
3869
4036
  }
3870
4037
  });
3871
4038
  if (changedFields_1) {
@@ -3937,7 +4104,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3937
4104
  return;
3938
4105
  if (isReference(existing))
3939
4106
  return;
3940
- if (equality.equal(existing, incoming))
4107
+ if (equal.equal(existing, incoming))
3941
4108
  return;
3942
4109
  if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
3943
4110
  return;
@@ -3960,10 +4127,9 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
3960
4127
  }
3961
4128
  });
3962
4129
  }
3963
- __DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the ".concat(fieldName, " field of a ").concat(parentType, " object.\n\nTo address this problem (which is not a bug in Apollo Client), ").concat(childTypenames.length
3964
- ? "either ensure all objects of type " +
3965
- childTypenames.join(" and ") + " have an ID or a custom merge function, or "
3966
- : "", "define a custom merge function for the ").concat(typeDotName, " field, so InMemoryCache can safely merge these objects:\n\n existing: ").concat(JSON.stringify(existing).slice(0, 1000), "\n incoming: ").concat(JSON.stringify(incoming).slice(0, 1000), "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n"));
4130
+ __DEV__ && invariant.warn(12, fieldName, parentType, childTypenames.length
4131
+ ? "either ensure all objects of type " + childTypenames.join(" and ") + " have an ID or a custom merge function, or "
4132
+ : "", typeDotName, existing, incoming);
3967
4133
  }
3968
4134
 
3969
4135
  var InMemoryCache = (function (_super) {
@@ -3972,7 +4138,8 @@ var InMemoryCache = (function (_super) {
3972
4138
  if (config === void 0) { config = {}; }
3973
4139
  var _this = _super.call(this) || this;
3974
4140
  _this.watches = new Set();
3975
- _this.typenameDocumentCache = new Map();
4141
+ _this.addTypenameTransform = new DocumentTransform(addTypenameToDocument);
4142
+ _this.assumeImmutableResults = true;
3976
4143
  _this.makeVar = makeVar;
3977
4144
  _this.txCount = 0;
3978
4145
  _this.config = normalizeConfig(config);
@@ -4120,7 +4287,7 @@ var InMemoryCache = (function (_super) {
4120
4287
  return this.policies.identify(object)[0];
4121
4288
  }
4122
4289
  catch (e) {
4123
- __DEV__ && tsInvariant.invariant.warn(e);
4290
+ __DEV__ && invariant.warn(e);
4124
4291
  }
4125
4292
  };
4126
4293
  InMemoryCache.prototype.evict = function (options) {
@@ -4223,28 +4390,25 @@ var InMemoryCache = (function (_super) {
4223
4390
  });
4224
4391
  };
4225
4392
  InMemoryCache.prototype.transformDocument = function (document) {
4226
- if (this.addTypename) {
4227
- var result = this.typenameDocumentCache.get(document);
4228
- if (!result) {
4229
- result = addTypenameToDocument(document);
4230
- this.typenameDocumentCache.set(document, result);
4231
- this.typenameDocumentCache.set(result, result);
4232
- }
4233
- return result;
4393
+ return this.addTypenameToDocument(this.addFragmentsToDocument(document));
4394
+ };
4395
+ InMemoryCache.prototype.broadcastWatches = function (options) {
4396
+ var _this = this;
4397
+ if (!this.txCount) {
4398
+ this.watches.forEach(function (c) { return _this.maybeBroadcastWatch(c, options); });
4234
4399
  }
4235
- return document;
4236
4400
  };
4237
- InMemoryCache.prototype.transformForLink = function (document) {
4401
+ InMemoryCache.prototype.addFragmentsToDocument = function (document) {
4238
4402
  var fragments = this.config.fragments;
4239
4403
  return fragments
4240
4404
  ? fragments.transform(document)
4241
4405
  : document;
4242
4406
  };
4243
- InMemoryCache.prototype.broadcastWatches = function (options) {
4244
- var _this = this;
4245
- if (!this.txCount) {
4246
- this.watches.forEach(function (c) { return _this.maybeBroadcastWatch(c, options); });
4407
+ InMemoryCache.prototype.addTypenameToDocument = function (document) {
4408
+ if (this.addTypename) {
4409
+ return this.addTypenameTransform.transformDocument(document);
4247
4410
  }
4411
+ return document;
4248
4412
  };
4249
4413
  InMemoryCache.prototype.broadcastWatch = function (c, options) {
4250
4414
  var lastDiff = c.lastDiff;
@@ -4259,51 +4423,13 @@ var InMemoryCache = (function (_super) {
4259
4423
  return;
4260
4424
  }
4261
4425
  }
4262
- if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
4426
+ if (!lastDiff || !equal.equal(lastDiff.result, diff.result)) {
4263
4427
  c.callback(c.lastDiff = diff, lastDiff);
4264
4428
  }
4265
4429
  };
4266
4430
  return InMemoryCache;
4267
4431
  }(ApolloCache));
4268
4432
 
4269
- function isApolloError(err) {
4270
- return err.hasOwnProperty('graphQLErrors');
4271
- }
4272
- var generateErrorMessage = function (err) {
4273
- var message = '';
4274
- if (isNonEmptyArray(err.graphQLErrors) || isNonEmptyArray(err.clientErrors)) {
4275
- var errors = (err.graphQLErrors || [])
4276
- .concat(err.clientErrors || []);
4277
- errors.forEach(function (error) {
4278
- var errorMessage = error
4279
- ? error.message
4280
- : 'Error message not found.';
4281
- message += "".concat(errorMessage, "\n");
4282
- });
4283
- }
4284
- if (err.networkError) {
4285
- message += "".concat(err.networkError.message, "\n");
4286
- }
4287
- message = message.replace(/\n$/, '');
4288
- return message;
4289
- };
4290
- var ApolloError = (function (_super) {
4291
- tslib.__extends(ApolloError, _super);
4292
- function ApolloError(_a) {
4293
- var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
4294
- var _this = _super.call(this, errorMessage) || this;
4295
- _this.name = 'ApolloError';
4296
- _this.graphQLErrors = graphQLErrors || [];
4297
- _this.clientErrors = clientErrors || [];
4298
- _this.networkError = networkError || null;
4299
- _this.message = errorMessage || generateErrorMessage(_this);
4300
- _this.extraInfo = extraInfo;
4301
- _this.__proto__ = ApolloError.prototype;
4302
- return _this;
4303
- }
4304
- return ApolloError;
4305
- }(Error));
4306
-
4307
4433
  exports.NetworkStatus = void 0;
4308
4434
  (function (NetworkStatus) {
4309
4435
  NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
@@ -4317,6 +4443,73 @@ exports.NetworkStatus = void 0;
4317
4443
  function isNetworkRequestInFlight(networkStatus) {
4318
4444
  return networkStatus ? networkStatus < 7 : false;
4319
4445
  }
4446
+ function isNetworkRequestSettled(networkStatus) {
4447
+ return networkStatus === 7 || networkStatus === 8;
4448
+ }
4449
+
4450
+ function equalByQuery(query, _a, _b, variables) {
4451
+ var aData = _a.data, aRest = tslib.__rest(_a, ["data"]);
4452
+ var bData = _b.data, bRest = tslib.__rest(_b, ["data"]);
4453
+ return equal__default(aRest, bRest) && equalBySelectionSet(getMainDefinition(query).selectionSet, aData, bData, {
4454
+ fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
4455
+ variables: variables,
4456
+ });
4457
+ }
4458
+ function equalBySelectionSet(selectionSet, aResult, bResult, context) {
4459
+ if (aResult === bResult) {
4460
+ return true;
4461
+ }
4462
+ var seenSelections = new Set();
4463
+ return selectionSet.selections.every(function (selection) {
4464
+ if (seenSelections.has(selection))
4465
+ return true;
4466
+ seenSelections.add(selection);
4467
+ if (!shouldInclude(selection, context.variables))
4468
+ return true;
4469
+ if (selectionHasNonreactiveDirective(selection))
4470
+ return true;
4471
+ if (isField(selection)) {
4472
+ var resultKey = resultKeyNameFromField(selection);
4473
+ var aResultChild = aResult && aResult[resultKey];
4474
+ var bResultChild = bResult && bResult[resultKey];
4475
+ var childSelectionSet = selection.selectionSet;
4476
+ if (!childSelectionSet) {
4477
+ return equal__default(aResultChild, bResultChild);
4478
+ }
4479
+ var aChildIsArray = Array.isArray(aResultChild);
4480
+ var bChildIsArray = Array.isArray(bResultChild);
4481
+ if (aChildIsArray !== bChildIsArray)
4482
+ return false;
4483
+ if (aChildIsArray && bChildIsArray) {
4484
+ var length_1 = aResultChild.length;
4485
+ if (bResultChild.length !== length_1) {
4486
+ return false;
4487
+ }
4488
+ for (var i = 0; i < length_1; ++i) {
4489
+ if (!equalBySelectionSet(childSelectionSet, aResultChild[i], bResultChild[i], context)) {
4490
+ return false;
4491
+ }
4492
+ }
4493
+ return true;
4494
+ }
4495
+ return equalBySelectionSet(childSelectionSet, aResultChild, bResultChild, context);
4496
+ }
4497
+ else {
4498
+ var fragment = getFragmentFromSelection(selection, context.fragmentMap);
4499
+ if (fragment) {
4500
+ if (selectionHasNonreactiveDirective(fragment))
4501
+ return true;
4502
+ return equalBySelectionSet(fragment.selectionSet, aResult, bResult, context);
4503
+ }
4504
+ }
4505
+ });
4506
+ }
4507
+ function selectionHasNonreactiveDirective(selection) {
4508
+ return !!selection.directives && selection.directives.some(directiveIsNonreactive);
4509
+ }
4510
+ function directiveIsNonreactive(dir) {
4511
+ return dir.name.value === "nonreactive";
4512
+ }
4320
4513
 
4321
4514
  var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
4322
4515
  var ObservableQuery = (function (_super) {
@@ -4324,14 +4517,13 @@ var ObservableQuery = (function (_super) {
4324
4517
  function ObservableQuery(_a) {
4325
4518
  var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
4326
4519
  var _this = _super.call(this, function (observer) {
4327
- var _a = options.fetchOnFirstSubscribe, fetchOnFirstSubscribe = _a === void 0 ? true : _a;
4328
4520
  try {
4329
4521
  var subObserver = observer._subscription._observer;
4330
4522
  if (subObserver && !subObserver.error) {
4331
4523
  subObserver.error = defaultSubscriptionObserverErrorCallback;
4332
4524
  }
4333
4525
  }
4334
- catch (_b) { }
4526
+ catch (_a) { }
4335
4527
  var first = !_this.observers.size;
4336
4528
  _this.observers.add(observer);
4337
4529
  var last = _this.last;
@@ -4341,7 +4533,7 @@ var ObservableQuery = (function (_super) {
4341
4533
  else if (last && last.result) {
4342
4534
  observer.next && observer.next(last.result);
4343
4535
  }
4344
- if (first && fetchOnFirstSubscribe) {
4536
+ if (first) {
4345
4537
  _this.reobserve().catch(function () { });
4346
4538
  }
4347
4539
  return function () {
@@ -4365,7 +4557,7 @@ var ObservableQuery = (function (_super) {
4365
4557
  }
4366
4558
  Object.defineProperty(ObservableQuery.prototype, "query", {
4367
4559
  get: function () {
4368
- return this.queryManager.transform(this.options.query).document;
4560
+ return this.lastQuery || this.options.query;
4369
4561
  },
4370
4562
  enumerable: false,
4371
4563
  configurable: true
@@ -4407,13 +4599,13 @@ var ObservableQuery = (function (_super) {
4407
4599
  if (fetchPolicy === 'network-only' ||
4408
4600
  fetchPolicy === 'no-cache' ||
4409
4601
  fetchPolicy === 'standby' ||
4410
- this.queryManager.transform(this.options.query).hasForcedResolvers) ;
4602
+ this.queryManager.getDocumentInfo(this.query).hasForcedResolvers) ;
4411
4603
  else {
4412
4604
  var diff = this.queryInfo.getDiff();
4413
4605
  if (diff.complete || this.options.returnPartialData) {
4414
4606
  result.data = diff.result;
4415
4607
  }
4416
- if (equality.equal(result.data, {})) {
4608
+ if (equal.equal(result.data, {})) {
4417
4609
  result.data = void 0;
4418
4610
  }
4419
4611
  if (diff.complete) {
@@ -4444,15 +4636,20 @@ var ObservableQuery = (function (_super) {
4444
4636
  return result;
4445
4637
  };
4446
4638
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
4447
- return (!this.last ||
4448
- !equality.equal(this.last.result, newResult) ||
4449
- (variables && !equality.equal(this.last.variables, variables)));
4639
+ if (!this.last) {
4640
+ return true;
4641
+ }
4642
+ var resultIsDifferent = this.queryManager.getDocumentInfo(this.query).hasNonreactiveDirective
4643
+ ? !equalByQuery(this.query, this.last.result, newResult, this.variables)
4644
+ : !equal.equal(this.last.result, newResult);
4645
+ return (resultIsDifferent ||
4646
+ (variables && !equal.equal(this.last.variables, variables)));
4450
4647
  };
4451
4648
  ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
4452
4649
  var last = this.last;
4453
4650
  if (last &&
4454
4651
  last[key] &&
4455
- (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
4652
+ (!variablesMustMatch || equal.equal(last.variables, this.variables))) {
4456
4653
  return last[key];
4457
4654
  }
4458
4655
  };
@@ -4488,10 +4685,14 @@ var ObservableQuery = (function (_super) {
4488
4685
  var queryDef = getQueryDefinition(this.query);
4489
4686
  var vars = queryDef.variableDefinitions;
4490
4687
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
4491
- __DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
4688
+ __DEV__ && invariant.warn(
4689
+ 20,
4690
+ variables,
4691
+ ((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || queryDef
4692
+ );
4492
4693
  }
4493
4694
  }
4494
- if (variables && !equality.equal(this.options.variables, variables)) {
4695
+ if (variables && !equal.equal(this.options.variables, variables)) {
4495
4696
  reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
4496
4697
  }
4497
4698
  this.queryInfo.resetLastWrite();
@@ -4499,8 +4700,12 @@ var ObservableQuery = (function (_super) {
4499
4700
  };
4500
4701
  ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
4501
4702
  var _this = this;
4502
- 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" });
4703
+ var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.options.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
4704
+ combinedOptions.query = this.transformDocument(combinedOptions.query);
4503
4705
  var qid = this.queryManager.generateQueryId();
4706
+ this.lastQuery = fetchMoreOptions.query
4707
+ ? this.transformDocument(this.options.query)
4708
+ : combinedOptions.query;
4504
4709
  var queryInfo = this.queryInfo;
4505
4710
  var originalNetworkStatus = queryInfo.networkStatus;
4506
4711
  queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
@@ -4572,7 +4777,7 @@ var ObservableQuery = (function (_super) {
4572
4777
  options.onError(err);
4573
4778
  return;
4574
4779
  }
4575
- __DEV__ && tsInvariant.invariant.error('Unhandled GraphQL subscription error', err);
4780
+ __DEV__ && invariant.error(21, err);
4576
4781
  },
4577
4782
  });
4578
4783
  this.subscriptions.add(subscription);
@@ -4586,7 +4791,7 @@ var ObservableQuery = (function (_super) {
4586
4791
  return this.reobserve(newOptions);
4587
4792
  };
4588
4793
  ObservableQuery.prototype.setVariables = function (variables) {
4589
- if (equality.equal(this.variables, variables)) {
4794
+ if (equal.equal(this.variables, variables)) {
4590
4795
  return this.observers.size
4591
4796
  ? this.result()
4592
4797
  : Promise.resolve();
@@ -4651,7 +4856,7 @@ var ObservableQuery = (function (_super) {
4651
4856
  };
4652
4857
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
4653
4858
  this.queryManager.setObservableQuery(this);
4654
- return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
4859
+ return this.queryManager['fetchConcastWithInfo'](this.queryId, options, newNetworkStatus);
4655
4860
  };
4656
4861
  ObservableQuery.prototype.updatePolling = function () {
4657
4862
  var _this = this;
@@ -4670,7 +4875,7 @@ var ObservableQuery = (function (_super) {
4670
4875
  pollingInfo.interval === pollInterval) {
4671
4876
  return;
4672
4877
  }
4673
- __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 13);
4878
+ invariant(pollInterval, 22);
4674
4879
  var info = pollingInfo || (this.pollingInfo = {});
4675
4880
  info.interval = pollInterval;
4676
4881
  var maybeFetch = function () {
@@ -4696,13 +4901,13 @@ var ObservableQuery = (function (_super) {
4696
4901
  };
4697
4902
  ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
4698
4903
  if (variables === void 0) { variables = this.variables; }
4699
- this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
4700
- ? newResult
4701
- : cloneDeep(newResult), variables: variables });
4702
- if (!isNonEmptyArray(newResult.errors)) {
4703
- delete this.last.error;
4904
+ var error = this.getLastError();
4905
+ if (error && this.last && !equal.equal(variables, this.last.variables)) {
4906
+ error = void 0;
4704
4907
  }
4705
- return this.last;
4908
+ return this.last = tslib.__assign({ result: this.queryManager.assumeImmutableResults
4909
+ ? newResult
4910
+ : cloneDeep(newResult), variables: variables }, (error ? { error: error } : null));
4706
4911
  };
4707
4912
  ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
4708
4913
  var _this = this;
@@ -4716,11 +4921,13 @@ var ObservableQuery = (function (_super) {
4716
4921
  var options = useDisposableConcast
4717
4922
  ? mergedOptions
4718
4923
  : assign(this.options, mergedOptions);
4924
+ var query = this.transformDocument(options.query);
4925
+ this.lastQuery = query;
4719
4926
  if (!useDisposableConcast) {
4720
4927
  this.updatePolling();
4721
4928
  if (newOptions &&
4722
4929
  newOptions.variables &&
4723
- !equality.equal(newOptions.variables, oldVariables) &&
4930
+ !equal.equal(newOptions.variables, oldVariables) &&
4724
4931
  options.fetchPolicy !== "standby" &&
4725
4932
  options.fetchPolicy === oldFetchPolicy) {
4726
4933
  this.applyNextFetchPolicy("variables-changed", options);
@@ -4729,8 +4936,9 @@ var ObservableQuery = (function (_super) {
4729
4936
  }
4730
4937
  }
4731
4938
  }
4939
+ var fetchOptions = query === options.query ? options : tslib.__assign(tslib.__assign({}, options), { query: query });
4732
4940
  var variables = options.variables && tslib.__assign({}, options.variables);
4733
- var concast = this.fetch(options, newNetworkStatus);
4941
+ var _a = this.fetch(fetchOptions, newNetworkStatus), concast = _a.concast, fromLink = _a.fromLink;
4734
4942
  var observer = {
4735
4943
  next: function (result) {
4736
4944
  _this.reportResult(result, variables);
@@ -4739,7 +4947,7 @@ var ObservableQuery = (function (_super) {
4739
4947
  _this.reportError(error, variables);
4740
4948
  },
4741
4949
  };
4742
- if (!useDisposableConcast) {
4950
+ if (!useDisposableConcast && (fromLink || !this.concast)) {
4743
4951
  if (this.concast && this.observer) {
4744
4952
  this.concast.removeObserver(this.observer);
4745
4953
  }
@@ -4757,11 +4965,12 @@ var ObservableQuery = (function (_super) {
4757
4965
  };
4758
4966
  ObservableQuery.prototype.reportResult = function (result, variables) {
4759
4967
  var lastError = this.getLastError();
4760
- if (lastError || this.isDifferentFromLastResult(result, variables)) {
4761
- if (lastError || !result.partial || this.options.returnPartialData) {
4762
- this.updateLastResult(result, variables);
4763
- }
4764
- iterateObserversSafely(this.observers, 'next', result);
4968
+ var isDifferent = this.isDifferentFromLastResult(result, variables);
4969
+ if (lastError || !result.partial || this.options.returnPartialData) {
4970
+ this.updateLastResult(result, variables);
4971
+ }
4972
+ if (lastError || isDifferent) {
4973
+ iterateObserversSafely(this.observers, "next", result);
4765
4974
  }
4766
4975
  };
4767
4976
  ObservableQuery.prototype.reportError = function (error, variables) {
@@ -4787,6 +4996,9 @@ var ObservableQuery = (function (_super) {
4787
4996
  this.observers.clear();
4788
4997
  this.isTornDown = true;
4789
4998
  };
4999
+ ObservableQuery.prototype.transformDocument = function (document) {
5000
+ return this.queryManager.transform(document);
5001
+ };
4790
5002
  return ObservableQuery;
4791
5003
  }(zenObservableTs.Observable));
4792
5004
  fixObservableSubclass(ObservableQuery);
@@ -4808,14 +5020,78 @@ function reobserveCacheFirst(obsQuery) {
4808
5020
  return obsQuery.reobserve();
4809
5021
  }
4810
5022
  function defaultSubscriptionObserverErrorCallback(error) {
4811
- __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
5023
+ __DEV__ && invariant.error(23, error.message, error.stack);
4812
5024
  }
4813
5025
  function logMissingFieldErrors(missing) {
4814
5026
  if (__DEV__ && missing) {
4815
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
5027
+ __DEV__ && invariant.debug(24, missing);
4816
5028
  }
4817
5029
  }
4818
5030
 
5031
+ function identity(document) {
5032
+ return document;
5033
+ }
5034
+ var DocumentTransform = (function () {
5035
+ function DocumentTransform(transform, options) {
5036
+ if (options === void 0) { options = Object.create(null); }
5037
+ this.resultCache = canUseWeakSet
5038
+ ? new WeakSet()
5039
+ : new Set();
5040
+ this.transform = transform;
5041
+ if (options.getCacheKey) {
5042
+ this.getCacheKey = options.getCacheKey;
5043
+ }
5044
+ if (options.cache !== false) {
5045
+ this.stableCacheKeys = new trie.Trie(canUseWeakMap, function (key) { return ({ key: key }); });
5046
+ }
5047
+ }
5048
+ DocumentTransform.prototype.getCacheKey = function (document) {
5049
+ return [document];
5050
+ };
5051
+ DocumentTransform.identity = function () {
5052
+ return new DocumentTransform(identity, { cache: false });
5053
+ };
5054
+ DocumentTransform.split = function (predicate, left, right) {
5055
+ if (right === void 0) { right = DocumentTransform.identity(); }
5056
+ return new DocumentTransform(function (document) {
5057
+ var documentTransform = predicate(document) ? left : right;
5058
+ return documentTransform.transformDocument(document);
5059
+ }, { cache: false });
5060
+ };
5061
+ DocumentTransform.prototype.transformDocument = function (document) {
5062
+ if (this.resultCache.has(document)) {
5063
+ return document;
5064
+ }
5065
+ var cacheEntry = this.getStableCacheEntry(document);
5066
+ if (cacheEntry && cacheEntry.value) {
5067
+ return cacheEntry.value;
5068
+ }
5069
+ checkDocument(document);
5070
+ var transformedDocument = this.transform(document);
5071
+ this.resultCache.add(transformedDocument);
5072
+ if (cacheEntry) {
5073
+ cacheEntry.value = transformedDocument;
5074
+ }
5075
+ return transformedDocument;
5076
+ };
5077
+ DocumentTransform.prototype.concat = function (otherTransform) {
5078
+ var _this = this;
5079
+ return new DocumentTransform(function (document) {
5080
+ return otherTransform.transformDocument(_this.transformDocument(document));
5081
+ }, { cache: false });
5082
+ };
5083
+ DocumentTransform.prototype.getStableCacheEntry = function (document) {
5084
+ if (!this.stableCacheKeys)
5085
+ return;
5086
+ var cacheKeys = this.getCacheKey(document);
5087
+ if (cacheKeys) {
5088
+ invariant(Array.isArray(cacheKeys), 17);
5089
+ return this.stableCacheKeys.lookupArray(cacheKeys);
5090
+ }
5091
+ };
5092
+ return DocumentTransform;
5093
+ }());
5094
+
4819
5095
  var LocalState = (function () {
4820
5096
  function LocalState(_a) {
4821
5097
  var cache = _a.cache, client = _a.client, resolvers = _a.resolvers, fragmentMatcher = _a.fragmentMatcher;
@@ -4875,12 +5151,8 @@ var LocalState = (function () {
4875
5151
  }
4876
5152
  return null;
4877
5153
  };
4878
- LocalState.prototype.serverQuery = function (document, options) {
4879
- if (options === void 0) { options = Object.create(null); }
4880
- var _a = options.removeClientFields, removeClientFields = _a === void 0 ? true : _a;
4881
- return removeClientFields
4882
- ? removeClientSetsFromDocument(document)
4883
- : document;
5154
+ LocalState.prototype.serverQuery = function (document) {
5155
+ return removeClientSetsFromDocument(document);
4884
5156
  };
4885
5157
  LocalState.prototype.prepareContext = function (context) {
4886
5158
  var cache = this.cache;
@@ -4995,7 +5267,7 @@ var LocalState = (function () {
4995
5267
  }
4996
5268
  else {
4997
5269
  fragment = fragmentMap[selection.name.value];
4998
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value)) : tsInvariant.invariant(fragment, 11);
5270
+ invariant(fragment, 18, selection.name.value);
4999
5271
  }
5000
5272
  if (fragment && fragment.typeCondition) {
5001
5273
  typeCondition = fragment.typeCondition.name.value;
@@ -5108,7 +5380,7 @@ var LocalState = (function () {
5108
5380
  },
5109
5381
  FragmentSpread: function (spread, _, __, ___, ancestors) {
5110
5382
  var fragment = fragmentMap[spread.name.value];
5111
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(spread.name.value)) : tsInvariant.invariant(fragment, 12);
5383
+ invariant(fragment, 19, spread.name.value);
5112
5384
  var fragmentSelections = collectByDefinition(fragment);
5113
5385
  if (fragmentSelections.size > 0) {
5114
5386
  ancestors.forEach(function (node) {
@@ -5170,10 +5442,10 @@ var QueryInfo = (function () {
5170
5442
  var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
5171
5443
  if (this.variables &&
5172
5444
  this.networkStatus !== exports.NetworkStatus.loading &&
5173
- !equality.equal(this.variables, query.variables)) {
5445
+ !equal.equal(this.variables, query.variables)) {
5174
5446
  networkStatus = exports.NetworkStatus.setVariables;
5175
5447
  }
5176
- if (!equality.equal(query.variables, this.variables)) {
5448
+ if (!equal.equal(query.variables, this.variables)) {
5177
5449
  this.lastDiff = void 0;
5178
5450
  }
5179
5451
  Object.assign(this, {
@@ -5198,7 +5470,7 @@ var QueryInfo = (function () {
5198
5470
  QueryInfo.prototype.getDiff = function (variables) {
5199
5471
  if (variables === void 0) { variables = this.variables; }
5200
5472
  var options = this.getDiffOptions(variables);
5201
- if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
5473
+ if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
5202
5474
  return this.lastDiff.diff;
5203
5475
  }
5204
5476
  this.updateWatch(this.variables = variables);
@@ -5232,7 +5504,7 @@ var QueryInfo = (function () {
5232
5504
  var oldDiff = this.lastDiff && this.lastDiff.diff;
5233
5505
  this.updateLastDiff(diff);
5234
5506
  if (!this.dirty &&
5235
- !equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
5507
+ !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
5236
5508
  this.dirty = true;
5237
5509
  if (!this.notifyTimeout) {
5238
5510
  this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
@@ -5307,7 +5579,7 @@ var QueryInfo = (function () {
5307
5579
  }
5308
5580
  var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
5309
5581
  if (!this.lastWatch ||
5310
- !equality.equal(watchOptions, this.lastWatch)) {
5582
+ !equal.equal(watchOptions, this.lastWatch)) {
5311
5583
  this.cancel();
5312
5584
  this.cancel = this.cache.watch(this.lastWatch = watchOptions);
5313
5585
  }
@@ -5319,8 +5591,8 @@ var QueryInfo = (function () {
5319
5591
  var lastWrite = this.lastWrite;
5320
5592
  return !(lastWrite &&
5321
5593
  lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
5322
- equality.equal(variables, lastWrite.variables) &&
5323
- equality.equal(result.data, lastWrite.result.data));
5594
+ equal.equal(variables, lastWrite.variables) &&
5595
+ equal.equal(result.data, lastWrite.result.data));
5324
5596
  };
5325
5597
  QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
5326
5598
  var _this = this;
@@ -5412,7 +5684,8 @@ function shouldWriteResult(result, errorPolicy) {
5412
5684
  var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
5413
5685
  var QueryManager = (function () {
5414
5686
  function QueryManager(_a) {
5415
- 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;
5687
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, documentTransform = _a.documentTransform, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e;
5688
+ var _this = this;
5416
5689
  this.clientAwareness = {};
5417
5690
  this.queries = new Map();
5418
5691
  this.fetchCancelFns = new Map();
@@ -5421,6 +5694,7 @@ var QueryManager = (function () {
5421
5694
  this.requestIdCounter = 1;
5422
5695
  this.mutationIdCounter = 1;
5423
5696
  this.inFlightLinkObservables = new Map();
5697
+ var defaultDocumentTransform = new DocumentTransform(function (document) { return _this.cache.transformDocument(document); }, { cache: false });
5424
5698
  this.cache = cache;
5425
5699
  this.link = link;
5426
5700
  this.defaultOptions = defaultOptions || Object.create(null);
@@ -5428,7 +5702,12 @@ var QueryManager = (function () {
5428
5702
  this.clientAwareness = clientAwareness;
5429
5703
  this.localState = localState || new LocalState({ cache: cache });
5430
5704
  this.ssrMode = ssrMode;
5431
- this.assumeImmutableResults = !!assumeImmutableResults;
5705
+ this.assumeImmutableResults = assumeImmutableResults;
5706
+ this.documentTransform = documentTransform
5707
+ ? defaultDocumentTransform
5708
+ .concat(documentTransform)
5709
+ .concat(defaultDocumentTransform)
5710
+ : defaultDocumentTransform;
5432
5711
  if ((this.onBroadcast = onBroadcast)) {
5433
5712
  this.mutationStore = Object.create(null);
5434
5713
  }
@@ -5438,7 +5717,7 @@ var QueryManager = (function () {
5438
5717
  this.queries.forEach(function (_info, queryId) {
5439
5718
  _this.stopQueryNoBroadcast(queryId);
5440
5719
  });
5441
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(14));
5720
+ this.cancelPendingFetches(newInvariantError(25));
5442
5721
  };
5443
5722
  QueryManager.prototype.cancelPendingFetches = function (error) {
5444
5723
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -5448,23 +5727,22 @@ var QueryManager = (function () {
5448
5727
  var _b, _c;
5449
5728
  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;
5450
5729
  return tslib.__awaiter(this, void 0, void 0, function () {
5451
- var mutationId, _h, document, hasClientExports, mutationStoreValue, self;
5452
- return tslib.__generator(this, function (_j) {
5453
- switch (_j.label) {
5730
+ var mutationId, hasClientExports, mutationStoreValue, self;
5731
+ return tslib.__generator(this, function (_h) {
5732
+ switch (_h.label) {
5454
5733
  case 0:
5455
- __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 15);
5456
- __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
5457
- fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : tsInvariant.invariant(fetchPolicy === 'network-only' ||
5458
- fetchPolicy === 'no-cache', 16);
5734
+ invariant(mutation, 26);
5735
+ invariant(fetchPolicy === 'network-only' ||
5736
+ fetchPolicy === 'no-cache', 27);
5459
5737
  mutationId = this.generateMutationId();
5460
- _h = this.transform(mutation), document = _h.document, hasClientExports = _h.hasClientExports;
5461
- mutation = this.cache.transformForLink(document);
5738
+ mutation = this.cache.transformForLink(this.transform(mutation));
5739
+ hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
5462
5740
  variables = this.getVariables(mutation, variables);
5463
5741
  if (!hasClientExports) return [3, 2];
5464
5742
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
5465
5743
  case 1:
5466
- variables = (_j.sent());
5467
- _j.label = 2;
5744
+ variables = (_h.sent());
5745
+ _h.label = 2;
5468
5746
  case 2:
5469
5747
  mutationStoreValue = this.mutationStore &&
5470
5748
  (this.mutationStore[mutationId] = {
@@ -5567,7 +5845,7 @@ var QueryManager = (function () {
5567
5845
  if (isExecutionPatchIncrementalResult(result) && isNonEmptyArray(result.incremental)) {
5568
5846
  var diff = cache.diff({
5569
5847
  id: "ROOT_MUTATION",
5570
- query: this.transform(mutation.document).asQuery,
5848
+ query: this.getDocumentInfo(mutation.document).asQuery,
5571
5849
  variables: mutation.variables,
5572
5850
  optimistic: false,
5573
5851
  returnPartialData: true,
@@ -5638,7 +5916,7 @@ var QueryManager = (function () {
5638
5916
  if (!skipCache) {
5639
5917
  var diff = cache.diff({
5640
5918
  id: "ROOT_MUTATION",
5641
- query: _this.transform(mutation.document).asQuery,
5919
+ query: _this.getDocumentInfo(mutation.document).asQuery,
5642
5920
  variables: mutation.variables,
5643
5921
  optimistic: false,
5644
5922
  returnPartialData: true,
@@ -5691,12 +5969,12 @@ var QueryManager = (function () {
5691
5969
  _this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
5692
5970
  }
5693
5971
  catch (error) {
5694
- __DEV__ && tsInvariant.invariant.error(error);
5972
+ __DEV__ && invariant.error(error);
5695
5973
  }
5696
5974
  }, mutation.mutationId);
5697
5975
  };
5698
5976
  QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
5699
- return this.fetchQueryObservable(queryId, options, networkStatus).promise;
5977
+ return this.fetchConcastWithInfo(queryId, options, networkStatus).concast.promise;
5700
5978
  };
5701
5979
  QueryManager.prototype.getQueryStore = function () {
5702
5980
  var store = Object.create(null);
@@ -5718,22 +5996,23 @@ var QueryManager = (function () {
5718
5996
  }
5719
5997
  };
5720
5998
  QueryManager.prototype.transform = function (document) {
5999
+ return this.documentTransform.transformDocument(document);
6000
+ };
6001
+ QueryManager.prototype.getDocumentInfo = function (document) {
5721
6002
  var transformCache = this.transformCache;
5722
- var _a = (this.defaultOptions.transformQuery || Object.create(null)).removeClientFields, removeClientFields = _a === void 0 ? true : _a;
5723
6003
  if (!transformCache.has(document)) {
5724
- var transformed = this.cache.transformDocument(document);
5725
- var noConnection = removeConnectionDirectiveFromDocument(transformed);
5726
- var clientQuery = this.localState.clientQuery(transformed);
5727
- var serverQuery = noConnection &&
5728
- this.localState.serverQuery(noConnection, { removeClientFields: removeClientFields });
5729
- var cacheEntry_1 = {
5730
- document: transformed,
5731
- hasClientExports: hasClientExports(transformed),
5732
- hasForcedResolvers: this.localState.shouldForceResolvers(transformed),
5733
- clientQuery: clientQuery,
5734
- serverQuery: serverQuery,
5735
- defaultVars: getDefaultValues(getOperationDefinition(transformed)),
5736
- asQuery: tslib.__assign(tslib.__assign({}, transformed), { definitions: transformed.definitions.map(function (def) {
6004
+ var cacheEntry = {
6005
+ hasClientExports: hasClientExports(document),
6006
+ hasForcedResolvers: this.localState.shouldForceResolvers(document),
6007
+ hasNonreactiveDirective: hasDirectives(['nonreactive'], document),
6008
+ clientQuery: this.localState.clientQuery(document),
6009
+ serverQuery: removeDirectivesFromDocument([
6010
+ { name: 'client', remove: true },
6011
+ { name: 'connection' },
6012
+ { name: 'nonreactive' },
6013
+ ], document),
6014
+ defaultVars: getDefaultValues(getOperationDefinition(document)),
6015
+ asQuery: tslib.__assign(tslib.__assign({}, document), { definitions: document.definitions.map(function (def) {
5737
6016
  if (def.kind === "OperationDefinition" &&
5738
6017
  def.operation !== "query") {
5739
6018
  return tslib.__assign(tslib.__assign({}, def), { operation: "query" });
@@ -5741,23 +6020,16 @@ var QueryManager = (function () {
5741
6020
  return def;
5742
6021
  }) })
5743
6022
  };
5744
- var add = function (doc) {
5745
- if (doc && !transformCache.has(doc)) {
5746
- transformCache.set(doc, cacheEntry_1);
5747
- }
5748
- };
5749
- add(document);
5750
- add(transformed);
5751
- add(clientQuery);
5752
- add(serverQuery);
6023
+ transformCache.set(document, cacheEntry);
5753
6024
  }
5754
6025
  return transformCache.get(document);
5755
6026
  };
5756
6027
  QueryManager.prototype.getVariables = function (document, variables) {
5757
- return tslib.__assign(tslib.__assign({}, this.transform(document).defaultVars), variables);
6028
+ return tslib.__assign(tslib.__assign({}, this.getDocumentInfo(document).defaultVars), variables);
5758
6029
  };
5759
6030
  QueryManager.prototype.watchQuery = function (options) {
5760
- options = tslib.__assign(tslib.__assign({}, options), { variables: this.getVariables(options.query, options.variables) });
6031
+ var query = this.transform(options.query);
6032
+ options = tslib.__assign(tslib.__assign({}, options), { variables: this.getVariables(query, options.variables) });
5761
6033
  if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
5762
6034
  options.notifyOnNetworkStatusChange = false;
5763
6035
  }
@@ -5767,9 +6039,10 @@ var QueryManager = (function () {
5767
6039
  queryInfo: queryInfo,
5768
6040
  options: options,
5769
6041
  });
6042
+ observable['lastQuery'] = query;
5770
6043
  this.queries.set(observable.queryId, queryInfo);
5771
6044
  queryInfo.init({
5772
- document: observable.query,
6045
+ document: query,
5773
6046
  observableQuery: observable,
5774
6047
  variables: observable.variables,
5775
6048
  });
@@ -5778,12 +6051,11 @@ var QueryManager = (function () {
5778
6051
  QueryManager.prototype.query = function (options, queryId) {
5779
6052
  var _this = this;
5780
6053
  if (queryId === void 0) { queryId = this.generateQueryId(); }
5781
- __DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
5782
- 'in the query option.') : tsInvariant.invariant(options.query, 17);
5783
- __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 18);
5784
- __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 19);
5785
- __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 20);
5786
- return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
6054
+ invariant(options.query, 28);
6055
+ invariant(options.query.kind === 'Document', 29);
6056
+ invariant(!options.returnPartialData, 30);
6057
+ invariant(!options.pollInterval, 31);
6058
+ return this.fetchQuery(queryId, tslib.__assign(tslib.__assign({}, options), { query: this.transform(options.query) })).finally(function () { return _this.stopQuery(queryId); });
5787
6059
  };
5788
6060
  QueryManager.prototype.generateQueryId = function () {
5789
6061
  return String(this.queryIdCounter++);
@@ -5807,7 +6079,7 @@ var QueryManager = (function () {
5807
6079
  if (options === void 0) { options = {
5808
6080
  discardWatches: true,
5809
6081
  }; }
5810
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(21));
6082
+ this.cancelPendingFetches(newInvariantError(32));
5811
6083
  this.queries.forEach(function (queryInfo) {
5812
6084
  if (queryInfo.observableQuery) {
5813
6085
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -5833,7 +6105,7 @@ var QueryManager = (function () {
5833
6105
  queryNamesAndDocs.set(desc, false);
5834
6106
  }
5835
6107
  else if (isDocumentNode(desc)) {
5836
- queryNamesAndDocs.set(_this.transform(desc).document, false);
6108
+ queryNamesAndDocs.set(_this.transform(desc), false);
5837
6109
  }
5838
6110
  else if (isNonNullObject(desc) && desc.query) {
5839
6111
  legacyQueryOptions.add(desc);
@@ -5875,7 +6147,7 @@ var QueryManager = (function () {
5875
6147
  queryInfo: queryInfo,
5876
6148
  options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
5877
6149
  });
5878
- tsInvariant.invariant(oq.queryId === queryId);
6150
+ invariant(oq.queryId === queryId);
5879
6151
  queryInfo.setObservableQuery(oq);
5880
6152
  queries.set(queryId, oq);
5881
6153
  });
@@ -5883,7 +6155,7 @@ var QueryManager = (function () {
5883
6155
  if (__DEV__ && queryNamesAndDocs.size) {
5884
6156
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
5885
6157
  if (!included) {
5886
- __DEV__ && tsInvariant.invariant.warn("Unknown query ".concat(typeof nameOrDoc === "string" ? "named " : "").concat(JSON.stringify(nameOrDoc, null, 2), " requested in refetchQueries options.include array"));
6158
+ __DEV__ && invariant.warn(typeof nameOrDoc === "string" ? 33 : 34, nameOrDoc);
5887
6159
  }
5888
6160
  });
5889
6161
  }
@@ -5912,7 +6184,7 @@ var QueryManager = (function () {
5912
6184
  QueryManager.prototype.startGraphQLSubscription = function (_a) {
5913
6185
  var _this = this;
5914
6186
  var query = _a.query, fetchPolicy = _a.fetchPolicy, errorPolicy = _a.errorPolicy, variables = _a.variables, _b = _a.context, context = _b === void 0 ? {} : _b;
5915
- query = this.transform(query).document;
6187
+ query = this.transform(query);
5916
6188
  variables = this.getVariables(query, variables);
5917
6189
  var makeObservable = function (variables) {
5918
6190
  return _this.getObservableFromLink(query, context, variables).map(function (result) {
@@ -5927,15 +6199,22 @@ var QueryManager = (function () {
5927
6199
  }
5928
6200
  _this.broadcastQueries();
5929
6201
  }
5930
- if (graphQLResultHasError(result)) {
5931
- throw new ApolloError({
5932
- graphQLErrors: result.errors,
5933
- });
6202
+ var hasErrors = graphQLResultHasError(result);
6203
+ var hasProtocolErrors = graphQLResultHasProtocolErrors(result);
6204
+ if (hasErrors || hasProtocolErrors) {
6205
+ var errors = {};
6206
+ if (hasErrors) {
6207
+ errors.graphQLErrors = result.errors;
6208
+ }
6209
+ if (hasProtocolErrors) {
6210
+ errors.protocolErrors = result.extensions[PROTOCOL_ERRORS_SYMBOL];
6211
+ }
6212
+ throw new ApolloError(errors);
5934
6213
  }
5935
6214
  return result;
5936
6215
  });
5937
6216
  };
5938
- if (this.transform(query).hasClientExports) {
6217
+ if (this.getDocumentInfo(query).hasClientExports) {
5939
6218
  var observablePromise_1 = this.localState.addExportedVariables(query, variables, context).then(makeObservable);
5940
6219
  return new zenObservableTs.Observable(function (observer) {
5941
6220
  var sub = null;
@@ -5973,9 +6252,9 @@ var QueryManager = (function () {
5973
6252
  var _a;
5974
6253
  if (deduplication === void 0) { deduplication = (_a = context === null || context === void 0 ? void 0 : context.queryDeduplication) !== null && _a !== void 0 ? _a : this.queryDeduplication; }
5975
6254
  var observable;
5976
- var serverQuery = this.transform(query).serverQuery;
6255
+ var _b = this.getDocumentInfo(query), serverQuery = _b.serverQuery, clientQuery = _b.clientQuery;
5977
6256
  if (serverQuery) {
5978
- var _b = this, inFlightLinkObservables_1 = _b.inFlightLinkObservables, link = _b.link;
6257
+ var _c = this, inFlightLinkObservables_1 = _c.inFlightLinkObservables, link = _c.link;
5979
6258
  var operation = {
5980
6259
  query: serverQuery,
5981
6260
  variables: variables,
@@ -6013,7 +6292,6 @@ var QueryManager = (function () {
6013
6292
  ]);
6014
6293
  context = this.prepareContext(context);
6015
6294
  }
6016
- var clientQuery = this.transform(query).clientQuery;
6017
6295
  if (clientQuery) {
6018
6296
  observable = asyncMap(observable, function (result) {
6019
6297
  return _this.localState.runResolvers({
@@ -6028,7 +6306,7 @@ var QueryManager = (function () {
6028
6306
  };
6029
6307
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
6030
6308
  var requestId = queryInfo.lastRequestId = this.generateRequestId();
6031
- var linkDocument = this.cache.transformForLink(this.transform(queryInfo.document).document);
6309
+ var linkDocument = this.cache.transformForLink(options.query);
6032
6310
  return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
6033
6311
  var graphQLErrors = getGraphQLErrorsFromResult(result);
6034
6312
  var hasErrors = graphQLErrors.length > 0;
@@ -6061,10 +6339,10 @@ var QueryManager = (function () {
6061
6339
  throw error;
6062
6340
  });
6063
6341
  };
6064
- QueryManager.prototype.fetchQueryObservable = function (queryId, options, networkStatus) {
6342
+ QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus) {
6065
6343
  var _this = this;
6066
6344
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
6067
- var query = this.transform(options.query).document;
6345
+ var query = options.query;
6068
6346
  var variables = this.getVariables(query, options.variables);
6069
6347
  var queryInfo = this.getQuery(queryId);
6070
6348
  var defaults = this.defaultOptions.watchQuery;
@@ -6080,24 +6358,36 @@ var QueryManager = (function () {
6080
6358
  });
6081
6359
  var fromVariables = function (variables) {
6082
6360
  normalized.variables = variables;
6083
- var concastSources = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
6361
+ var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
6084
6362
  if (normalized.fetchPolicy !== "standby" &&
6085
- concastSources.length > 0 &&
6363
+ sourcesWithInfo.sources.length > 0 &&
6086
6364
  queryInfo.observableQuery) {
6087
6365
  queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
6088
6366
  }
6089
- return concastSources;
6367
+ return sourcesWithInfo;
6090
6368
  };
6091
6369
  var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
6092
6370
  this.fetchCancelFns.set(queryId, function (reason) {
6093
6371
  cleanupCancelFn();
6094
6372
  setTimeout(function () { return concast.cancel(reason); });
6095
6373
  });
6096
- var concast = new Concast(this.transform(normalized.query).hasClientExports
6097
- ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
6098
- : fromVariables(normalized.variables));
6374
+ var concast, containsDataFromLink;
6375
+ if (this.getDocumentInfo(normalized.query).hasClientExports) {
6376
+ concast = new Concast(this.localState
6377
+ .addExportedVariables(normalized.query, normalized.variables, normalized.context)
6378
+ .then(fromVariables).then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
6379
+ containsDataFromLink = true;
6380
+ }
6381
+ else {
6382
+ var sourcesWithInfo = fromVariables(normalized.variables);
6383
+ containsDataFromLink = sourcesWithInfo.fromLink;
6384
+ concast = new Concast(sourcesWithInfo.sources);
6385
+ }
6099
6386
  concast.promise.then(cleanupCancelFn, cleanupCancelFn);
6100
- return concast;
6387
+ return {
6388
+ concast: concast,
6389
+ fromLink: containsDataFromLink,
6390
+ };
6101
6391
  };
6102
6392
  QueryManager.prototype.refetchQueries = function (_a) {
6103
6393
  var _this = this;
@@ -6172,7 +6462,7 @@ var QueryManager = (function () {
6172
6462
  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;
6173
6463
  var oldNetworkStatus = queryInfo.networkStatus;
6174
6464
  queryInfo.init({
6175
- document: this.transform(query).document,
6465
+ document: query,
6176
6466
  variables: variables,
6177
6467
  networkStatus: networkStatus,
6178
6468
  });
@@ -6182,11 +6472,11 @@ var QueryManager = (function () {
6182
6472
  var data = diff.result;
6183
6473
  if (__DEV__ &&
6184
6474
  !returnPartialData &&
6185
- !equality.equal(data, {})) {
6475
+ !equal.equal(data, {})) {
6186
6476
  logMissingFieldErrors(diff.missing);
6187
6477
  }
6188
6478
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
6189
- if (data && _this.transform(query).hasForcedResolvers) {
6479
+ if (data && _this.getDocumentInfo(query).hasForcedResolvers) {
6190
6480
  return _this.localState.runResolvers({
6191
6481
  document: query,
6192
6482
  remoteResult: { data: data },
@@ -6207,6 +6497,7 @@ var QueryManager = (function () {
6207
6497
  refetchWritePolicy !== "merge") ? 1
6208
6498
  : 2;
6209
6499
  var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
6500
+ query: query,
6210
6501
  variables: variables,
6211
6502
  context: context,
6212
6503
  fetchPolicy: fetchPolicy,
@@ -6221,54 +6512,40 @@ var QueryManager = (function () {
6221
6512
  case "cache-first": {
6222
6513
  var diff = readCache();
6223
6514
  if (diff.complete) {
6224
- return [
6225
- resultsFromCache(diff, queryInfo.markReady()),
6226
- ];
6515
+ return { fromLink: false, sources: [resultsFromCache(diff, queryInfo.markReady())] };
6227
6516
  }
6228
6517
  if (returnPartialData || shouldNotify) {
6229
- return [
6230
- resultsFromCache(diff),
6231
- resultsFromLink(),
6232
- ];
6518
+ return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
6233
6519
  }
6234
- return [
6235
- resultsFromLink(),
6236
- ];
6520
+ return { fromLink: true, sources: [resultsFromLink()] };
6237
6521
  }
6238
6522
  case "cache-and-network": {
6239
6523
  var diff = readCache();
6240
6524
  if (diff.complete || returnPartialData || shouldNotify) {
6241
- return [
6242
- resultsFromCache(diff),
6243
- resultsFromLink(),
6244
- ];
6525
+ return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
6245
6526
  }
6246
- return [
6247
- resultsFromLink(),
6248
- ];
6527
+ return { fromLink: true, sources: [resultsFromLink()] };
6249
6528
  }
6250
6529
  case "cache-only":
6251
- return [
6252
- resultsFromCache(readCache(), queryInfo.markReady()),
6253
- ];
6530
+ return { fromLink: false, sources: [resultsFromCache(readCache(), queryInfo.markReady())] };
6254
6531
  case "network-only":
6255
6532
  if (shouldNotify) {
6256
- return [
6257
- resultsFromCache(readCache()),
6258
- resultsFromLink(),
6259
- ];
6533
+ return { fromLink: true, sources: [resultsFromCache(readCache()), resultsFromLink()] };
6260
6534
  }
6261
- return [resultsFromLink()];
6535
+ return { fromLink: true, sources: [resultsFromLink()] };
6262
6536
  case "no-cache":
6263
6537
  if (shouldNotify) {
6264
- return [
6265
- resultsFromCache(queryInfo.getDiff()),
6266
- resultsFromLink(),
6267
- ];
6538
+ return {
6539
+ fromLink: true,
6540
+ sources: [
6541
+ resultsFromCache(queryInfo.getDiff()),
6542
+ resultsFromLink(),
6543
+ ],
6544
+ };
6268
6545
  }
6269
- return [resultsFromLink()];
6546
+ return { fromLink: true, sources: [resultsFromLink()] };
6270
6547
  case "standby":
6271
- return [];
6548
+ return { fromLink: false, sources: [] };
6272
6549
  }
6273
6550
  };
6274
6551
  QueryManager.prototype.getQuery = function (queryId) {
@@ -6291,20 +6568,18 @@ var ApolloClient = (function () {
6291
6568
  var _this = this;
6292
6569
  this.resetStoreCallbacks = [];
6293
6570
  this.clearStoreCallbacks = [];
6294
- 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' &&
6571
+ if (!options.cache) {
6572
+ throw newInvariantError(13);
6573
+ }
6574
+ var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform, _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' &&
6295
6575
  !window.__APOLLO_CLIENT__ &&
6296
- __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;
6576
+ __DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
6297
6577
  var link = options.link;
6298
6578
  if (!link) {
6299
6579
  link = uri
6300
6580
  ? new HttpLink({ uri: uri, credentials: credentials, headers: headers })
6301
6581
  : ApolloLink.empty();
6302
6582
  }
6303
- if (!cache) {
6304
- throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
6305
- "in the options object. \n" +
6306
- "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
6307
- }
6308
6583
  this.link = link;
6309
6584
  this.cache = cache;
6310
6585
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
@@ -6341,8 +6616,7 @@ var ApolloClient = (function () {
6341
6616
  }
6342
6617
  }
6343
6618
  if (url) {
6344
- __DEV__ && tsInvariant.invariant.log("Download the Apollo DevTools for a better development " +
6345
- "experience: " + url);
6619
+ __DEV__ && invariant.log(14, url);
6346
6620
  }
6347
6621
  }
6348
6622
  }
@@ -6357,6 +6631,7 @@ var ApolloClient = (function () {
6357
6631
  cache: this.cache,
6358
6632
  link: this.link,
6359
6633
  defaultOptions: this.defaultOptions,
6634
+ documentTransform: documentTransform,
6360
6635
  queryDeduplication: queryDeduplication,
6361
6636
  ssrMode: ssrMode,
6362
6637
  clientAwareness: {
@@ -6379,6 +6654,13 @@ var ApolloClient = (function () {
6379
6654
  } : void 0,
6380
6655
  });
6381
6656
  }
6657
+ Object.defineProperty(ApolloClient.prototype, "documentTransform", {
6658
+ get: function () {
6659
+ return this.queryManager.documentTransform;
6660
+ },
6661
+ enumerable: false,
6662
+ configurable: true
6663
+ });
6382
6664
  ApolloClient.prototype.stop = function () {
6383
6665
  this.queryManager.stop();
6384
6666
  };
@@ -6397,10 +6679,7 @@ var ApolloClient = (function () {
6397
6679
  if (this.defaultOptions.query) {
6398
6680
  options = mergeOptions(this.defaultOptions.query, options);
6399
6681
  }
6400
- __DEV__ ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
6401
- 'client.query can only return a single result. Please use client.watchQuery ' +
6402
- 'to receive multiple results from the cache and the network, or consider ' +
6403
- 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 10);
6682
+ invariant(options.fetchPolicy !== 'cache-and-network', 15);
6404
6683
  if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
6405
6684
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
6406
6685
  }
@@ -6489,7 +6768,7 @@ var ApolloClient = (function () {
6489
6768
  result.queries = queries;
6490
6769
  result.results = results;
6491
6770
  result.catch(function (error) {
6492
- __DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error ".concat(error));
6771
+ __DEV__ && invariant.debug(16, error);
6493
6772
  });
6494
6773
  return result;
6495
6774
  };
@@ -6525,24 +6804,25 @@ var contextKey = canUseSymbol
6525
6804
  ? Symbol.for('__APOLLO_CONTEXT__')
6526
6805
  : '__APOLLO_CONTEXT__';
6527
6806
  function getApolloContext() {
6528
- var context = React__namespace.createContext[contextKey];
6807
+ invariant('createContext' in React__namespace, 45);
6808
+ var contextStorage = global$1[contextKey];
6809
+ if (!contextStorage) {
6810
+ contextStorage = global$1[contextKey] = new Map();
6811
+ }
6812
+ var context = contextStorage.get(React__namespace);
6529
6813
  if (!context) {
6530
- Object.defineProperty(React__namespace.createContext, contextKey, {
6531
- value: context = React__namespace.createContext({}),
6532
- enumerable: false,
6533
- writable: false,
6534
- configurable: true,
6535
- });
6814
+ context = React__namespace.createContext({});
6536
6815
  context.displayName = 'ApolloContext';
6816
+ contextStorage.set(React__namespace, context);
6537
6817
  }
6538
6818
  return context;
6539
6819
  }
6820
+ var resetApolloContext = getApolloContext;
6540
6821
 
6541
6822
  var ApolloConsumer = function (props) {
6542
6823
  var ApolloContext = getApolloContext();
6543
6824
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6544
- __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
6545
- 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 28);
6825
+ invariant(context && context.client, 44);
6546
6826
  return props.children(context.client);
6547
6827
  }));
6548
6828
  };
@@ -6550,39 +6830,31 @@ var ApolloConsumer = function (props) {
6550
6830
  var ApolloProvider = function (_a) {
6551
6831
  var client = _a.client, suspenseCache = _a.suspenseCache, children = _a.children;
6552
6832
  var ApolloContext = getApolloContext();
6553
- return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6554
- if (context === void 0) { context = {}; }
6555
- if (client && context.client !== client) {
6556
- context = Object.assign({}, context, { client: client });
6557
- }
6558
- if (suspenseCache) {
6559
- context = Object.assign({}, context, { suspenseCache: suspenseCache });
6560
- }
6561
- __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
6562
- 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 29);
6563
- return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6564
- }));
6833
+ var parentContext = React__namespace.useContext(ApolloContext);
6834
+ var context = React__namespace.useMemo(function () {
6835
+ return tslib.__assign(tslib.__assign({}, parentContext), { client: client || parentContext.client, suspenseCache: suspenseCache || parentContext.suspenseCache });
6836
+ }, [parentContext, client, suspenseCache]);
6837
+ invariant(context.client, 46);
6838
+ return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6565
6839
  };
6566
6840
 
6567
6841
  function useApolloClient(override) {
6568
6842
  var context = React.useContext(getApolloContext());
6569
6843
  var client = override || context.client;
6570
- __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
6571
- 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
6572
- 'instance in via options.') : tsInvariant.invariant(!!client, 32);
6844
+ invariant(!!client, 49);
6573
6845
  return client;
6574
6846
  }
6575
6847
 
6576
6848
  var didWarnUncachedGetSnapshot = false;
6577
6849
  var uSESKey = "useSyncExternalStore";
6578
- var realHook = React__namespace[uSESKey];
6579
- var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
6850
+ var realHook$1 = React__namespace[uSESKey];
6851
+ var useSyncExternalStore = realHook$1 || (function (subscribe, getSnapshot, getServerSnapshot) {
6580
6852
  var value = getSnapshot();
6581
6853
  if (__DEV__ &&
6582
6854
  !didWarnUncachedGetSnapshot &&
6583
6855
  value !== getSnapshot()) {
6584
6856
  didWarnUncachedGetSnapshot = true;
6585
- __DEV__ && tsInvariant.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
6857
+ __DEV__ && invariant.error(59);
6586
6858
  }
6587
6859
  var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
6588
6860
  if (canUseLayoutEffect) {
@@ -6645,9 +6917,7 @@ function parser(document) {
6645
6917
  if (cached)
6646
6918
  return cached;
6647
6919
  var variables, type, name;
6648
- __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6649
- "DocumentNode. You may need to use 'graphql-tag' or another method " +
6650
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 35);
6920
+ invariant(!!document && !!document.kind, 60, document);
6651
6921
  var fragments = [];
6652
6922
  var queries = [];
6653
6923
  var mutations = [];
@@ -6672,14 +6942,16 @@ function parser(document) {
6672
6942
  }
6673
6943
  }
6674
6944
  }
6675
- __DEV__ ? tsInvariant.invariant(!fragments.length ||
6676
- (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6677
- "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6678
- (queries.length || mutations.length || subscriptions.length), 36);
6679
- __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6680
- "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6681
- "subscriptions and ".concat(mutations.length, " mutations. ") +
6682
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 37);
6945
+ invariant(!fragments.length ||
6946
+ (queries.length || mutations.length || subscriptions.length), 61);
6947
+ invariant(
6948
+ queries.length + mutations.length + subscriptions.length <= 1,
6949
+ 62,
6950
+ document,
6951
+ queries.length,
6952
+ subscriptions.length,
6953
+ mutations.length
6954
+ );
6683
6955
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6684
6956
  if (!queries.length && !mutations.length)
6685
6957
  type = exports.DocumentType.Subscription;
@@ -6688,9 +6960,7 @@ function parser(document) {
6688
6960
  : mutations.length
6689
6961
  ? mutations
6690
6962
  : subscriptions;
6691
- __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6692
- "".concat(definitions.length, " definitions. ") +
6693
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 38);
6963
+ invariant(definitions.length === 1, 63, document, definitions.length);
6694
6964
  var definition = definitions[0];
6695
6965
  variables = definition.variableDefinitions || [];
6696
6966
  if (definition.name && definition.name.kind === 'Name') {
@@ -6707,8 +6977,13 @@ function verifyDocumentType(document, type) {
6707
6977
  var operation = parser(document);
6708
6978
  var requiredOperationName = operationName(type);
6709
6979
  var usedOperationName = operationName(operation.type);
6710
- __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6711
- "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 39);
6980
+ invariant(
6981
+ operation.type === type,
6982
+ 64,
6983
+ requiredOperationName,
6984
+ requiredOperationName,
6985
+ usedOperationName
6986
+ );
6712
6987
  }
6713
6988
 
6714
6989
  var hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -6734,8 +7009,6 @@ var InternalState = (function () {
6734
7009
  function InternalState(client, query, previous) {
6735
7010
  this.client = client;
6736
7011
  this.query = query;
6737
- this.asyncResolveFns = new Set();
6738
- this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
6739
7012
  this.ssrDisabledResult = maybeDeepFreeze({
6740
7013
  loading: true,
6741
7014
  data: void 0,
@@ -6757,22 +7030,32 @@ var InternalState = (function () {
6757
7030
  }
6758
7031
  }
6759
7032
  InternalState.prototype.forceUpdate = function () {
6760
- __DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
7033
+ __DEV__ && invariant.warn(51);
6761
7034
  };
6762
- InternalState.prototype.asyncUpdate = function (signal) {
7035
+ InternalState.prototype.executeQuery = function (options) {
6763
7036
  var _this = this;
6764
- return new Promise(function (resolve, reject) {
6765
- var watchQueryOptions = _this.watchQueryOptions;
6766
- var handleAborted = function () {
6767
- _this.asyncResolveFns.delete(resolve);
6768
- _this.optionsToIgnoreOnce.delete(watchQueryOptions);
6769
- signal.removeEventListener('abort', handleAborted);
6770
- reject(signal.reason);
6771
- };
6772
- _this.asyncResolveFns.add(resolve);
6773
- _this.optionsToIgnoreOnce.add(watchQueryOptions);
6774
- signal.addEventListener('abort', handleAborted);
6775
- _this.forceUpdate();
7037
+ var _a;
7038
+ if (options.query) {
7039
+ Object.assign(this, { query: options.query });
7040
+ }
7041
+ this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
7042
+ var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
7043
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
7044
+ this.result = void 0;
7045
+ this.forceUpdate();
7046
+ return new Promise(function (resolve) {
7047
+ var result;
7048
+ concast.subscribe({
7049
+ next: function (value) {
7050
+ result = value;
7051
+ },
7052
+ error: function () {
7053
+ resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
7054
+ },
7055
+ complete: function () {
7056
+ resolve(_this.toQueryResult(result));
7057
+ }
7058
+ });
6776
7059
  });
6777
7060
  };
6778
7061
  InternalState.prototype.useQuery = function (options) {
@@ -6790,7 +7073,7 @@ var InternalState = (function () {
6790
7073
  if (previousResult &&
6791
7074
  previousResult.loading === result.loading &&
6792
7075
  previousResult.networkStatus === result.networkStatus &&
6793
- equality.equal(previousResult.data, result.data)) {
7076
+ equal.equal(previousResult.data, result.data)) {
6794
7077
  return;
6795
7078
  }
6796
7079
  _this.setResult(result);
@@ -6811,7 +7094,7 @@ var InternalState = (function () {
6811
7094
  var previousResult = _this.result;
6812
7095
  if (!previousResult ||
6813
7096
  (previousResult && previousResult.loading) ||
6814
- !equality.equal(error, previousResult.error)) {
7097
+ !equal.equal(error, previousResult.error)) {
6815
7098
  _this.setResult({
6816
7099
  data: (previousResult && previousResult.data),
6817
7100
  error: error,
@@ -6828,22 +7111,15 @@ var InternalState = (function () {
6828
7111
  this.client.disableNetworkFetches,
6829
7112
  ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
6830
7113
  this.unsafeHandlePartialRefetch(result);
6831
- var queryResult = this.toQueryResult(result);
6832
- if (!queryResult.loading && this.asyncResolveFns.size) {
6833
- this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
6834
- this.asyncResolveFns.clear();
6835
- }
6836
- return queryResult;
7114
+ return this.toQueryResult(result);
6837
7115
  };
6838
7116
  InternalState.prototype.useOptions = function (options) {
6839
7117
  var _a;
6840
7118
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
6841
7119
  var currentWatchQueryOptions = this.watchQueryOptions;
6842
- if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
6843
- !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
7120
+ if (!equal.equal(watchQueryOptions, currentWatchQueryOptions)) {
6844
7121
  this.watchQueryOptions = watchQueryOptions;
6845
7122
  if (currentWatchQueryOptions && this.observable) {
6846
- this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
6847
7123
  this.observable.reobserve(this.getObsQueryOptions());
6848
7124
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
6849
7125
  this.result = void 0;
@@ -6959,7 +7235,7 @@ var InternalState = (function () {
6959
7235
  _this.onCompleted(result.data);
6960
7236
  }
6961
7237
  }).catch(function (error) {
6962
- __DEV__ && tsInvariant.invariant.warn(error);
7238
+ __DEV__ && invariant.warn(error);
6963
7239
  });
6964
7240
  }
6965
7241
  };
@@ -7010,11 +7286,15 @@ var EAGER_METHODS = [
7010
7286
  'subscribeToMore',
7011
7287
  ];
7012
7288
  function useLazyQuery(query, options) {
7013
- var _a, _b;
7014
- var abortControllersRef = React.useRef(new Set());
7289
+ var _a;
7015
7290
  var execOptionsRef = React.useRef();
7016
- var merged = execOptionsRef.current ? mergeOptions(options, execOptionsRef.current) : options;
7017
- var internalState = useInternalState(useApolloClient(options && options.client), (_b = (_a = execOptionsRef.current) === null || _a === void 0 ? void 0 : _a.query) !== null && _b !== void 0 ? _b : query);
7291
+ var optionsRef = React.useRef();
7292
+ var queryRef = React.useRef();
7293
+ var merged = mergeOptions(options, execOptionsRef.current || {});
7294
+ var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
7295
+ optionsRef.current = merged;
7296
+ queryRef.current = document;
7297
+ var internalState = useInternalState(useApolloClient(options && options.client), document);
7018
7298
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
7019
7299
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
7020
7300
  internalState.getDefaultFetchPolicy();
@@ -7040,28 +7320,15 @@ function useLazyQuery(query, options) {
7040
7320
  return eagerMethods;
7041
7321
  }, []);
7042
7322
  Object.assign(result, eagerMethods);
7043
- React.useEffect(function () {
7044
- return function () {
7045
- abortControllersRef.current.forEach(function (controller) {
7046
- controller.abort();
7047
- });
7048
- };
7049
- }, []);
7050
7323
  var execute = React.useCallback(function (executeOptions) {
7051
- var controller = new AbortController();
7052
- abortControllersRef.current.add(controller);
7053
7324
  execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
7054
7325
  fetchPolicy: initialFetchPolicy,
7055
7326
  };
7327
+ var options = mergeOptions(optionsRef.current, tslib.__assign({ query: queryRef.current }, execOptionsRef.current));
7056
7328
  var promise = internalState
7057
- .asyncUpdate(controller.signal)
7058
- .then(function (queryResult) {
7059
- abortControllersRef.current.delete(controller);
7060
- return Object.assign(queryResult, eagerMethods);
7061
- });
7062
- promise.catch(function () {
7063
- abortControllersRef.current.delete(controller);
7064
- });
7329
+ .executeQuery(tslib.__assign(tslib.__assign({}, options), { skip: false }))
7330
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
7331
+ promise.catch(function () { });
7065
7332
  return promise;
7066
7333
  }, []);
7067
7334
  return [execute, result];
@@ -7117,7 +7384,7 @@ function useMutation(mutation, options) {
7117
7384
  error: error,
7118
7385
  client: client,
7119
7386
  };
7120
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
7387
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
7121
7388
  setResult(ref.current.result = result_1);
7122
7389
  }
7123
7390
  }
@@ -7135,7 +7402,7 @@ function useMutation(mutation, options) {
7135
7402
  called: true,
7136
7403
  client: client,
7137
7404
  };
7138
- if (!equality.equal(ref.current.result, result_2)) {
7405
+ if (!equal.equal(ref.current.result, result_2)) {
7139
7406
  setResult(ref.current.result = result_2);
7140
7407
  }
7141
7408
  }
@@ -7174,14 +7441,10 @@ function useSubscription(subscription, options) {
7174
7441
  if (!hasIssuedDeprecationWarningRef.current) {
7175
7442
  hasIssuedDeprecationWarningRef.current = true;
7176
7443
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionData) {
7177
- __DEV__ && tsInvariant.invariant.warn(options.onData
7178
- ? "'useSubscription' supports only the 'onSubscriptionData' or 'onData' option, but not both. Only the 'onData' option will be used."
7179
- : "'onSubscriptionData' is deprecated and will be removed in a future major version. Please use the 'onData' option instead.");
7444
+ __DEV__ && invariant.warn(options.onData ? 52 : 53);
7180
7445
  }
7181
7446
  if (options === null || options === void 0 ? void 0 : options.onSubscriptionComplete) {
7182
- __DEV__ && tsInvariant.invariant.warn(options.onComplete
7183
- ? "'useSubscription' supports only the 'onSubscriptionComplete' or 'onComplete' option, but not both. Only the 'onComplete' option will be used."
7184
- : "'onSubscriptionComplete' is deprecated and will be removed in a future major version. Please use the 'onComplete' option instead.");
7447
+ __DEV__ && invariant.warn(options.onComplete ? 54 : 55);
7185
7448
  }
7186
7449
  }
7187
7450
  var _b = React.useState(function () {
@@ -7225,7 +7488,7 @@ function useSubscription(subscription, options) {
7225
7488
  subscription !== ref.current.subscription ||
7226
7489
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
7227
7490
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
7228
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
7491
+ !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
7229
7492
  canResetObservableRef.current) {
7230
7493
  setResult({
7231
7494
  loading: true,
@@ -7247,9 +7510,13 @@ function useSubscription(subscription, options) {
7247
7510
  if (!observable) {
7248
7511
  return;
7249
7512
  }
7513
+ var subscriptionStopped = false;
7250
7514
  var subscription = observable.subscribe({
7251
7515
  next: function (fetchResult) {
7252
7516
  var _a, _b;
7517
+ if (subscriptionStopped) {
7518
+ return;
7519
+ }
7253
7520
  var result = {
7254
7521
  loading: false,
7255
7522
  data: fetchResult.data,
@@ -7272,26 +7539,33 @@ function useSubscription(subscription, options) {
7272
7539
  },
7273
7540
  error: function (error) {
7274
7541
  var _a, _b;
7275
- setResult({
7276
- loading: false,
7277
- data: void 0,
7278
- error: error,
7279
- variables: options === null || options === void 0 ? void 0 : options.variables,
7280
- });
7281
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
7542
+ if (!subscriptionStopped) {
7543
+ setResult({
7544
+ loading: false,
7545
+ data: void 0,
7546
+ error: error,
7547
+ variables: options === null || options === void 0 ? void 0 : options.variables,
7548
+ });
7549
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
7550
+ }
7282
7551
  },
7283
7552
  complete: function () {
7284
7553
  var _a, _b;
7285
- if ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onComplete) {
7286
- ref.current.options.onComplete();
7287
- }
7288
- else if ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onSubscriptionComplete) {
7289
- ref.current.options.onSubscriptionComplete();
7554
+ if (!subscriptionStopped) {
7555
+ if ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onComplete) {
7556
+ ref.current.options.onComplete();
7557
+ }
7558
+ else if ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onSubscriptionComplete) {
7559
+ ref.current.options.onSubscriptionComplete();
7560
+ }
7290
7561
  }
7291
7562
  },
7292
7563
  });
7293
7564
  return function () {
7294
- subscription.unsubscribe();
7565
+ subscriptionStopped = true;
7566
+ setTimeout(function () {
7567
+ subscription.unsubscribe();
7568
+ });
7295
7569
  };
7296
7570
  }, [observable]);
7297
7571
  return result;
@@ -7312,22 +7586,22 @@ function useReactiveVar(rv) {
7312
7586
  return value;
7313
7587
  }
7314
7588
 
7315
- function useFragment_experimental(options) {
7589
+ function useFragment(options) {
7316
7590
  var cache = useApolloClient().cache;
7317
7591
  var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
7318
- var diffOptions = tslib.__assign(tslib.__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
7592
+ var diffOptions = tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
7319
7593
  var resultRef = React.useRef();
7320
7594
  var latestDiff = cache.diff(diffOptions);
7321
7595
  var getSnapshot = function () {
7322
7596
  var latestDiffToResult = diffToResult(latestDiff);
7323
7597
  return resultRef.current &&
7324
- equality.equal(resultRef.current.data, latestDiffToResult.data)
7598
+ equal.equal(resultRef.current.data, latestDiffToResult.data)
7325
7599
  ? resultRef.current
7326
7600
  : (resultRef.current = latestDiffToResult);
7327
7601
  };
7328
7602
  return useSyncExternalStore(function (forceUpdate) {
7329
7603
  return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
7330
- if (!equality.equal(diff, latestDiff)) {
7604
+ if (!equal.equal(diff, latestDiff)) {
7331
7605
  resultRef.current = diffToResult((latestDiff = diff));
7332
7606
  forceUpdate();
7333
7607
  }
@@ -7347,122 +7621,116 @@ function diffToResult(diff) {
7347
7621
 
7348
7622
  function useDeepMemo(memoFn, deps) {
7349
7623
  var ref = React.useRef();
7350
- if (!ref.current || !equality.equal(ref.current.deps, deps)) {
7624
+ if (!ref.current || !equal.equal(ref.current.deps, deps)) {
7351
7625
  ref.current = { value: memoFn(), deps: deps };
7352
7626
  }
7353
7627
  return ref.current.value;
7354
7628
  }
7355
7629
 
7356
- var useIsomorphicLayoutEffect = canUseLayoutEffect
7357
- ? React.useLayoutEffect
7358
- : React.useEffect;
7630
+ function useStrictModeSafeCleanupEffect(cleanup) {
7631
+ var timeout;
7632
+ React.useEffect(function () {
7633
+ clearTimeout(timeout);
7634
+ return function () {
7635
+ timeout = setTimeout(cleanup);
7636
+ };
7637
+ }, []);
7638
+ }
7639
+
7640
+ var useKey = 'use';
7641
+ var realHook = React__default[useKey];
7642
+ var __use = realHook ||
7643
+ function __use(promise) {
7644
+ var statefulPromise = wrapPromiseWithState(promise);
7645
+ switch (statefulPromise.status) {
7646
+ case 'pending':
7647
+ throw statefulPromise;
7648
+ case 'rejected':
7649
+ throw statefulPromise.reason;
7650
+ case 'fulfilled':
7651
+ return statefulPromise.value;
7652
+ }
7653
+ };
7359
7654
 
7360
7655
  function useSuspenseCache(override) {
7361
7656
  var context = React.useContext(getApolloContext());
7362
7657
  var suspenseCache = override || context.suspenseCache;
7363
- __DEV__ ? tsInvariant.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context or passed in as an option. ' +
7364
- 'Wrap the root component in an <ApolloProvider> and provide a suspenseCache, ' +
7365
- 'or pass a SuspenseCache instance in via options.') : tsInvariant.invariant(suspenseCache, 33);
7658
+ invariant(suspenseCache, 56);
7366
7659
  return suspenseCache;
7367
7660
  }
7368
7661
 
7369
- var SUPPORTED_FETCH_POLICIES = [
7370
- 'cache-first',
7371
- 'network-only',
7372
- 'no-cache',
7373
- 'cache-and-network',
7374
- ];
7375
- var DEFAULT_FETCH_POLICY = 'cache-first';
7376
- var DEFAULT_SUSPENSE_POLICY = 'always';
7377
- var DEFAULT_ERROR_POLICY = 'none';
7378
- function useSuspenseQuery_experimental(query, options) {
7662
+ function useSuspenseQuery(query, options) {
7379
7663
  if (options === void 0) { options = Object.create(null); }
7380
- var suspenseCache = useSuspenseCache(options.suspenseCache);
7381
7664
  var client = useApolloClient(options.client);
7382
- var watchQueryOptions = useWatchQueryOptions({ query: query, options: options, client: client });
7383
- var previousWatchQueryOptionsRef = React.useRef(watchQueryOptions);
7384
- var deferred = useIsDeferred(query);
7385
- var fetchPolicy = watchQueryOptions.fetchPolicy, errorPolicy = watchQueryOptions.errorPolicy, returnPartialData = watchQueryOptions.returnPartialData, variables = watchQueryOptions.variables;
7386
- var cacheEntry = suspenseCache.lookup(query, variables);
7387
- var observable = React.useState(function () {
7388
- return (cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.observable) || client.watchQuery(watchQueryOptions);
7389
- })[0];
7390
- var result = useObservableQueryResult(observable);
7391
- var hasFullResult = result.data && !result.partial;
7392
- var hasPartialResult = result.data && result.partial;
7393
- var usePartialResult = returnPartialData && hasPartialResult;
7394
- var allowsThrownErrors = errorPolicy === 'none' && (!deferred || !hasPartialResult);
7395
- if (result.error &&
7396
- (result.error.networkError || allowsThrownErrors)) {
7397
- throw result.error;
7398
- }
7399
- if (result.loading) {
7400
- if (!cacheEntry) {
7401
- cacheEntry = suspenseCache.add(query, variables, {
7402
- promise: maybeWrapConcastWithCustomPromise(observable.reobserveAsConcast(watchQueryOptions), { deferred: deferred }),
7403
- observable: observable,
7404
- });
7405
- }
7406
- var hasUsableResult = usePartialResult ||
7407
- (fetchPolicy === 'cache-and-network' && hasFullResult);
7408
- if (!hasUsableResult && !cacheEntry.fulfilled) {
7409
- throw cacheEntry.promise;
7410
- }
7665
+ var suspenseCache = useSuspenseCache(options.suspenseCache);
7666
+ var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
7667
+ var variables = watchQueryOptions.variables;
7668
+ var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
7669
+ var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
7670
+ var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
7671
+ return client.watchQuery(watchQueryOptions);
7672
+ });
7673
+ var _b = React.useState(function () { return new Map([[queryRef.key, queryRef.promise]]); }), promiseCache = _b[0], setPromiseCache = _b[1];
7674
+ var promise = promiseCache.get(queryRef.key);
7675
+ if (!promise) {
7676
+ promise = queryRef.promise;
7677
+ promiseCache.set(queryRef.key, promise);
7411
7678
  }
7679
+ useTrackedQueryRefs(queryRef);
7412
7680
  React.useEffect(function () {
7413
- var variables = watchQueryOptions.variables, query = watchQueryOptions.query;
7414
- var previousOpts = previousWatchQueryOptionsRef.current;
7415
- if (variables !== previousOpts.variables || query !== previousOpts.query) {
7416
- suspenseCache.remove(previousOpts.query, previousOpts.variables);
7417
- suspenseCache.add(query, variables, {
7418
- promise: observable.reobserve({ query: query, variables: variables }),
7419
- observable: observable,
7681
+ return queryRef.listen(function (promise) {
7682
+ setPromiseCache(function (promiseCache) {
7683
+ return new Map(promiseCache).set(queryRef.key, promise);
7420
7684
  });
7421
- previousWatchQueryOptionsRef.current = watchQueryOptions;
7422
- }
7423
- }, [watchQueryOptions]);
7424
- React.useEffect(function () {
7425
- return function () {
7426
- suspenseCache.remove(query, variables);
7427
- };
7428
- }, []);
7685
+ });
7686
+ }, [queryRef]);
7687
+ var result = __use(promise);
7688
+ var fetchMore = React.useCallback(function (options) {
7689
+ var promise = queryRef.fetchMore(options);
7690
+ setPromiseCache(function (previousPromiseCache) {
7691
+ return new Map(previousPromiseCache).set(queryRef.key, promise);
7692
+ });
7693
+ return promise;
7694
+ }, [queryRef]);
7695
+ var refetch = React.useCallback(function (variables) {
7696
+ var promise = queryRef.refetch(variables);
7697
+ setPromiseCache(function (previousPromiseCache) {
7698
+ return new Map(previousPromiseCache).set(queryRef.key, promise);
7699
+ });
7700
+ return promise;
7701
+ }, [queryRef]);
7702
+ var subscribeToMore = React.useCallback(function (options) { return queryRef.observable.subscribeToMore(options); }, [queryRef]);
7429
7703
  return React.useMemo(function () {
7430
7704
  return {
7431
7705
  client: client,
7432
7706
  data: result.data,
7433
- error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
7434
- fetchMore: function (options) {
7435
- var promise = observable.fetchMore(options);
7436
- suspenseCache.add(query, watchQueryOptions.variables, {
7437
- promise: promise,
7438
- observable: observable,
7439
- });
7440
- return promise;
7441
- },
7442
- refetch: function (variables) {
7443
- var promise = observable.refetch(variables);
7444
- suspenseCache.add(query, watchQueryOptions.variables, {
7445
- promise: promise,
7446
- observable: observable,
7447
- });
7448
- return promise;
7449
- },
7450
- subscribeToMore: function (options) { return observable.subscribeToMore(options); },
7707
+ error: toApolloError(result),
7708
+ networkStatus: result.networkStatus,
7709
+ fetchMore: fetchMore,
7710
+ refetch: refetch,
7711
+ subscribeToMore: subscribeToMore,
7451
7712
  };
7452
- }, [client, result, observable, errorPolicy]);
7713
+ }, [client, fetchMore, refetch, result, subscribeToMore]);
7453
7714
  }
7454
7715
  function validateOptions(options) {
7455
- var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
7716
+ var query = options.query, fetchPolicy = options.fetchPolicy, returnPartialData = options.returnPartialData;
7456
7717
  verifyDocumentType(query, exports.DocumentType.Query);
7457
7718
  validateFetchPolicy(fetchPolicy);
7458
7719
  validatePartialDataReturn(fetchPolicy, returnPartialData);
7459
7720
  }
7460
7721
  function validateFetchPolicy(fetchPolicy) {
7461
- __DEV__ ? tsInvariant.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : tsInvariant.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), 34);
7722
+ if (fetchPolicy === void 0) { fetchPolicy = 'cache-first'; }
7723
+ var supportedFetchPolicies = [
7724
+ 'cache-first',
7725
+ 'network-only',
7726
+ 'no-cache',
7727
+ 'cache-and-network',
7728
+ ];
7729
+ invariant(supportedFetchPolicies.includes(fetchPolicy), 57, fetchPolicy);
7462
7730
  }
7463
7731
  function validatePartialDataReturn(fetchPolicy, returnPartialData) {
7464
7732
  if (fetchPolicy === 'no-cache' && returnPartialData) {
7465
- __DEV__ && tsInvariant.invariant.warn('Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.');
7733
+ __DEV__ && invariant.warn(58);
7466
7734
  }
7467
7735
  }
7468
7736
  function toApolloError(result) {
@@ -7470,120 +7738,205 @@ function toApolloError(result) {
7470
7738
  ? new ApolloError({ graphQLErrors: result.errors })
7471
7739
  : result.error;
7472
7740
  }
7473
- function maybeWrapConcastWithCustomPromise(concast, _a) {
7474
- var deferred = _a.deferred;
7475
- if (deferred) {
7476
- return new Promise(function (resolve, reject) {
7477
- var subscription = concast.subscribe({
7478
- next: function (value) {
7479
- resolve(value);
7480
- subscription.unsubscribe();
7481
- },
7482
- error: reject,
7483
- });
7484
- });
7485
- }
7486
- return concast.promise;
7741
+ function useTrackedQueryRefs(queryRef) {
7742
+ var trackedQueryRefs = React.useRef(new Set());
7743
+ trackedQueryRefs.current.add(queryRef);
7744
+ useStrictModeSafeCleanupEffect(function () {
7745
+ trackedQueryRefs.current.forEach(function (sub) { return sub.dispose(); });
7746
+ });
7487
7747
  }
7488
7748
  function useWatchQueryOptions(_a) {
7489
- var query = _a.query, options = _a.options, client = _a.client;
7490
- var defaultOptions = client.defaultOptions.watchQuery;
7491
- var watchQueryOptions = useDeepMemo(function () {
7492
- var errorPolicy = options.errorPolicy, fetchPolicy = options.fetchPolicy, _a = options.suspensePolicy, suspensePolicy = _a === void 0 ? DEFAULT_SUSPENSE_POLICY : _a, variables = options.variables, watchQueryOptions = tslib.__rest(options, ["errorPolicy", "fetchPolicy", "suspensePolicy", "variables"]);
7493
- return tslib.__assign(tslib.__assign({}, watchQueryOptions), { query: query, errorPolicy: errorPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.errorPolicy) || DEFAULT_ERROR_POLICY, fetchPolicy: fetchPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.fetchPolicy) || DEFAULT_FETCH_POLICY, notifyOnNetworkStatusChange: suspensePolicy === 'always', fetchOnFirstSubscribe: false, variables: compact(tslib.__assign(tslib.__assign({}, defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.variables), variables)) });
7494
- }, [options, query, defaultOptions]);
7749
+ var query = _a.query, options = _a.options;
7750
+ var watchQueryOptions = useDeepMemo(function () { return (tslib.__assign(tslib.__assign({}, options), { query: query, notifyOnNetworkStatusChange: false, nextFetchPolicy: void 0 })); }, [options, query]);
7495
7751
  if (__DEV__) {
7496
7752
  validateOptions(watchQueryOptions);
7497
7753
  }
7498
7754
  return watchQueryOptions;
7499
7755
  }
7500
- function useIsDeferred(query) {
7501
- return React.useMemo(function () { return hasDirectives(['defer'], query); }, [query]);
7756
+
7757
+ function useBackgroundQuery(query, options) {
7758
+ if (options === void 0) { options = Object.create(null); }
7759
+ var suspenseCache = useSuspenseCache(options.suspenseCache);
7760
+ var client = useApolloClient(options.client);
7761
+ var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
7762
+ var variables = watchQueryOptions.variables;
7763
+ var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
7764
+ var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
7765
+ var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
7766
+ return client.watchQuery(watchQueryOptions);
7767
+ });
7768
+ var _b = React.useState(function () { return new Map([[queryRef.key, queryRef.promise]]); }), promiseCache = _b[0], setPromiseCache = _b[1];
7769
+ useTrackedQueryRefs(queryRef);
7770
+ var fetchMore = React.useCallback(function (options) {
7771
+ var promise = queryRef.fetchMore(options);
7772
+ setPromiseCache(function (promiseCache) {
7773
+ return new Map(promiseCache).set(queryRef.key, promise);
7774
+ });
7775
+ return promise;
7776
+ }, [queryRef]);
7777
+ var refetch = React.useCallback(function (variables) {
7778
+ var promise = queryRef.refetch(variables);
7779
+ setPromiseCache(function (promiseCache) {
7780
+ return new Map(promiseCache).set(queryRef.key, promise);
7781
+ });
7782
+ return promise;
7783
+ }, [queryRef]);
7784
+ queryRef.promiseCache = promiseCache;
7785
+ return React.useMemo(function () {
7786
+ return [
7787
+ queryRef,
7788
+ {
7789
+ fetchMore: fetchMore,
7790
+ refetch: refetch,
7791
+ },
7792
+ ];
7793
+ }, [queryRef, fetchMore, refetch]);
7502
7794
  }
7503
- function useObservableQueryResult(observable) {
7504
- var resultRef = React.useRef();
7505
- var isMountedRef = React.useRef(false);
7506
- var subscribeTimeoutRef = React.useRef();
7507
- if (!resultRef.current) {
7508
- resultRef.current = observable.getCurrentResult();
7795
+ function useReadQuery(queryRef) {
7796
+ var _a = React.useState(0), forceUpdate = _a[1];
7797
+ invariant(queryRef.promiseCache, 50);
7798
+ var promise = queryRef.promiseCache.get(queryRef.key);
7799
+ if (!promise) {
7800
+ promise = queryRef.promise;
7801
+ queryRef.promiseCache.set(queryRef.key, promise);
7509
7802
  }
7510
- useIsomorphicLayoutEffect(function () {
7511
- isMountedRef.current = true;
7512
- return function () {
7513
- isMountedRef.current = false;
7514
- };
7515
- }, []);
7516
- return useSyncExternalStore(React.useCallback(function (forceUpdate) {
7517
- clearTimeout(subscribeTimeoutRef.current);
7518
- function handleUpdate() {
7519
- var previousResult = resultRef.current;
7520
- var result = observable.getCurrentResult();
7521
- if (previousResult.loading === result.loading &&
7522
- previousResult.networkStatus === result.networkStatus &&
7523
- equality.equal(previousResult.data, result.data)) {
7524
- return;
7525
- }
7526
- resultRef.current = result;
7527
- if (isMountedRef.current) {
7528
- forceUpdate();
7529
- }
7530
- }
7531
- var subscription;
7532
- subscribeTimeoutRef.current = setTimeout(function () {
7533
- subscription = observable.subscribe({
7534
- next: handleUpdate,
7535
- error: handleUpdate,
7536
- });
7803
+ React.useEffect(function () {
7804
+ return queryRef.listen(function (promise) {
7805
+ queryRef.promiseCache.set(queryRef.key, promise);
7806
+ forceUpdate(function (prevState) { return prevState + 1; });
7537
7807
  });
7538
- return function () {
7539
- subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
7808
+ }, [queryRef]);
7809
+ var result = __use(promise);
7810
+ return React.useMemo(function () {
7811
+ return {
7812
+ data: result.data,
7813
+ networkStatus: result.networkStatus,
7814
+ error: toApolloError(result),
7540
7815
  };
7541
- }, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
7816
+ }, [result]);
7542
7817
  }
7543
7818
 
7544
- var SuspenseCache = (function () {
7545
- function SuspenseCache() {
7546
- this.queries = new Map();
7819
+ var QueryReference = (function () {
7820
+ function QueryReference(observable, options) {
7821
+ var _this = this;
7822
+ var _a;
7823
+ this.listeners = new Set();
7824
+ this.initialized = false;
7825
+ this.refetching = false;
7826
+ this.listen = this.listen.bind(this);
7827
+ this.handleNext = this.handleNext.bind(this);
7828
+ this.handleError = this.handleError.bind(this);
7829
+ this.dispose = this.dispose.bind(this);
7830
+ this.observable = observable;
7831
+ this.result = observable.getCurrentResult(false);
7832
+ this.key = options.key;
7833
+ if (options.onDispose) {
7834
+ this.onDispose = options.onDispose;
7835
+ }
7836
+ if (isNetworkRequestSettled(this.result.networkStatus) ||
7837
+ (this.result.data &&
7838
+ (!this.result.partial || this.observable.options.returnPartialData))) {
7839
+ this.promise = createFulfilledPromise(this.result);
7840
+ this.initialized = true;
7841
+ this.refetching = false;
7842
+ }
7843
+ this.subscription = observable.subscribe({
7844
+ next: this.handleNext,
7845
+ error: this.handleError,
7846
+ });
7847
+ if (!this.promise) {
7848
+ this.promise = new Promise(function (resolve, reject) {
7849
+ _this.resolve = resolve;
7850
+ _this.reject = reject;
7851
+ });
7852
+ }
7853
+ this.autoDisposeTimeoutId = setTimeout(this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
7547
7854
  }
7548
- SuspenseCache.prototype.add = function (query, variables, _a) {
7549
- var promise = _a.promise, observable = _a.observable;
7550
- var variablesKey = this.getVariablesKey(variables);
7551
- var map = this.queries.get(query) || new Map();
7552
- var entry = {
7553
- observable: observable,
7554
- fulfilled: false,
7555
- promise: promise
7556
- .catch(function () {
7557
- })
7558
- .finally(function () {
7559
- entry.fulfilled = true;
7560
- }),
7855
+ QueryReference.prototype.listen = function (listener) {
7856
+ var _this = this;
7857
+ clearTimeout(this.autoDisposeTimeoutId);
7858
+ this.listeners.add(listener);
7859
+ return function () {
7860
+ _this.listeners.delete(listener);
7561
7861
  };
7562
- map.set(variablesKey, entry);
7563
- this.queries.set(query, map);
7564
- return entry;
7565
7862
  };
7566
- SuspenseCache.prototype.lookup = function (query, variables) {
7567
- var _a;
7568
- return (_a = this.queries
7569
- .get(query)) === null || _a === void 0 ? void 0 : _a.get(this.getVariablesKey(variables));
7863
+ QueryReference.prototype.refetch = function (variables) {
7864
+ this.refetching = true;
7865
+ var promise = this.observable.refetch(variables);
7866
+ this.promise = promise;
7867
+ return promise;
7570
7868
  };
7571
- SuspenseCache.prototype.remove = function (query, variables) {
7572
- var map = this.queries.get(query);
7573
- if (!map) {
7869
+ QueryReference.prototype.fetchMore = function (options) {
7870
+ var promise = this.observable.fetchMore(options);
7871
+ this.promise = promise;
7872
+ return promise;
7873
+ };
7874
+ QueryReference.prototype.dispose = function () {
7875
+ this.subscription.unsubscribe();
7876
+ this.onDispose();
7877
+ };
7878
+ QueryReference.prototype.onDispose = function () {
7879
+ };
7880
+ QueryReference.prototype.handleNext = function (result) {
7881
+ if (!this.initialized || this.refetching) {
7882
+ if (!isNetworkRequestSettled(result.networkStatus)) {
7883
+ return;
7884
+ }
7885
+ if (this.result.data && result.data === void 0) {
7886
+ result.data = this.result.data;
7887
+ }
7888
+ this.initialized = true;
7889
+ this.refetching = false;
7890
+ this.result = result;
7891
+ this.resolve(result);
7574
7892
  return;
7575
7893
  }
7576
- var key = this.getVariablesKey(variables);
7577
- var entry = map.get(key);
7578
- if (entry && !entry.observable.hasObservers()) {
7579
- map.delete(key);
7894
+ if (result.data === this.result.data) {
7895
+ return;
7580
7896
  }
7581
- if (map.size === 0) {
7582
- this.queries.delete(query);
7897
+ this.result = result;
7898
+ this.promise = createFulfilledPromise(result);
7899
+ this.deliver(this.promise);
7900
+ };
7901
+ QueryReference.prototype.handleError = function (error) {
7902
+ var result = tslib.__assign(tslib.__assign({}, this.result), { error: error, networkStatus: exports.NetworkStatus.error });
7903
+ this.result = result;
7904
+ if (!this.initialized || this.refetching) {
7905
+ this.initialized = true;
7906
+ this.refetching = false;
7907
+ this.reject(error);
7908
+ return;
7583
7909
  }
7910
+ this.result = result;
7911
+ this.promise = result.data
7912
+ ? createFulfilledPromise(result)
7913
+ : createRejectedPromise(result);
7914
+ this.deliver(this.promise);
7584
7915
  };
7585
- SuspenseCache.prototype.getVariablesKey = function (variables) {
7586
- return canonicalStringify(variables || Object.create(null));
7916
+ QueryReference.prototype.deliver = function (promise) {
7917
+ this.listeners.forEach(function (listener) { return listener(promise); });
7918
+ };
7919
+ return QueryReference;
7920
+ }());
7921
+
7922
+ var SuspenseCache = (function () {
7923
+ function SuspenseCache(options) {
7924
+ if (options === void 0) { options = Object.create(null); }
7925
+ this.cacheKeys = new trie.Trie(canUseWeakMap, function (cacheKey) { return cacheKey; });
7926
+ this.queryRefs = new Map();
7927
+ this.options = options;
7928
+ }
7929
+ SuspenseCache.prototype.getQueryRef = function (cacheKey, createObservable) {
7930
+ var _this = this;
7931
+ var stableCacheKey = this.cacheKeys.lookupArray(cacheKey);
7932
+ if (!this.queryRefs.has(stableCacheKey)) {
7933
+ this.queryRefs.set(stableCacheKey, new QueryReference(createObservable(), {
7934
+ key: stableCacheKey,
7935
+ autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,
7936
+ onDispose: function () { return _this.queryRefs.delete(stableCacheKey); },
7937
+ }));
7938
+ }
7939
+ return this.queryRefs.get(stableCacheKey);
7587
7940
  };
7588
7941
  return SuspenseCache;
7589
7942
  }());
@@ -7601,6 +7954,7 @@ exports.ApolloConsumer = ApolloConsumer;
7601
7954
  exports.ApolloError = ApolloError;
7602
7955
  exports.ApolloLink = ApolloLink;
7603
7956
  exports.ApolloProvider = ApolloProvider;
7957
+ exports.DocumentTransform = DocumentTransform;
7604
7958
  exports.HttpLink = HttpLink;
7605
7959
  exports.InMemoryCache = InMemoryCache;
7606
7960
  exports.MissingFieldError = MissingFieldError;
@@ -7620,6 +7974,7 @@ exports.fromError = fromError;
7620
7974
  exports.fromPromise = fromPromise;
7621
7975
  exports.getApolloContext = getApolloContext;
7622
7976
  exports.isApolloError = isApolloError;
7977
+ exports.isNetworkRequestSettled = isNetworkRequestSettled;
7623
7978
  exports.isReference = isReference;
7624
7979
  exports.makeReference = makeReference;
7625
7980
  exports.makeVar = makeVar;
@@ -7627,7 +7982,7 @@ exports.mergeOptions = mergeOptions;
7627
7982
  exports.operationName = operationName;
7628
7983
  exports.parseAndCheckHttpResponse = parseAndCheckHttpResponse;
7629
7984
  exports.parser = parser;
7630
- exports.resetApolloContext = getApolloContext;
7985
+ exports.resetApolloContext = resetApolloContext;
7631
7986
  exports.rewriteURIForGET = rewriteURIForGET;
7632
7987
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
7633
7988
  exports.selectHttpOptionsAndBodyInternal = selectHttpOptionsAndBodyInternal;
@@ -7637,11 +7992,13 @@ exports.split = split;
7637
7992
  exports.throwServerError = throwServerError;
7638
7993
  exports.toPromise = toPromise;
7639
7994
  exports.useApolloClient = useApolloClient;
7640
- exports.useFragment_experimental = useFragment_experimental;
7995
+ exports.useBackgroundQuery = useBackgroundQuery;
7996
+ exports.useFragment = useFragment;
7641
7997
  exports.useLazyQuery = useLazyQuery;
7642
7998
  exports.useMutation = useMutation;
7643
7999
  exports.useQuery = useQuery;
7644
8000
  exports.useReactiveVar = useReactiveVar;
8001
+ exports.useReadQuery = useReadQuery;
7645
8002
  exports.useSubscription = useSubscription;
7646
- exports.useSuspenseQuery_experimental = useSuspenseQuery_experimental;
8003
+ exports.useSuspenseQuery = useSuspenseQuery;
7647
8004
  //# sourceMappingURL=apollo-client.cjs.map