@apollo/client 4.3.0-alpha.1 → 4.3.0-alpha.11

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 (416) hide show
  1. package/CHANGELOG.md +503 -0
  2. package/README.md +3 -7
  3. package/__cjs/cache/core/Scalar.cjs +36 -0
  4. package/__cjs/cache/core/Scalar.cjs.map +1 -0
  5. package/__cjs/cache/core/Scalar.d.cts +19 -0
  6. package/__cjs/cache/core/cache.cjs +32 -1
  7. package/__cjs/cache/core/cache.cjs.map +1 -1
  8. package/__cjs/cache/core/cache.d.cts +89 -6
  9. package/__cjs/cache/core/types/Cache.d.cts +25 -0
  10. package/__cjs/cache/index.cjs +3 -1
  11. package/__cjs/cache/index.cjs.map +1 -1
  12. package/__cjs/cache/index.d.cts +3 -2
  13. package/__cjs/cache/inmemory/entityStore.cjs +48 -5
  14. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  15. package/__cjs/cache/inmemory/entityStore.d.cts +3 -0
  16. package/__cjs/cache/inmemory/helpers.d.cts +9 -1
  17. package/__cjs/cache/inmemory/inMemoryCache.cjs +83 -4
  18. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  19. package/__cjs/cache/inmemory/inMemoryCache.d.cts +44 -5
  20. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  21. package/__cjs/cache/inmemory/policies.cjs +35 -6
  22. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  23. package/__cjs/cache/inmemory/policies.d.cts +4 -1
  24. package/__cjs/cache/inmemory/readFromStore.cjs +490 -49
  25. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  26. package/__cjs/cache/inmemory/readFromStore.d.cts +11 -2
  27. package/__cjs/cache/inmemory/types.d.cts +29 -4
  28. package/__cjs/cache/inmemory/writeToStore.cjs +6 -6
  29. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  30. package/__cjs/core/ApolloClient.cjs +37 -38
  31. package/__cjs/core/ApolloClient.cjs.map +1 -1
  32. package/__cjs/core/ApolloClient.d.cts +44 -10
  33. package/__cjs/core/ObservableQuery.cjs +228 -76
  34. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  35. package/__cjs/core/ObservableQuery.d.cts +16 -8
  36. package/__cjs/core/QueryInfo.cjs +178 -190
  37. package/__cjs/core/QueryInfo.cjs.map +1 -1
  38. package/__cjs/core/QueryInfo.d.cts +16 -21
  39. package/__cjs/core/QueryManager.cjs +88 -59
  40. package/__cjs/core/QueryManager.cjs.map +1 -1
  41. package/__cjs/core/QueryManager.d.cts +1 -3
  42. package/__cjs/core/RefetchEventManager.cjs +3 -3
  43. package/__cjs/core/dataStateErrorCache.cjs +12 -0
  44. package/__cjs/core/dataStateErrorCache.cjs.map +1 -0
  45. package/__cjs/core/dataStateErrorCache.d.cts +3 -0
  46. package/__cjs/core/index.cjs +2 -1
  47. package/__cjs/core/index.cjs.map +1 -1
  48. package/__cjs/core/index.d.cts +4 -3
  49. package/__cjs/core/types.d.cts +10 -3
  50. package/__cjs/incremental/GraphQLCodegenIncremental.cjs +3 -0
  51. package/__cjs/incremental/GraphQLCodegenIncremental.cjs.map +1 -0
  52. package/__cjs/incremental/GraphQLCodegenIncremental.d.cts +55 -0
  53. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  54. package/__cjs/incremental/handlers/defer20220824.d.cts +2 -4
  55. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +47 -16
  56. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  57. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +29 -6
  58. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  59. package/__cjs/incremental/index.cjs.map +1 -1
  60. package/__cjs/incremental/index.d.cts +1 -0
  61. package/__cjs/{utilities/internal/types/NoInfer.cjs → incremental/internal/types.cjs} +1 -1
  62. package/__cjs/incremental/internal/types.cjs.map +1 -0
  63. package/__cjs/incremental/internal/types.d.cts +17 -0
  64. package/__cjs/incremental/types.d.cts +55 -4
  65. package/__cjs/invariantErrorCodes.cjs +167 -112
  66. package/__cjs/link/core/ApolloLink.cjs +3 -3
  67. package/__cjs/link/http/checkFetcher.cjs +1 -1
  68. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +2 -2
  69. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  70. package/__cjs/link/persisted-queries/index.cjs +2 -2
  71. package/__cjs/link/ws/index.cjs +1 -1
  72. package/__cjs/local-state/LocalState.cjs +11 -11
  73. package/__cjs/local-state/LocalState.cjs.map +1 -1
  74. package/__cjs/local-state/LocalState.d.cts +1 -1
  75. package/__cjs/masking/internal/types.d.cts +1 -2
  76. package/__cjs/masking/maskDefinition.cjs +2 -2
  77. package/__cjs/masking/maskFragment.cjs +2 -2
  78. package/__cjs/masking/maskOperation.cjs +1 -1
  79. package/__cjs/masking/utils.cjs +3 -3
  80. package/__cjs/react/context/ApolloContext.cjs +1 -1
  81. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  82. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
  83. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  84. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  85. package/__cjs/react/hooks/useBackgroundQuery.d.cts +100 -47
  86. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  87. package/__cjs/react/hooks/useFragment.d.cts +0 -1
  88. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  89. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  90. package/__cjs/react/hooks/useLazyQuery.d.cts +40 -34
  91. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  92. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  93. package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
  94. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  95. package/__cjs/react/hooks/useMutation.d.cts +10 -7
  96. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  97. package/__cjs/react/hooks/useQuery.d.cts +74 -32
  98. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  99. package/__cjs/react/hooks/useSubscription.cjs +7 -3
  100. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  101. package/__cjs/react/hooks/useSubscription.d.cts +7 -4
  102. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  103. package/__cjs/react/hooks/useSuspenseFragment.d.cts +1 -1
  104. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  105. package/__cjs/react/hooks/useSuspenseQuery.d.cts +83 -34
  106. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  107. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  108. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  109. package/__cjs/react/internal/types.d.cts +14 -3
  110. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  111. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
  112. package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
  113. package/__cjs/testing/core/mocking/mockLink.cjs +25 -5
  114. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  115. package/__cjs/testing/core/mocking/mockLink.d.cts +1 -2
  116. package/__cjs/utilities/caching/sizes.cjs.map +1 -1
  117. package/__cjs/utilities/caching/sizes.d.cts +39 -1
  118. package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
  119. package/__cjs/utilities/index.cjs.map +1 -1
  120. package/__cjs/utilities/index.d.cts +1 -0
  121. package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
  122. package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
  123. package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
  124. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs +33 -0
  125. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs.map +1 -0
  126. package/__cjs/utilities/internal/addDeferFragmentLabels.d.cts +3 -0
  127. package/__cjs/utilities/internal/capitalize.cjs +12 -0
  128. package/__cjs/utilities/internal/capitalize.cjs.map +1 -0
  129. package/__cjs/utilities/internal/capitalize.d.cts +7 -0
  130. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs +69 -0
  131. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs.map +1 -0
  132. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.d.cts +9 -0
  133. package/__cjs/utilities/internal/constants.cjs +20 -1
  134. package/__cjs/utilities/internal/constants.cjs.map +1 -1
  135. package/__cjs/utilities/internal/constants.d.cts +19 -0
  136. package/__cjs/utilities/internal/getDirectiveArgValue.cjs +19 -0
  137. package/__cjs/utilities/internal/getDirectiveArgValue.cjs.map +1 -0
  138. package/__cjs/utilities/internal/getDirectiveArgValue.d.cts +9 -0
  139. package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
  140. package/__cjs/utilities/internal/getFragmentFromSelection.cjs +2 -2
  141. package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
  142. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +2 -2
  143. package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
  144. package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
  145. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  146. package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
  147. package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
  148. package/__cjs/utilities/internal/getUnwrappedType.cjs +20 -0
  149. package/__cjs/utilities/internal/getUnwrappedType.cjs.map +1 -0
  150. package/__cjs/utilities/internal/getUnwrappedType.d.cts +8 -0
  151. package/__cjs/utilities/internal/index.cjs +25 -2
  152. package/__cjs/utilities/internal/index.cjs.map +1 -1
  153. package/__cjs/utilities/internal/index.d.cts +16 -2
  154. package/__cjs/utilities/internal/isDeferredFragment.cjs +38 -0
  155. package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -0
  156. package/__cjs/utilities/internal/isDeferredFragment.d.cts +9 -0
  157. package/__cjs/utilities/internal/isStreamField.cjs +37 -0
  158. package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
  159. package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
  160. package/__cjs/utilities/internal/isTypenameField.cjs +7 -0
  161. package/__cjs/utilities/internal/isTypenameField.cjs.map +1 -0
  162. package/__cjs/utilities/internal/isTypenameField.d.cts +3 -0
  163. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
  164. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
  165. package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
  166. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
  167. package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
  168. package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
  169. package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
  170. package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
  171. package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
  172. package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
  173. package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
  174. package/__cjs/utilities/internal/types/Exact.cjs +3 -0
  175. package/__cjs/utilities/internal/types/Exact.cjs.map +1 -0
  176. package/__cjs/utilities/internal/types/Exact.d.cts +2 -0
  177. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs +3 -0
  178. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs.map +1 -0
  179. package/__cjs/utilities/internal/types/IsLooselyEqual.d.cts +10 -0
  180. package/__cjs/utilities/internal/types/IsNeverish.cjs +3 -0
  181. package/__cjs/utilities/internal/types/IsNeverish.cjs.map +1 -0
  182. package/__cjs/utilities/internal/types/IsNeverish.d.cts +4 -0
  183. package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
  184. package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
  185. package/__cjs/utilities/policies/pagination.cjs.map +1 -1
  186. package/__cjs/utilities/policies/pagination.d.cts +1 -1
  187. package/__cjs/utilities/subscriptions/relay/index.cjs +1 -0
  188. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  189. package/__cjs/version.cjs +1 -1
  190. package/__cjs/version.cjs.map +1 -1
  191. package/cache/core/Scalar.d.ts +19 -0
  192. package/cache/core/Scalar.js +32 -0
  193. package/cache/core/Scalar.js.map +1 -0
  194. package/cache/core/cache.d.ts +89 -6
  195. package/cache/core/cache.js +33 -2
  196. package/cache/core/cache.js.map +1 -1
  197. package/cache/core/types/Cache.d.ts +25 -0
  198. package/cache/core/types/Cache.js.map +1 -1
  199. package/cache/index.d.ts +3 -2
  200. package/cache/index.js +1 -0
  201. package/cache/index.js.map +1 -1
  202. package/cache/inmemory/entityStore.d.ts +3 -0
  203. package/cache/inmemory/entityStore.js +49 -6
  204. package/cache/inmemory/entityStore.js.map +1 -1
  205. package/cache/inmemory/helpers.d.ts +9 -1
  206. package/cache/inmemory/inMemoryCache.d.ts +44 -5
  207. package/cache/inmemory/inMemoryCache.js +84 -5
  208. package/cache/inmemory/inMemoryCache.js.map +1 -1
  209. package/cache/inmemory/key-extractor.js +1 -1
  210. package/cache/inmemory/policies.d.ts +4 -1
  211. package/cache/inmemory/policies.js +35 -6
  212. package/cache/inmemory/policies.js.map +1 -1
  213. package/cache/inmemory/readFromStore.d.ts +11 -2
  214. package/cache/inmemory/readFromStore.js +486 -49
  215. package/cache/inmemory/readFromStore.js.map +1 -1
  216. package/cache/inmemory/types.d.ts +30 -5
  217. package/cache/inmemory/types.js.map +1 -1
  218. package/cache/inmemory/writeToStore.js +7 -7
  219. package/cache/inmemory/writeToStore.js.map +1 -1
  220. package/core/ApolloClient.d.ts +44 -10
  221. package/core/ApolloClient.js +37 -38
  222. package/core/ApolloClient.js.map +1 -1
  223. package/core/ObservableQuery.d.ts +16 -8
  224. package/core/ObservableQuery.js +225 -77
  225. package/core/ObservableQuery.js.map +1 -1
  226. package/core/QueryInfo.d.ts +17 -22
  227. package/core/QueryInfo.js +174 -190
  228. package/core/QueryInfo.js.map +1 -1
  229. package/core/QueryManager.d.ts +1 -3
  230. package/core/QueryManager.js +89 -60
  231. package/core/QueryManager.js.map +1 -1
  232. package/core/RefetchEventManager.js +3 -3
  233. package/core/dataStateErrorCache.d.ts +3 -0
  234. package/core/dataStateErrorCache.js +9 -0
  235. package/core/dataStateErrorCache.js.map +1 -0
  236. package/core/index.d.ts +4 -3
  237. package/core/index.js +1 -1
  238. package/core/index.js.map +1 -1
  239. package/core/types.d.ts +10 -3
  240. package/core/types.js.map +1 -1
  241. package/incremental/GraphQLCodegenIncremental.d.ts +55 -0
  242. package/incremental/GraphQLCodegenIncremental.js +2 -0
  243. package/incremental/GraphQLCodegenIncremental.js.map +1 -0
  244. package/incremental/handlers/defer20220824.d.ts +2 -4
  245. package/incremental/handlers/defer20220824.js.map +1 -1
  246. package/incremental/handlers/graphql17Alpha9.d.ts +29 -6
  247. package/incremental/handlers/graphql17Alpha9.js +48 -17
  248. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  249. package/incremental/handlers/notImplemented.js +1 -1
  250. package/incremental/index.d.ts +1 -0
  251. package/incremental/index.js.map +1 -1
  252. package/incremental/internal/types.d.ts +17 -0
  253. package/incremental/internal/types.js +2 -0
  254. package/incremental/internal/types.js.map +1 -0
  255. package/incremental/types.d.ts +55 -4
  256. package/incremental/types.js.map +1 -1
  257. package/invariantErrorCodes.js +167 -112
  258. package/link/core/ApolloLink.js +3 -3
  259. package/link/http/checkFetcher.js +1 -1
  260. package/link/http/parseAndCheckHttpResponse.js +2 -2
  261. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  262. package/link/persisted-queries/index.js +2 -2
  263. package/link/ws/index.js +1 -1
  264. package/local-state/LocalState.d.ts +1 -1
  265. package/local-state/LocalState.js +11 -11
  266. package/local-state/LocalState.js.map +1 -1
  267. package/masking/internal/types.d.ts +1 -2
  268. package/masking/internal/types.js.map +1 -1
  269. package/masking/maskDefinition.js +2 -2
  270. package/masking/maskFragment.js +2 -2
  271. package/masking/maskOperation.js +1 -1
  272. package/masking/utils.js +3 -3
  273. package/package.json +1 -1
  274. package/react/context/ApolloContext.js +1 -1
  275. package/react/context/ApolloProvider.js +1 -1
  276. package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
  277. package/react/hooks/useApolloClient.js +1 -1
  278. package/react/hooks/useBackgroundQuery.d.ts +100 -47
  279. package/react/hooks/useBackgroundQuery.js.map +1 -1
  280. package/react/hooks/useFragment.d.ts +0 -1
  281. package/react/hooks/useFragment.js.map +1 -1
  282. package/react/hooks/useLazyQuery.d.ts +40 -34
  283. package/react/hooks/useLazyQuery.js +2 -2
  284. package/react/hooks/useLazyQuery.js.map +1 -1
  285. package/react/hooks/useLoadableQuery.d.ts +23 -15
  286. package/react/hooks/useLoadableQuery.js +2 -2
  287. package/react/hooks/useLoadableQuery.js.map +1 -1
  288. package/react/hooks/useMutation.d.ts +10 -7
  289. package/react/hooks/useMutation.js.map +1 -1
  290. package/react/hooks/useQuery.d.ts +74 -32
  291. package/react/hooks/useQuery.js.map +1 -1
  292. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  293. package/react/hooks/useSubscription.d.ts +7 -4
  294. package/react/hooks/useSubscription.js +7 -3
  295. package/react/hooks/useSubscription.js.map +1 -1
  296. package/react/hooks/useSuspenseFragment.d.ts +1 -1
  297. package/react/hooks/useSuspenseFragment.js.map +1 -1
  298. package/react/hooks/useSuspenseQuery.d.ts +83 -34
  299. package/react/hooks/useSuspenseQuery.js.map +1 -1
  300. package/react/hooks/useSyncExternalStore.js +1 -1
  301. package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
  302. package/react/hooks-compiled/useApolloClient.js +1 -1
  303. package/react/hooks-compiled/useBackgroundQuery.d.ts +100 -47
  304. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  305. package/react/hooks-compiled/useFragment.d.ts +0 -1
  306. package/react/hooks-compiled/useFragment.js.map +1 -1
  307. package/react/hooks-compiled/useLazyQuery.d.ts +40 -34
  308. package/react/hooks-compiled/useLazyQuery.js +2 -2
  309. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  310. package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
  311. package/react/hooks-compiled/useLoadableQuery.js +2 -2
  312. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  313. package/react/hooks-compiled/useMutation.d.ts +10 -7
  314. package/react/hooks-compiled/useMutation.js.map +1 -1
  315. package/react/hooks-compiled/useQuery.d.ts +74 -32
  316. package/react/hooks-compiled/useQuery.js.map +1 -1
  317. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  318. package/react/hooks-compiled/useSubscription.d.ts +7 -4
  319. package/react/hooks-compiled/useSubscription.js +107 -93
  320. package/react/hooks-compiled/useSubscription.js.map +1 -1
  321. package/react/hooks-compiled/useSuspenseFragment.d.ts +1 -1
  322. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  323. package/react/hooks-compiled/useSuspenseQuery.d.ts +83 -34
  324. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  325. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  326. package/react/internal/cache/QueryReference.js +1 -1
  327. package/react/internal/cache/QueryReference.js.map +1 -1
  328. package/react/internal/types.d.ts +15 -4
  329. package/react/internal/types.js.map +1 -1
  330. package/react/query-preloader/createQueryPreloader.d.ts +20 -5
  331. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  332. package/react/ssr/prerenderStatic.js +2 -2
  333. package/testing/core/mocking/mockLink.d.ts +1 -2
  334. package/testing/core/mocking/mockLink.js +25 -5
  335. package/testing/core/mocking/mockLink.js.map +1 -1
  336. package/utilities/caching/sizes.d.ts +39 -1
  337. package/utilities/caching/sizes.js.map +1 -1
  338. package/utilities/graphql/DocumentTransform.js +1 -1
  339. package/utilities/index.d.ts +1 -0
  340. package/utilities/index.js.map +1 -1
  341. package/utilities/internal/StreamArrayState.d.ts +12 -0
  342. package/utilities/internal/StreamArrayState.js +23 -0
  343. package/utilities/internal/StreamArrayState.js.map +1 -0
  344. package/utilities/internal/addDeferFragmentLabels.d.ts +3 -0
  345. package/utilities/internal/addDeferFragmentLabels.js +30 -0
  346. package/utilities/internal/addDeferFragmentLabels.js.map +1 -0
  347. package/utilities/internal/capitalize.d.ts +7 -0
  348. package/utilities/internal/capitalize.js +9 -0
  349. package/utilities/internal/capitalize.js.map +1 -0
  350. package/utilities/internal/coerceScalarFieldsToParsed.d.ts +9 -0
  351. package/utilities/internal/coerceScalarFieldsToParsed.js +66 -0
  352. package/utilities/internal/coerceScalarFieldsToParsed.js.map +1 -0
  353. package/utilities/internal/constants.d.ts +19 -0
  354. package/utilities/internal/constants.js +19 -0
  355. package/utilities/internal/constants.js.map +1 -1
  356. package/utilities/internal/getDirectiveArgValue.d.ts +9 -0
  357. package/utilities/internal/getDirectiveArgValue.js +16 -0
  358. package/utilities/internal/getDirectiveArgValue.js.map +1 -0
  359. package/utilities/internal/getFragmentDefinition.js +3 -3
  360. package/utilities/internal/getFragmentFromSelection.js +2 -2
  361. package/utilities/internal/getFragmentFromSelection.js.map +1 -1
  362. package/utilities/internal/getFragmentQueryDocument.js +2 -2
  363. package/utilities/internal/getMainDefinition.js +1 -1
  364. package/utilities/internal/getMemoryInternals.d.ts +4 -0
  365. package/utilities/internal/getMemoryInternals.js +6 -0
  366. package/utilities/internal/getMemoryInternals.js.map +1 -1
  367. package/utilities/internal/getQueryDefinition.js +1 -1
  368. package/utilities/internal/getUnwrappedType.d.ts +8 -0
  369. package/utilities/internal/getUnwrappedType.js +17 -0
  370. package/utilities/internal/getUnwrappedType.js.map +1 -0
  371. package/utilities/internal/index.d.ts +16 -2
  372. package/utilities/internal/index.js +12 -1
  373. package/utilities/internal/index.js.map +1 -1
  374. package/utilities/internal/isDeferredFragment.d.ts +9 -0
  375. package/utilities/internal/isDeferredFragment.js +35 -0
  376. package/utilities/internal/isDeferredFragment.js.map +1 -0
  377. package/utilities/internal/isStreamField.d.ts +9 -0
  378. package/utilities/internal/isStreamField.js +34 -0
  379. package/utilities/internal/isStreamField.js.map +1 -0
  380. package/utilities/internal/isTypenameField.d.ts +3 -0
  381. package/utilities/internal/isTypenameField.js +4 -0
  382. package/utilities/internal/isTypenameField.js.map +1 -0
  383. package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
  384. package/utilities/internal/makeStreamInfoTrie.js +14 -0
  385. package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
  386. package/utilities/internal/removeDirectivesFromDocument.js +1 -1
  387. package/utilities/internal/shouldInclude.js +4 -4
  388. package/utilities/internal/toDiffWithDataState.d.ts +8 -0
  389. package/utilities/internal/toDiffWithDataState.js +17 -0
  390. package/utilities/internal/toDiffWithDataState.js.map +1 -0
  391. package/utilities/internal/types/DeferInfo.d.ts +10 -0
  392. package/utilities/internal/types/DeferInfo.js +2 -0
  393. package/utilities/internal/types/DeferInfo.js.map +1 -0
  394. package/utilities/internal/types/Exact.d.ts +2 -0
  395. package/utilities/internal/types/Exact.js +2 -0
  396. package/utilities/internal/types/Exact.js.map +1 -0
  397. package/utilities/internal/types/IsLooselyEqual.d.ts +10 -0
  398. package/utilities/internal/types/IsLooselyEqual.js +2 -0
  399. package/utilities/internal/types/IsLooselyEqual.js.map +1 -0
  400. package/utilities/internal/types/IsNeverish.d.ts +4 -0
  401. package/utilities/internal/types/IsNeverish.js +2 -0
  402. package/utilities/internal/types/IsNeverish.js.map +1 -0
  403. package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
  404. package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
  405. package/utilities/internal/valueToObjectRepresentation.js +1 -1
  406. package/utilities/policies/pagination.d.ts +1 -1
  407. package/utilities/policies/pagination.js.map +1 -1
  408. package/utilities/subscriptions/relay/index.js +1 -0
  409. package/utilities/subscriptions/relay/index.js.map +1 -1
  410. package/version.js +1 -1
  411. package/version.js.map +1 -1
  412. package/__cjs/utilities/internal/types/NoInfer.cjs.map +0 -1
  413. package/__cjs/utilities/internal/types/NoInfer.d.cts +0 -35
  414. package/utilities/internal/types/NoInfer.d.ts +0 -35
  415. package/utilities/internal/types/NoInfer.js +0 -2
  416. package/utilities/internal/types/NoInfer.js.map +0 -1
@@ -278,12 +278,8 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
278
278
  readonly options: ObservableQuery.Options<TData, TVariables>;
279
279
  readonly queryName?: string;
280
280
  private variablesUnknown;
281
- /**
282
- * @internal will be read and written from `QueryInfo`
283
- *
284
- * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
285
- */
286
- _lastWrite?: unknown;
281
+ private didWarnOnFeud;
282
+ private lastMissing?;
287
283
  get query(): TypedDocumentNode<TData, TVariables>;
288
284
  /**
289
285
  * An object containing the variables that were provided for the query.
@@ -349,7 +345,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
349
345
  */
350
346
  getCacheDiff({ optimistic }?: {
351
347
  optimistic?: boolean | undefined;
352
- }): Cache.DiffResult<TData>;
348
+ }): Cache.InternalDiffResultWithDataState<TData>;
353
349
  private getInitialResult;
354
350
  private resubscribeCache;
355
351
  private stableLastResult?;
@@ -372,7 +368,18 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
372
368
  /**
373
369
  * A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
374
370
  */
375
- fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>): Promise<ApolloClient.QueryResult<TFetchData>>;
371
+ fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables, TErrorPolicy extends ErrorPolicy = "none">(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars> & {
372
+ /**
373
+ * Specifies how the query handles a response that returns both GraphQL errors and partial results.
374
+ *
375
+ * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
376
+ *
377
+ * The default value is `none`, meaning that the query result includes error details but not partial results.
378
+ *
379
+ * @docGroup 1. Operation options
380
+ */
381
+ errorPolicy?: TErrorPolicy;
382
+ }): Promise<ApolloClient.QueryResult<TFetchData, TErrorPolicy>>;
376
383
  /**
377
384
  * A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
378
385
  *
@@ -458,6 +465,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
458
465
  * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
459
466
  */
460
467
  notify(scheduled?: boolean): void;
468
+ private deliverCacheDiff;
461
469
  private activeOperations;
462
470
  private pushOperation;
463
471
  private calculateNetworkStatus;
@@ -2,8 +2,9 @@ import { equal } from "@wry/equality";
2
2
  import { BehaviorSubject, filter, Observable, share, Subject, tap } from "rxjs";
3
3
  import { isNetworkRequestInFlight, isNetworkRequestSettled, } from "@apollo/client/utilities";
4
4
  import { __DEV__ } from "@apollo/client/utilities/environment";
5
- import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
5
+ import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, handleIncrementalSymbol, preventUnhandledRejection, toDiffWithDataState, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
6
6
  import { invariant } from "@apollo/client/utilities/invariant";
7
+ import { dataStateErrorCache } from "./dataStateErrorCache.js";
7
8
  import { NetworkStatus } from "./networkStatus.js";
8
9
  const { assign, hasOwnProperty } = Object;
9
10
  const uninitialized = {
@@ -20,16 +21,29 @@ const empty = {
20
21
  dataState: "empty",
21
22
  partial: true,
22
23
  };
24
+ const destructiveMethodCounts = new WeakMap();
25
+ function wrapDestructiveCacheMethod(cache, methodName) {
26
+ const original = cache[methodName];
27
+ if (typeof original === "function") {
28
+ // @ts-expect-error this is just too generic to be typed correctly
29
+ cache[methodName] = function () {
30
+ destructiveMethodCounts.set(cache,
31
+ // The %1e15 allows the count to wrap around to 0 safely every
32
+ // quadrillion evictions, so there's no risk of overflow. To be
33
+ // clear, this is more of a pedantic principle than something
34
+ // that matters in any conceivable practical scenario.
35
+ (destructiveMethodCounts.get(cache) + 1) % 1e15);
36
+ // @ts-expect-error this is just too generic to be typed correctly
37
+ return original.apply(this, arguments);
38
+ };
39
+ }
40
+ }
23
41
  export class ObservableQuery {
24
42
  options;
25
43
  queryName;
26
44
  variablesUnknown = false;
27
- /**
28
- * @internal will be read and written from `QueryInfo`
29
- *
30
- * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
31
- */
32
- _lastWrite;
45
+ didWarnOnFeud = false;
46
+ lastMissing;
33
47
  // The `query` computed property will always reflect the document transformed
34
48
  // by the last run query. `this.options.query` will always reflect the raw
35
49
  // untransformed query to ensure document transforms with runtime conditionals
@@ -66,6 +80,18 @@ export class ObservableQuery {
66
80
  }
67
81
  constructor({ queryManager, options, transformedQuery = queryManager.transform(options.query), }) {
68
82
  this.queryManager = queryManager;
83
+ // Track how often destructive cache methods are called, since we want
84
+ // eviction to override the feud-stopping logic in `shouldAutoRefetch`,
85
+ // by causing it to return true. Wrapping these cache methods is a bit of a
86
+ // hack, but it saves us from having to make eviction counting an official
87
+ // part of the ApolloCache API.
88
+ const { cache } = queryManager;
89
+ if (!destructiveMethodCounts.has(cache)) {
90
+ destructiveMethodCounts.set(cache, 0);
91
+ wrapDestructiveCacheMethod(cache, "evict");
92
+ wrapDestructiveCacheMethod(cache, "modify");
93
+ wrapDestructiveCacheMethod(cache, "reset");
94
+ }
69
95
  // active state
70
96
  this.waitForNetworkResult = options.fetchPolicy === "network-only";
71
97
  this.isTornDown = false;
@@ -76,7 +102,7 @@ export class ObservableQuery {
76
102
  // Make sure we don't store "standby" as the initialFetchPolicy.
77
103
  initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
78
104
  if (options[variablesUnknownSymbol]) {
79
- invariant(fetchPolicy === "standby", 82);
105
+ invariant(fetchPolicy === "standby", 83);
80
106
  this.variablesUnknown = true;
81
107
  }
82
108
  this.lastQuery = transformedQuery;
@@ -205,12 +231,13 @@ export class ObservableQuery {
205
231
  * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
206
232
  */
207
233
  getCacheDiff({ optimistic = true } = {}) {
208
- return this.cache.diff({
234
+ return toDiffWithDataState(this.cache.diff({
209
235
  query: this.query,
210
236
  variables: this.variables,
211
237
  returnPartialData: true,
212
238
  optimistic,
213
- });
239
+ [handleIncrementalSymbol]: undefined,
240
+ }));
214
241
  }
215
242
  getInitialResult(initialFetchPolicy) {
216
243
  let fetchPolicy = initialFetchPolicy || this.options.fetchPolicy;
@@ -220,16 +247,18 @@ export class ObservableQuery {
220
247
  }
221
248
  const cacheResult = () => {
222
249
  const diff = this.getCacheDiff();
250
+ let { dataState } = diff;
223
251
  // TODO: queryInfo.getDiff should handle this since cache.diff returns a
224
252
  // null when returnPartialData is false
225
253
  const data = this.options.returnPartialData || diff.complete ?
226
254
  diff.result ?? undefined
227
255
  : undefined;
256
+ if (data === undefined) {
257
+ dataState = "empty";
258
+ }
228
259
  return this.maskResult({
229
260
  data,
230
- dataState: diff.complete ? "complete"
231
- : data === undefined ? "empty"
232
- : "partial",
261
+ dataState,
233
262
  loading: !diff.complete,
234
263
  networkStatus: diff.complete ? NetworkStatus.ready : NetworkStatus.loading,
235
264
  partial: !diff.complete,
@@ -382,7 +411,7 @@ export class ObservableQuery {
382
411
  const queryDef = getQueryDefinition(this.query);
383
412
  const vars = queryDef.variableDefinitions;
384
413
  if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
385
- __DEV__ && invariant.warn(83, variables, queryDef.name?.value || queryDef);
414
+ __DEV__ && invariant.warn(84, variables, queryDef.name?.value || queryDef);
386
415
  }
387
416
  }
388
417
  if (variables && !equal(this.variables, variables)) {
@@ -390,7 +419,6 @@ export class ObservableQuery {
390
419
  reobserveOptions.variables = this.options.variables =
391
420
  this.getVariablesWithDefaults({ ...this.variables, ...variables });
392
421
  }
393
- this._lastWrite = undefined;
394
422
  return this._reobserve(reobserveOptions, {
395
423
  newNetworkStatus: NetworkStatus.refetch,
396
424
  });
@@ -398,7 +426,7 @@ export class ObservableQuery {
398
426
  fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
399
427
  invariant(
400
428
  this.options.fetchPolicy !== "cache-only",
401
- 84,
429
+ 85,
402
430
  getOperationName(this.query, "(anonymous)")
403
431
  );
404
432
  const combinedOptions = {
@@ -432,7 +460,7 @@ export class ObservableQuery {
432
460
  let wasUpdated = false;
433
461
  const isCached = this.options.fetchPolicy !== "no-cache";
434
462
  if (!isCached) {
435
- invariant(updateQuery, 85);
463
+ invariant(updateQuery, 86);
436
464
  }
437
465
  const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
438
466
  pushNotification({
@@ -509,9 +537,7 @@ export class ObservableQuery {
509
537
  // will be overwritten anyways, just here for types sake
510
538
  loading: false,
511
539
  data: diff.result,
512
- dataState: fetchMoreResult.dataState === "streaming" ?
513
- "streaming"
514
- : "complete",
540
+ dataState: diff.complete ? "complete" : "streaming",
515
541
  },
516
542
  });
517
543
  }
@@ -608,7 +634,7 @@ export class ObservableQuery {
608
634
  onError(error);
609
635
  }
610
636
  else {
611
- invariant.error(86, error);
637
+ invariant.error(87, error);
612
638
  }
613
639
  return;
614
640
  }
@@ -859,7 +885,7 @@ export class ObservableQuery {
859
885
  if (!this.didWarnCacheOnlyPolling &&
860
886
  pollInterval &&
861
887
  fetchPolicy === "cache-only") {
862
- __DEV__ && invariant.warn(87, getOperationName(this.query, "(anonymous)"));
888
+ __DEV__ && invariant.warn(88, getOperationName(this.query, "(anonymous)"));
863
889
  this.didWarnCacheOnlyPolling = true;
864
890
  }
865
891
  }
@@ -925,7 +951,10 @@ export class ObservableQuery {
925
951
  }
926
952
  _reobserve(newOptions, internalOptions) {
927
953
  this.isTornDown = false;
928
- let { newNetworkStatus } = internalOptions || {};
954
+ let { newNetworkStatus, keepLastMissing } = internalOptions || {};
955
+ if (!keepLastMissing) {
956
+ this.lastMissing = undefined;
957
+ }
929
958
  this.queryManager.obsQueries.add(this);
930
959
  const useDisposableObservable =
931
960
  // Refetching uses a disposable Observable to allow refetches using different
@@ -1066,7 +1095,7 @@ export class ObservableQuery {
1066
1095
  this.queryManager.obsQueries.delete(this);
1067
1096
  this.isTornDown = true;
1068
1097
  this.abortActiveOperations();
1069
- this._lastWrite = undefined;
1098
+ this.lastMissing = undefined;
1070
1099
  }
1071
1100
  transformDocument(document) {
1072
1101
  return this.queryManager.transform(document);
@@ -1124,53 +1153,126 @@ export class ObservableQuery {
1124
1153
  return;
1125
1154
  }
1126
1155
  }
1127
- const { dirty } = this;
1156
+ const { dirty, lastMissing } = this;
1157
+ const { fetchPolicy } = this.options;
1128
1158
  this.resetNotifications();
1129
- if (dirty &&
1130
- (this.options.fetchPolicy === "cache-only" ||
1131
- this.options.fetchPolicy === "cache-and-network" ||
1132
- !this.activeOperations.size)) {
1133
- const diff = this.getCacheDiff();
1134
- if (
1135
- // `fromOptimisticTransaction` is not available through the `cache.diff`
1136
- // code path, so we need to check it this way
1137
- equal(diff.result, this.getCacheDiff({ optimistic: false }).result)) {
1138
- //If this diff did not come from an optimistic transaction
1139
- // make the ObservableQuery "reobserve" the latest data
1140
- // using a temporary fetch policy of "cache-first", so complete cache
1141
- // results have a chance to be delivered without triggering additional
1142
- // network requests, even when options.fetchPolicy is "network-only"
1143
- // or "cache-and-network". All other fetch policies are preserved by
1144
- // this method, and are handled by calling oq.reobserve(). If this
1145
- // reobservation is spurious, distinctUntilChanged still has a
1146
- // chance to catch it before delivery to ObservableQuery subscribers.
1147
- this.reobserveCacheFirst();
1159
+ if (!dirty ||
1160
+ (fetchPolicy !== "cache-only" &&
1161
+ fetchPolicy !== "cache-and-network" &&
1162
+ this.activeOperations.size)) {
1163
+ return;
1164
+ }
1165
+ const diff = this.getCacheDiff();
1166
+ const current = this.getCurrentResult();
1167
+ // `fromOptimisticTransaction` is not available through the `cache.diff`
1168
+ // code path, so we need to check whether the cache result is an optimistic
1169
+ // result this way.
1170
+ const isOptimistic = !equal(diff.result, this.getCacheDiff({ optimistic: false }).result);
1171
+ if (
1172
+ // When this diff came from an optimistic transaction, deliver the
1173
+ // current cache data to the ObservableQuery, but don't perform a
1174
+ // reobservation, since oq.reobserveCacheFirst might make a network
1175
+ // request, and we never want to trigger network requests in the
1176
+ // middle of optimistic updates.
1177
+ isOptimistic ||
1178
+ // If we get a cache update in the middle of streaming (possible with
1179
+ // cache-and-network fetch policy), just deliver the cache value without
1180
+ // going through the full reobserve which would otherwise trigger another
1181
+ // request (deduplication should kick in, but doing so replays any
1182
+ // previous emits from the link chain, which get rewritten into the cache
1183
+ // and might clobber this cache update)
1184
+ (!diff.complete && current.networkStatus === NetworkStatus.streaming)) {
1185
+ this.deliverCacheDiff(diff);
1186
+ return;
1187
+ }
1188
+ if (diff.complete) {
1189
+ this.lastMissing = undefined;
1190
+ }
1191
+ else if (!lastMissing ||
1192
+ // If a destructive cache method has been called since the last recorded
1193
+ // incomplete result, there's a chance fetching this data again will
1194
+ // restore what was evicted, even though the cache result looks the same
1195
+ // as before.
1196
+ lastMissing.dmCount !== destructiveMethodCounts.get(this.cache) ||
1197
+ !equal(lastMissing.variables, this.variables) ||
1198
+ !equal(lastMissing.missing, diff.missing?.missing)) {
1199
+ this.didWarnOnFeud = false;
1200
+ this.lastMissing = {
1201
+ variables: this.variables,
1202
+ missing: diff.missing?.missing,
1203
+ dmCount: destructiveMethodCounts.get(this.cache),
1204
+ };
1205
+ }
1206
+ else if (
1207
+ // reobserveCacheFirst with cache-only fetch policy only calls
1208
+ // reobserve which never fetches from the network so we are ok
1209
+ // allowing cache-only queries to fallthrough to reobserveCacheFirst.
1210
+ // This also prevents the feud warning which would be confusing for a
1211
+ // cache-only query anyways.
1212
+ fetchPolicy !== "cache-only") {
1213
+ // If we've fallen through to this case, a cache emit has returned the
1214
+ // same missing fields which means at least one value on the fields we've
1215
+ // already delivered have changed. We are ok delivering the updated
1216
+ // partial result in this case to keep the result as fresh as possible. We
1217
+ // NEVER want to downgrade this query from a complete query to a partial
1218
+ // query though, so we also make sure we only deliver if the previous
1219
+ // result was also partial.
1220
+ if (current.dataState === "partial") {
1221
+ this.deliverCacheDiff(diff);
1148
1222
  }
1149
- else {
1150
- // If this diff came from an optimistic transaction, deliver the
1151
- // current cache data to the ObservableQuery, but don't perform a
1152
- // reobservation, since oq.reobserveCacheFirst might make a network
1153
- // request, and we never want to trigger network requests in the
1154
- // middle of optimistic updates.
1155
- this.input.next({
1156
- kind: "N",
1157
- value: {
1158
- data: diff.result,
1159
- dataState: diff.complete ? "complete"
1160
- : diff.result ? "partial"
1161
- : "empty",
1162
- networkStatus: NetworkStatus.ready,
1163
- loading: false,
1164
- error: undefined,
1165
- partial: !diff.complete,
1166
- },
1167
- source: "cache",
1168
- query: this.query,
1169
- variables: this.variables,
1170
- meta: {},
1171
- });
1223
+ // If the (partial) result is the same as the last partial result
1224
+ // we recorded from a previous broadcast (and the variables match
1225
+ // too), avoid calling reobserveCacheFirst to refetch this query
1226
+ // again. If we allow refetching anytime this result becomes partial,
1227
+ // we risk feuds between queries competing to update the same data in
1228
+ // incompatible ways, which can lead to an endless cycle of cache
1229
+ // broadcasts and useless network requests. As with any
1230
+ // feud, eventually one side must step back from the brink,
1231
+ // letting the other side(s) have the last word(s). There may
1232
+ // be other points where we could break this cycle, such as
1233
+ // silencing the broadcast for cache.writeQuery (not a good
1234
+ // idea, since it just delays the feud a bit) or somehow
1235
+ // avoiding the network request that just happened (also bad,
1236
+ // because the server could return useful new data). All
1237
+ // options considered, returning early and stopping the
1238
+ // reobserveCacheFirst cycle seems to be the least damaging place to
1239
+ // break the cycle because it allows read functions/custom scalars to
1240
+ // be applied to the feuding query while avoiding the endless cycle of
1241
+ // requests.
1242
+ if (__DEV__ && !this.didWarnOnFeud) {
1243
+ this.didWarnOnFeud = true;
1244
+ warnOnFeud(this.query, diff);
1172
1245
  }
1246
+ return;
1173
1247
  }
1248
+ //If this diff did not come from an optimistic transaction
1249
+ // make the ObservableQuery "reobserve" the latest data
1250
+ // using a temporary fetch policy of "cache-first", so complete cache
1251
+ // results have a chance to be delivered without triggering additional
1252
+ // network requests, even when options.fetchPolicy is "network-only"
1253
+ // or "cache-and-network". All other fetch policies are preserved by
1254
+ // this method, and are handled by calling oq.reobserve(). If this
1255
+ // reobservation is spurious, distinctUntilChanged still has a
1256
+ // chance to catch it before delivery to ObservableQuery subscribers.
1257
+ this.reobserveCacheFirst();
1258
+ }
1259
+ deliverCacheDiff(diff) {
1260
+ const current = this.getCurrentResult();
1261
+ this.input.next({
1262
+ kind: "N",
1263
+ value: {
1264
+ data: diff.result,
1265
+ dataState: diff.dataState,
1266
+ networkStatus: current.networkStatus,
1267
+ loading: current.loading,
1268
+ error: undefined,
1269
+ partial: !diff.complete,
1270
+ },
1271
+ source: "cache",
1272
+ query: this.query,
1273
+ variables: this.variables,
1274
+ meta: {},
1275
+ });
1174
1276
  }
1175
1277
  activeOperations = new Set();
1176
1278
  pushOperation(networkStatus) {
@@ -1233,6 +1335,7 @@ export class ObservableQuery {
1233
1335
  // exception for cache-only queries - we reset them into a "ready" state
1234
1336
  // as we won't trigger a refetch for them
1235
1337
  const resetToEmpty = this.options.fetchPolicy === "cache-only";
1338
+ this.lastMissing = undefined;
1236
1339
  this.setResult(resetToEmpty ? empty : uninitialized, {
1237
1340
  shouldEmit: resetToEmpty ? 1 /* EmitBehavior.force */ : 2 /* EmitBehavior.never */,
1238
1341
  });
@@ -1254,19 +1357,55 @@ export class ObservableQuery {
1254
1357
  });
1255
1358
  }
1256
1359
  operator = filterMap((notification) => {
1257
- const { query, variables, meta } = notification;
1360
+ const { query, meta } = notification;
1258
1361
  if (notification.source === "setResult") {
1259
- return { query, variables, result: notification.value, meta };
1362
+ return {
1363
+ query,
1364
+ variables: this.variables,
1365
+ result: notification.value,
1366
+ meta,
1367
+ };
1368
+ }
1369
+ if (notification.kind === "C") {
1370
+ return;
1260
1371
  }
1261
- if (notification.kind === "C" || !isEqualQuery(notification, this)) {
1372
+ const resolvedVariables = "resolvedVariables" in notification ?
1373
+ notification.resolvedVariables
1374
+ : undefined;
1375
+ // Usually we prefer to drop notifications that don't match this query
1376
+ // but this breaks when used with `@export` queries that resolve variables
1377
+ // after the request is initiated. `notification.resolvedVariables` gives us
1378
+ // the variables the query actually resolved with during evaluation in
1379
+ // QueryManager (which is the variables value after `@export` variables have
1380
+ // been applied), but we need to update this query with those resolved
1381
+ // variables maybe in the middle of a request (updating is handled below).
1382
+ // When we update this.variables to the resolved variables, this causes
1383
+ // isEqualQuery(notification, this) to fail for future notifications since
1384
+ // the notification.variables holds the stale variables value. In this case,
1385
+ // we want to allow the notification through only if the current variables
1386
+ // value matches the resolved variables.
1387
+ //
1388
+ // Note: the check for matching resolved variables typically kicks in for
1389
+ // multi-emission fetches (such as defer, or cache-and-network, etc).
1390
+ if (notification.query !== this.query) {
1262
1391
  return;
1263
1392
  }
1393
+ if (!equal(resolvedVariables, this.variables)) {
1394
+ if (!equal(notification.variables, this.variables)) {
1395
+ return;
1396
+ }
1397
+ if (resolvedVariables) {
1398
+ this.options.variables = resolvedVariables;
1399
+ this.resubscribeCache();
1400
+ }
1401
+ }
1402
+ const variables = this.variables;
1264
1403
  let result;
1265
1404
  const previous = this.subject.getValue();
1266
1405
  if (notification.source === "cache") {
1267
1406
  result = notification.value;
1268
1407
  if (result.networkStatus === NetworkStatus.ready &&
1269
- result.partial &&
1408
+ result.dataState === "partial" &&
1270
1409
  (!this.options.returnPartialData ||
1271
1410
  previous.result.networkStatus === NetworkStatus.error) &&
1272
1411
  this.options.fetchPolicy !== "cache-only") {
@@ -1281,7 +1420,9 @@ export class ObservableQuery {
1281
1420
  result =
1282
1421
  notification.kind === "E" ?
1283
1422
  {
1284
- ...(isEqualQuery(previous, notification) ?
1423
+ ...((isEqualQuery(previous, notification) ||
1424
+ (resolvedVariables &&
1425
+ equal(resolvedVariables, previous.variables))) ?
1285
1426
  previous.result
1286
1427
  : { data: undefined, dataState: "empty", partial: true }),
1287
1428
  error: notification.error,
@@ -1290,7 +1431,8 @@ export class ObservableQuery {
1290
1431
  }
1291
1432
  : notification.value;
1292
1433
  if (notification.kind === "E" && result.dataState === "streaming") {
1293
- result.dataState = "complete";
1434
+ result.dataState =
1435
+ dataStateErrorCache.get(notification.error) ?? "complete";
1294
1436
  }
1295
1437
  if (result.error) {
1296
1438
  meta.shouldEmit = 1 /* EmitBehavior.force */;
@@ -1338,7 +1480,10 @@ export class ObservableQuery {
1338
1480
  reobserveCacheFirst() {
1339
1481
  const { fetchPolicy, nextFetchPolicy } = this.options;
1340
1482
  if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
1341
- this.reobserve({
1483
+ // Preserve this.lastMissing so a cache update that triggers this
1484
+ // reobserve doesn't reset feud detection. All user-initiated calls to
1485
+ // reobserve (refetch/poll/reobserve, etc) should clear it.
1486
+ this._reobserve({
1342
1487
  fetchPolicy: "cache-first",
1343
1488
  // Use a temporary nextFetchPolicy function that replaces itself with the
1344
1489
  // previous nextFetchPolicy value and returns the original fetchPolicy.
@@ -1354,10 +1499,10 @@ export class ObservableQuery {
1354
1499
  // Otherwise go back to the original this.options.fetchPolicy.
1355
1500
  return fetchPolicy;
1356
1501
  },
1357
- });
1502
+ }, { keepLastMissing: true });
1358
1503
  }
1359
1504
  else {
1360
- this.reobserve();
1505
+ this._reobserve(undefined, { keepLastMissing: true });
1361
1506
  }
1362
1507
  }
1363
1508
  getVariablesWithDefaults(variables) {
@@ -1366,7 +1511,7 @@ export class ObservableQuery {
1366
1511
  }
1367
1512
  export function logMissingFieldErrors(missing) {
1368
1513
  if (__DEV__ && missing) {
1369
- __DEV__ && invariant.debug(88, missing);
1514
+ __DEV__ && invariant.debug(89, missing);
1370
1515
  }
1371
1516
  }
1372
1517
  function isEqualQuery(a, b) {
@@ -1409,4 +1554,7 @@ function getTrackingOperatorPromise(defaultValue) {
1409
1554
  });
1410
1555
  return { promise, operator };
1411
1556
  }
1557
+ function warnOnFeud(query, diff) {
1558
+ __DEV__ && invariant.warn(90, getOperationName(query, "(anonymous)"), diff.missing?.missing);
1559
+ }
1412
1560
  //# sourceMappingURL=ObservableQuery.js.map