@apollo/client 4.3.0-alpha.0 → 4.3.0-alpha.10

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 (392) hide show
  1. package/CHANGELOG.md +490 -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 +20 -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 +17 -22
  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 +12 -6
  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/incremental/internal/types.cjs +3 -0
  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/masking/internal/types.d.cts +1 -2
  74. package/__cjs/masking/maskDefinition.cjs +2 -2
  75. package/__cjs/masking/maskFragment.cjs +2 -2
  76. package/__cjs/masking/maskOperation.cjs +1 -1
  77. package/__cjs/masking/utils.cjs +3 -3
  78. package/__cjs/react/context/ApolloContext.cjs +1 -1
  79. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  80. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
  81. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  82. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  83. package/__cjs/react/hooks/useBackgroundQuery.d.cts +100 -47
  84. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  85. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  86. package/__cjs/react/hooks/useLazyQuery.d.cts +39 -33
  87. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  88. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  89. package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
  90. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  91. package/__cjs/react/hooks/useMutation.d.cts +10 -7
  92. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  93. package/__cjs/react/hooks/useQuery.d.cts +74 -32
  94. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  95. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  96. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  97. package/__cjs/react/hooks/useSuspenseQuery.d.cts +83 -34
  98. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  99. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  100. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  101. package/__cjs/react/internal/types.d.cts +14 -3
  102. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  103. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
  104. package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
  105. package/__cjs/react/types/deprecated.d.cts +5 -4
  106. package/__cjs/testing/core/mocking/mockLink.cjs +25 -5
  107. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  108. package/__cjs/testing/core/mocking/mockLink.d.cts +1 -2
  109. package/__cjs/utilities/caching/sizes.cjs.map +1 -1
  110. package/__cjs/utilities/caching/sizes.d.cts +39 -1
  111. package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
  112. package/__cjs/utilities/index.cjs.map +1 -1
  113. package/__cjs/utilities/index.d.cts +1 -0
  114. package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
  115. package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
  116. package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
  117. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs +33 -0
  118. package/__cjs/utilities/internal/addDeferFragmentLabels.cjs.map +1 -0
  119. package/__cjs/utilities/internal/addDeferFragmentLabels.d.cts +3 -0
  120. package/__cjs/utilities/internal/capitalize.cjs +12 -0
  121. package/__cjs/utilities/internal/capitalize.cjs.map +1 -0
  122. package/__cjs/utilities/internal/capitalize.d.cts +7 -0
  123. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs +69 -0
  124. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs.map +1 -0
  125. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.d.cts +9 -0
  126. package/__cjs/utilities/internal/constants.cjs +20 -1
  127. package/__cjs/utilities/internal/constants.cjs.map +1 -1
  128. package/__cjs/utilities/internal/constants.d.cts +19 -0
  129. package/__cjs/utilities/internal/getDirectiveArgValue.cjs +19 -0
  130. package/__cjs/utilities/internal/getDirectiveArgValue.cjs.map +1 -0
  131. package/__cjs/utilities/internal/getDirectiveArgValue.d.cts +9 -0
  132. package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
  133. package/__cjs/utilities/internal/getFragmentFromSelection.cjs +2 -2
  134. package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
  135. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +2 -2
  136. package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
  137. package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
  138. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  139. package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
  140. package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
  141. package/__cjs/utilities/internal/getUnwrappedType.cjs +20 -0
  142. package/__cjs/utilities/internal/getUnwrappedType.cjs.map +1 -0
  143. package/__cjs/utilities/internal/getUnwrappedType.d.cts +8 -0
  144. package/__cjs/utilities/internal/index.cjs +25 -2
  145. package/__cjs/utilities/internal/index.cjs.map +1 -1
  146. package/__cjs/utilities/internal/index.d.cts +16 -1
  147. package/__cjs/utilities/internal/isDeferredFragment.cjs +38 -0
  148. package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -0
  149. package/__cjs/utilities/internal/isDeferredFragment.d.cts +9 -0
  150. package/__cjs/utilities/internal/isStreamField.cjs +37 -0
  151. package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
  152. package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
  153. package/__cjs/utilities/internal/isTypenameField.cjs +7 -0
  154. package/__cjs/utilities/internal/isTypenameField.cjs.map +1 -0
  155. package/__cjs/utilities/internal/isTypenameField.d.cts +3 -0
  156. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
  157. package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
  158. package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
  159. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
  160. package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
  161. package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
  162. package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
  163. package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
  164. package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
  165. package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
  166. package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
  167. package/__cjs/utilities/internal/types/Exact.cjs +3 -0
  168. package/__cjs/utilities/internal/types/Exact.cjs.map +1 -0
  169. package/__cjs/utilities/internal/types/Exact.d.cts +2 -0
  170. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs +3 -0
  171. package/__cjs/utilities/internal/types/IsLooselyEqual.cjs.map +1 -0
  172. package/__cjs/utilities/internal/types/IsLooselyEqual.d.cts +10 -0
  173. package/__cjs/utilities/internal/types/IsNeverish.cjs +3 -0
  174. package/__cjs/utilities/internal/types/IsNeverish.cjs.map +1 -0
  175. package/__cjs/utilities/internal/types/IsNeverish.d.cts +4 -0
  176. package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
  177. package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
  178. package/__cjs/utilities/policies/pagination.cjs.map +1 -1
  179. package/__cjs/utilities/policies/pagination.d.cts +1 -1
  180. package/__cjs/utilities/subscriptions/relay/index.cjs +1 -0
  181. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  182. package/__cjs/version.cjs +1 -1
  183. package/__cjs/version.cjs.map +1 -1
  184. package/cache/core/Scalar.d.ts +20 -0
  185. package/cache/core/Scalar.js +32 -0
  186. package/cache/core/Scalar.js.map +1 -0
  187. package/cache/core/cache.d.ts +89 -6
  188. package/cache/core/cache.js +33 -2
  189. package/cache/core/cache.js.map +1 -1
  190. package/cache/core/types/Cache.d.ts +25 -0
  191. package/cache/core/types/Cache.js.map +1 -1
  192. package/cache/index.d.ts +3 -2
  193. package/cache/index.js +1 -0
  194. package/cache/index.js.map +1 -1
  195. package/cache/inmemory/entityStore.d.ts +3 -0
  196. package/cache/inmemory/entityStore.js +49 -6
  197. package/cache/inmemory/entityStore.js.map +1 -1
  198. package/cache/inmemory/helpers.d.ts +9 -1
  199. package/cache/inmemory/inMemoryCache.d.ts +44 -5
  200. package/cache/inmemory/inMemoryCache.js +84 -5
  201. package/cache/inmemory/inMemoryCache.js.map +1 -1
  202. package/cache/inmemory/key-extractor.js +1 -1
  203. package/cache/inmemory/policies.d.ts +4 -1
  204. package/cache/inmemory/policies.js +35 -6
  205. package/cache/inmemory/policies.js.map +1 -1
  206. package/cache/inmemory/readFromStore.d.ts +11 -2
  207. package/cache/inmemory/readFromStore.js +486 -49
  208. package/cache/inmemory/readFromStore.js.map +1 -1
  209. package/cache/inmemory/types.d.ts +30 -5
  210. package/cache/inmemory/types.js.map +1 -1
  211. package/cache/inmemory/writeToStore.js +7 -7
  212. package/cache/inmemory/writeToStore.js.map +1 -1
  213. package/core/ApolloClient.d.ts +44 -10
  214. package/core/ApolloClient.js +37 -38
  215. package/core/ApolloClient.js.map +1 -1
  216. package/core/ObservableQuery.d.ts +16 -8
  217. package/core/ObservableQuery.js +225 -77
  218. package/core/ObservableQuery.js.map +1 -1
  219. package/core/QueryInfo.d.ts +18 -23
  220. package/core/QueryInfo.js +174 -190
  221. package/core/QueryInfo.js.map +1 -1
  222. package/core/QueryManager.d.ts +1 -3
  223. package/core/QueryManager.js +89 -60
  224. package/core/QueryManager.js.map +1 -1
  225. package/core/RefetchEventManager.js +3 -3
  226. package/core/dataStateErrorCache.d.ts +3 -0
  227. package/core/dataStateErrorCache.js +9 -0
  228. package/core/dataStateErrorCache.js.map +1 -0
  229. package/core/index.d.ts +4 -3
  230. package/core/index.js +1 -1
  231. package/core/index.js.map +1 -1
  232. package/core/types.d.ts +12 -6
  233. package/core/types.js.map +1 -1
  234. package/incremental/GraphQLCodegenIncremental.d.ts +55 -0
  235. package/incremental/GraphQLCodegenIncremental.js +2 -0
  236. package/incremental/GraphQLCodegenIncremental.js.map +1 -0
  237. package/incremental/handlers/defer20220824.d.ts +2 -4
  238. package/incremental/handlers/defer20220824.js.map +1 -1
  239. package/incremental/handlers/graphql17Alpha9.d.ts +29 -6
  240. package/incremental/handlers/graphql17Alpha9.js +48 -17
  241. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  242. package/incremental/handlers/notImplemented.js +1 -1
  243. package/incremental/index.d.ts +1 -0
  244. package/incremental/index.js.map +1 -1
  245. package/incremental/internal/types.d.ts +17 -0
  246. package/incremental/internal/types.js +2 -0
  247. package/incremental/internal/types.js.map +1 -0
  248. package/incremental/types.d.ts +55 -4
  249. package/incremental/types.js.map +1 -1
  250. package/invariantErrorCodes.js +167 -112
  251. package/link/core/ApolloLink.js +3 -3
  252. package/link/http/checkFetcher.js +1 -1
  253. package/link/http/parseAndCheckHttpResponse.js +2 -2
  254. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  255. package/link/persisted-queries/index.js +2 -2
  256. package/link/ws/index.js +1 -1
  257. package/local-state/LocalState.js +11 -11
  258. package/masking/internal/types.d.ts +1 -2
  259. package/masking/internal/types.js.map +1 -1
  260. package/masking/maskDefinition.js +2 -2
  261. package/masking/maskFragment.js +2 -2
  262. package/masking/maskOperation.js +1 -1
  263. package/masking/utils.js +3 -3
  264. package/package.json +1 -1
  265. package/react/context/ApolloContext.js +1 -1
  266. package/react/context/ApolloProvider.js +1 -1
  267. package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
  268. package/react/hooks/useApolloClient.js +1 -1
  269. package/react/hooks/useBackgroundQuery.d.ts +100 -47
  270. package/react/hooks/useBackgroundQuery.js.map +1 -1
  271. package/react/hooks/useLazyQuery.d.ts +39 -33
  272. package/react/hooks/useLazyQuery.js +2 -2
  273. package/react/hooks/useLazyQuery.js.map +1 -1
  274. package/react/hooks/useLoadableQuery.d.ts +23 -15
  275. package/react/hooks/useLoadableQuery.js +2 -2
  276. package/react/hooks/useLoadableQuery.js.map +1 -1
  277. package/react/hooks/useMutation.d.ts +10 -7
  278. package/react/hooks/useMutation.js.map +1 -1
  279. package/react/hooks/useQuery.d.ts +74 -32
  280. package/react/hooks/useQuery.js.map +1 -1
  281. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  282. package/react/hooks/useSubscription.js +1 -1
  283. package/react/hooks/useSuspenseQuery.d.ts +83 -34
  284. package/react/hooks/useSuspenseQuery.js.map +1 -1
  285. package/react/hooks/useSyncExternalStore.js +1 -1
  286. package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
  287. package/react/hooks-compiled/useApolloClient.js +1 -1
  288. package/react/hooks-compiled/useBackgroundQuery.d.ts +100 -47
  289. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  290. package/react/hooks-compiled/useLazyQuery.d.ts +39 -33
  291. package/react/hooks-compiled/useLazyQuery.js +2 -2
  292. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  293. package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
  294. package/react/hooks-compiled/useLoadableQuery.js +2 -2
  295. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  296. package/react/hooks-compiled/useMutation.d.ts +10 -7
  297. package/react/hooks-compiled/useMutation.js.map +1 -1
  298. package/react/hooks-compiled/useQuery.d.ts +74 -32
  299. package/react/hooks-compiled/useQuery.js.map +1 -1
  300. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  301. package/react/hooks-compiled/useSubscription.js +1 -1
  302. package/react/hooks-compiled/useSuspenseQuery.d.ts +83 -34
  303. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  304. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  305. package/react/internal/cache/QueryReference.js +1 -1
  306. package/react/internal/cache/QueryReference.js.map +1 -1
  307. package/react/internal/types.d.ts +15 -4
  308. package/react/internal/types.js.map +1 -1
  309. package/react/query-preloader/createQueryPreloader.d.ts +20 -5
  310. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  311. package/react/ssr/prerenderStatic.js +2 -2
  312. package/react/types/deprecated.d.ts +5 -4
  313. package/react/types/deprecated.js.map +1 -1
  314. package/testing/core/mocking/mockLink.d.ts +1 -2
  315. package/testing/core/mocking/mockLink.js +25 -5
  316. package/testing/core/mocking/mockLink.js.map +1 -1
  317. package/utilities/caching/sizes.d.ts +39 -1
  318. package/utilities/caching/sizes.js.map +1 -1
  319. package/utilities/graphql/DocumentTransform.js +1 -1
  320. package/utilities/index.d.ts +1 -0
  321. package/utilities/index.js.map +1 -1
  322. package/utilities/internal/StreamArrayState.d.ts +12 -0
  323. package/utilities/internal/StreamArrayState.js +23 -0
  324. package/utilities/internal/StreamArrayState.js.map +1 -0
  325. package/utilities/internal/addDeferFragmentLabels.d.ts +3 -0
  326. package/utilities/internal/addDeferFragmentLabels.js +30 -0
  327. package/utilities/internal/addDeferFragmentLabels.js.map +1 -0
  328. package/utilities/internal/capitalize.d.ts +7 -0
  329. package/utilities/internal/capitalize.js +9 -0
  330. package/utilities/internal/capitalize.js.map +1 -0
  331. package/utilities/internal/coerceScalarFieldsToParsed.d.ts +9 -0
  332. package/utilities/internal/coerceScalarFieldsToParsed.js +66 -0
  333. package/utilities/internal/coerceScalarFieldsToParsed.js.map +1 -0
  334. package/utilities/internal/constants.d.ts +19 -0
  335. package/utilities/internal/constants.js +19 -0
  336. package/utilities/internal/constants.js.map +1 -1
  337. package/utilities/internal/getDirectiveArgValue.d.ts +9 -0
  338. package/utilities/internal/getDirectiveArgValue.js +16 -0
  339. package/utilities/internal/getDirectiveArgValue.js.map +1 -0
  340. package/utilities/internal/getFragmentDefinition.js +3 -3
  341. package/utilities/internal/getFragmentFromSelection.js +2 -2
  342. package/utilities/internal/getFragmentFromSelection.js.map +1 -1
  343. package/utilities/internal/getFragmentQueryDocument.js +2 -2
  344. package/utilities/internal/getMainDefinition.js +1 -1
  345. package/utilities/internal/getMemoryInternals.d.ts +4 -0
  346. package/utilities/internal/getMemoryInternals.js +6 -0
  347. package/utilities/internal/getMemoryInternals.js.map +1 -1
  348. package/utilities/internal/getQueryDefinition.js +1 -1
  349. package/utilities/internal/getUnwrappedType.d.ts +8 -0
  350. package/utilities/internal/getUnwrappedType.js +17 -0
  351. package/utilities/internal/getUnwrappedType.js.map +1 -0
  352. package/utilities/internal/index.d.ts +16 -1
  353. package/utilities/internal/index.js +12 -1
  354. package/utilities/internal/index.js.map +1 -1
  355. package/utilities/internal/isDeferredFragment.d.ts +9 -0
  356. package/utilities/internal/isDeferredFragment.js +35 -0
  357. package/utilities/internal/isDeferredFragment.js.map +1 -0
  358. package/utilities/internal/isStreamField.d.ts +9 -0
  359. package/utilities/internal/isStreamField.js +34 -0
  360. package/utilities/internal/isStreamField.js.map +1 -0
  361. package/utilities/internal/isTypenameField.d.ts +3 -0
  362. package/utilities/internal/isTypenameField.js +4 -0
  363. package/utilities/internal/isTypenameField.js.map +1 -0
  364. package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
  365. package/utilities/internal/makeStreamInfoTrie.js +14 -0
  366. package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
  367. package/utilities/internal/removeDirectivesFromDocument.js +1 -1
  368. package/utilities/internal/shouldInclude.js +4 -4
  369. package/utilities/internal/toDiffWithDataState.d.ts +8 -0
  370. package/utilities/internal/toDiffWithDataState.js +17 -0
  371. package/utilities/internal/toDiffWithDataState.js.map +1 -0
  372. package/utilities/internal/types/DeferInfo.d.ts +10 -0
  373. package/utilities/internal/types/DeferInfo.js +2 -0
  374. package/utilities/internal/types/DeferInfo.js.map +1 -0
  375. package/utilities/internal/types/Exact.d.ts +2 -0
  376. package/utilities/internal/types/Exact.js +2 -0
  377. package/utilities/internal/types/Exact.js.map +1 -0
  378. package/utilities/internal/types/IsLooselyEqual.d.ts +10 -0
  379. package/utilities/internal/types/IsLooselyEqual.js +2 -0
  380. package/utilities/internal/types/IsLooselyEqual.js.map +1 -0
  381. package/utilities/internal/types/IsNeverish.d.ts +4 -0
  382. package/utilities/internal/types/IsNeverish.js +2 -0
  383. package/utilities/internal/types/IsNeverish.js.map +1 -0
  384. package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
  385. package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
  386. package/utilities/internal/valueToObjectRepresentation.js +1 -1
  387. package/utilities/policies/pagination.d.ts +1 -1
  388. package/utilities/policies/pagination.js.map +1 -1
  389. package/utilities/subscriptions/relay/index.js +1 -0
  390. package/utilities/subscriptions/relay/index.js.map +1 -1
  391. package/version.js +1 -1
  392. package/version.js.map +1 -1
@@ -8,7 +8,7 @@ import type { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
8
8
  import type { LocalState } from "@apollo/client/local-state";
9
9
  import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
10
10
  import { DocumentTransform } from "@apollo/client/utilities";
11
- import type { LazyType, OptionWithFallback, SignatureStyle, VariablesOption, variablesUnknownSymbol } from "@apollo/client/utilities/internal";
11
+ import type { LazyType, OptionWithFallback, Prettify, SignatureStyle, VariablesOption, variablesUnknownSymbol } from "@apollo/client/utilities/internal";
12
12
  import { getApolloClientMemoryInternals } from "@apollo/client/utilities/internal";
13
13
  import type { DeclareDefaultOptions, DefaultOptions } from "./defaultOptions.cjs";
14
14
  import type { ObservableQuery } from "./ObservableQuery.cjs";
@@ -232,7 +232,20 @@ export declare namespace ApolloClient {
232
232
  export namespace mutate {
233
233
  interface DefaultOptions extends ApolloClient.DefaultOptions.Mutate.Calculated {
234
234
  }
235
- type ResultForOptions<TData, TVariables extends OperationVariables, TCache extends Cache.Implementation, TOptions extends Record<string, unknown> | MutateOptions<any, TVariables, TCache>> = LazyType<MutateResult<MaybeMasked<TData>, OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
235
+ type OptionsFor<TData, TVariables extends OperationVariables, TCache extends Cache.Implementation, TOptions extends {
236
+ variables?: unknown;
237
+ }> = MutateOptions<NoInfer<TData>, NoInfer<TVariables>, TCache> & {
238
+ variables?: Prettify<TVariables & {
239
+ [K in keyof TOptions["variables"]]: K extends keyof TVariables ? TVariables[K] : never;
240
+ }>;
241
+ } & (Exclude<keyof TOptions, keyof MutateOptions<any, any, any>> extends (infer InvalidOptionNames extends string) ? [
242
+ InvalidOptionNames
243
+ ] extends [never] ? unknown : {
244
+ [K in InvalidOptionNames]: never;
245
+ } : never);
246
+ type ResultForOptions<TData, TErrorPolicy extends ErrorPolicy | undefined = undefined> = LazyType<MutateResult<MaybeMasked<TData>, OptionWithFallback<{
247
+ errorPolicy: TErrorPolicy;
248
+ }, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
236
249
  namespace Signatures {
237
250
  interface Classic {
238
251
  /**
@@ -271,11 +284,21 @@ export declare namespace ApolloClient {
271
284
  *
272
285
  * It takes options as an object with the following keys and values:
273
286
  */
274
- <TData, TVariables extends OperationVariables, TOptions extends ApolloClient.MutateOptions<NoInfer<TData>, NoInfer<TVariables>, Cache.Implementation> & VariablesOption<TVariables & {
275
- [K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
276
- }>>(options: TOptions & {
287
+ <TData, TVariables extends OperationVariables, TOptions extends Omit<ApolloClient.MutateOptions<NoInfer<TData>, any, Cache.Implementation>, "variables"> & {
288
+ variables?: unknown;
289
+ }, TErrorPolicy extends ErrorPolicy | undefined = undefined>(options: TOptions & ApolloClient.mutate.OptionsFor<TData, TVariables, Cache.Implementation, TOptions> & {
277
290
  mutation: TypedDocumentNode<TData, TVariables>;
278
- }): Promise<ApolloClient.mutate.ResultForOptions<TData, TVariables, Cache.Implementation, TOptions>>;
291
+ /**
292
+ * Specifies how the mutation handles a response that returns both GraphQL errors and partial results.
293
+ *
294
+ * For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
295
+ *
296
+ * The default value is `none`, meaning that the mutation result includes error details but _not_ partial results.
297
+ *
298
+ * @docGroup 1. Operation options
299
+ */
300
+ errorPolicy?: TErrorPolicy;
301
+ }): Promise<ApolloClient.mutate.ResultForOptions<TData, TErrorPolicy>>;
279
302
  }
280
303
  type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
281
304
  }
@@ -473,7 +496,18 @@ export declare namespace ApolloClient {
473
496
  export namespace query {
474
497
  interface DefaultOptions extends ApolloClient.DefaultOptions.Query.Calculated {
475
498
  }
476
- type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, unknown> | QueryOptions<any, TVariables>> = LazyType<QueryResult<MaybeMasked<TData>, OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
499
+ type OptionsFor<TData, TVariables extends OperationVariables, TOptions extends {
500
+ variables?: unknown;
501
+ }> = QueryOptions<NoInfer<TData>, NoInfer<TVariables>> & {
502
+ variables?: Prettify<TVariables & {
503
+ [K in keyof TOptions["variables"]]: K extends keyof TVariables ? TVariables[K] : never;
504
+ }>;
505
+ } & (Exclude<keyof TOptions, keyof QueryOptions<any, any>> extends (infer InvalidOptionNames extends string) ? [
506
+ InvalidOptionNames
507
+ ] extends [never] ? unknown : {
508
+ [K in InvalidOptionNames]: never;
509
+ } : never);
510
+ type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, unknown> | Omit<QueryOptions<any, any>, "variables">> = LazyType<QueryResult<MaybeMasked<TData>, OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
477
511
  namespace Signatures {
478
512
  interface Classic {
479
513
  /**
@@ -515,9 +549,9 @@ export declare namespace ApolloClient {
515
549
  * describe how this query should be treated e.g. whether it should hit the
516
550
  * server at all or just resolve from the cache, etc.
517
551
  */
518
- <TData, TVariables extends OperationVariables, TOptions extends ApolloClient.QueryOptions<NoInfer<TData>, NoInfer<TVariables>> & VariablesOption<TVariables & {
519
- [K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
520
- }>>(options: TOptions & {
552
+ <TData, TVariables extends OperationVariables, TOptions extends Omit<ApolloClient.QueryOptions<NoInfer<TData>, any>, "variables"> & {
553
+ variables?: unknown;
554
+ }>(options: TOptions & ApolloClient.query.OptionsFor<TData, TVariables, TOptions> & {
521
555
  query: TypedDocumentNode<TData, TVariables>;
522
556
  }): Promise<ApolloClient.query.ResultForOptions<TData, TVariables, TOptions>>;
523
557
  }
@@ -12,6 +12,7 @@ const utilities_1 = require("@apollo/client/utilities");
12
12
  const environment_1 = require("@apollo/client/utilities/environment");
13
13
  const internal_1 = require("@apollo/client/utilities/internal");
14
14
  const invariant_1 = require("@apollo/client/utilities/invariant");
15
+ const dataStateErrorCache_js_1 = require("./dataStateErrorCache.cjs");
15
16
  const networkStatus_js_1 = require("./networkStatus.cjs");
16
17
  const { assign, hasOwnProperty } = Object;
17
18
  const uninitialized = {
@@ -28,16 +29,29 @@ const empty = {
28
29
  dataState: "empty",
29
30
  partial: true,
30
31
  };
32
+ const destructiveMethodCounts = new WeakMap();
33
+ function wrapDestructiveCacheMethod(cache, methodName) {
34
+ const original = cache[methodName];
35
+ if (typeof original === "function") {
36
+ // @ts-expect-error this is just too generic to be typed correctly
37
+ cache[methodName] = function () {
38
+ destructiveMethodCounts.set(cache,
39
+ // The %1e15 allows the count to wrap around to 0 safely every
40
+ // quadrillion evictions, so there's no risk of overflow. To be
41
+ // clear, this is more of a pedantic principle than something
42
+ // that matters in any conceivable practical scenario.
43
+ (destructiveMethodCounts.get(cache) + 1) % 1e15);
44
+ // @ts-expect-error this is just too generic to be typed correctly
45
+ return original.apply(this, arguments);
46
+ };
47
+ }
48
+ }
31
49
  class ObservableQuery {
32
50
  options;
33
51
  queryName;
34
52
  variablesUnknown = false;
35
- /**
36
- * @internal will be read and written from `QueryInfo`
37
- *
38
- * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
39
- */
40
- _lastWrite;
53
+ didWarnOnFeud = false;
54
+ lastMissing;
41
55
  // The `query` computed property will always reflect the document transformed
42
56
  // by the last run query. `this.options.query` will always reflect the raw
43
57
  // untransformed query to ensure document transforms with runtime conditionals
@@ -74,6 +88,18 @@ class ObservableQuery {
74
88
  }
75
89
  constructor({ queryManager, options, transformedQuery = queryManager.transform(options.query), }) {
76
90
  this.queryManager = queryManager;
91
+ // Track how often destructive cache methods are called, since we want
92
+ // eviction to override the feud-stopping logic in `shouldAutoRefetch`,
93
+ // by causing it to return true. Wrapping these cache methods is a bit of a
94
+ // hack, but it saves us from having to make eviction counting an official
95
+ // part of the ApolloCache API.
96
+ const { cache } = queryManager;
97
+ if (!destructiveMethodCounts.has(cache)) {
98
+ destructiveMethodCounts.set(cache, 0);
99
+ wrapDestructiveCacheMethod(cache, "evict");
100
+ wrapDestructiveCacheMethod(cache, "modify");
101
+ wrapDestructiveCacheMethod(cache, "reset");
102
+ }
77
103
  // active state
78
104
  this.waitForNetworkResult = options.fetchPolicy === "network-only";
79
105
  this.isTornDown = false;
@@ -84,7 +110,7 @@ class ObservableQuery {
84
110
  // Make sure we don't store "standby" as the initialFetchPolicy.
85
111
  initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
86
112
  if (options[internal_1.variablesUnknownSymbol]) {
87
- (0, invariant_1.invariant)(fetchPolicy === "standby", 82);
113
+ (0, invariant_1.invariant)(fetchPolicy === "standby", 83);
88
114
  this.variablesUnknown = true;
89
115
  }
90
116
  this.lastQuery = transformedQuery;
@@ -213,12 +239,13 @@ class ObservableQuery {
213
239
  * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
214
240
  */
215
241
  getCacheDiff({ optimistic = true } = {}) {
216
- return this.cache.diff({
242
+ return (0, internal_1.toDiffWithDataState)(this.cache.diff({
217
243
  query: this.query,
218
244
  variables: this.variables,
219
245
  returnPartialData: true,
220
246
  optimistic,
221
- });
247
+ [internal_1.handleIncrementalSymbol]: undefined,
248
+ }));
222
249
  }
223
250
  getInitialResult(initialFetchPolicy) {
224
251
  let fetchPolicy = initialFetchPolicy || this.options.fetchPolicy;
@@ -228,16 +255,18 @@ class ObservableQuery {
228
255
  }
229
256
  const cacheResult = () => {
230
257
  const diff = this.getCacheDiff();
258
+ let { dataState } = diff;
231
259
  // TODO: queryInfo.getDiff should handle this since cache.diff returns a
232
260
  // null when returnPartialData is false
233
261
  const data = this.options.returnPartialData || diff.complete ?
234
262
  diff.result ?? undefined
235
263
  : undefined;
264
+ if (data === undefined) {
265
+ dataState = "empty";
266
+ }
236
267
  return this.maskResult({
237
268
  data,
238
- dataState: diff.complete ? "complete"
239
- : data === undefined ? "empty"
240
- : "partial",
269
+ dataState,
241
270
  loading: !diff.complete,
242
271
  networkStatus: diff.complete ? networkStatus_js_1.NetworkStatus.ready : networkStatus_js_1.NetworkStatus.loading,
243
272
  partial: !diff.complete,
@@ -390,7 +419,7 @@ class ObservableQuery {
390
419
  const queryDef = (0, internal_1.getQueryDefinition)(this.query);
391
420
  const vars = queryDef.variableDefinitions;
392
421
  if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
393
- __DEV__ && invariant_1.invariant.warn(83, variables, queryDef.name?.value || queryDef);
422
+ __DEV__ && invariant_1.invariant.warn(84, variables, queryDef.name?.value || queryDef);
394
423
  }
395
424
  }
396
425
  if (variables && !(0, equality_1.equal)(this.variables, variables)) {
@@ -398,7 +427,6 @@ class ObservableQuery {
398
427
  reobserveOptions.variables = this.options.variables =
399
428
  this.getVariablesWithDefaults({ ...this.variables, ...variables });
400
429
  }
401
- this._lastWrite = undefined;
402
430
  return this._reobserve(reobserveOptions, {
403
431
  newNetworkStatus: networkStatus_js_1.NetworkStatus.refetch,
404
432
  });
@@ -406,7 +434,7 @@ class ObservableQuery {
406
434
  fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
407
435
  (0, invariant_1.invariant)(
408
436
  this.options.fetchPolicy !== "cache-only",
409
- 84,
437
+ 85,
410
438
  (0, internal_1.getOperationName)(this.query, "(anonymous)")
411
439
  );
412
440
  const combinedOptions = {
@@ -440,7 +468,7 @@ class ObservableQuery {
440
468
  let wasUpdated = false;
441
469
  const isCached = this.options.fetchPolicy !== "no-cache";
442
470
  if (!isCached) {
443
- (0, invariant_1.invariant)(updateQuery, 85);
471
+ (0, invariant_1.invariant)(updateQuery, 86);
444
472
  }
445
473
  const { finalize, pushNotification } = this.pushOperation(networkStatus_js_1.NetworkStatus.fetchMore);
446
474
  pushNotification({
@@ -517,9 +545,7 @@ class ObservableQuery {
517
545
  // will be overwritten anyways, just here for types sake
518
546
  loading: false,
519
547
  data: diff.result,
520
- dataState: fetchMoreResult.dataState === "streaming" ?
521
- "streaming"
522
- : "complete",
548
+ dataState: diff.complete ? "complete" : "streaming",
523
549
  },
524
550
  });
525
551
  }
@@ -616,7 +642,7 @@ class ObservableQuery {
616
642
  onError(error);
617
643
  }
618
644
  else {
619
- invariant_1.invariant.error(86, error);
645
+ invariant_1.invariant.error(87, error);
620
646
  }
621
647
  return;
622
648
  }
@@ -867,7 +893,7 @@ class ObservableQuery {
867
893
  if (!this.didWarnCacheOnlyPolling &&
868
894
  pollInterval &&
869
895
  fetchPolicy === "cache-only") {
870
- __DEV__ && invariant_1.invariant.warn(87, (0, internal_1.getOperationName)(this.query, "(anonymous)"));
896
+ __DEV__ && invariant_1.invariant.warn(88, (0, internal_1.getOperationName)(this.query, "(anonymous)"));
871
897
  this.didWarnCacheOnlyPolling = true;
872
898
  }
873
899
  }
@@ -933,7 +959,10 @@ class ObservableQuery {
933
959
  }
934
960
  _reobserve(newOptions, internalOptions) {
935
961
  this.isTornDown = false;
936
- let { newNetworkStatus } = internalOptions || {};
962
+ let { newNetworkStatus, keepLastMissing } = internalOptions || {};
963
+ if (!keepLastMissing) {
964
+ this.lastMissing = undefined;
965
+ }
937
966
  this.queryManager.obsQueries.add(this);
938
967
  const useDisposableObservable =
939
968
  // Refetching uses a disposable Observable to allow refetches using different
@@ -1074,7 +1103,7 @@ class ObservableQuery {
1074
1103
  this.queryManager.obsQueries.delete(this);
1075
1104
  this.isTornDown = true;
1076
1105
  this.abortActiveOperations();
1077
- this._lastWrite = undefined;
1106
+ this.lastMissing = undefined;
1078
1107
  }
1079
1108
  transformDocument(document) {
1080
1109
  return this.queryManager.transform(document);
@@ -1132,53 +1161,126 @@ class ObservableQuery {
1132
1161
  return;
1133
1162
  }
1134
1163
  }
1135
- const { dirty } = this;
1164
+ const { dirty, lastMissing } = this;
1165
+ const { fetchPolicy } = this.options;
1136
1166
  this.resetNotifications();
1137
- if (dirty &&
1138
- (this.options.fetchPolicy === "cache-only" ||
1139
- this.options.fetchPolicy === "cache-and-network" ||
1140
- !this.activeOperations.size)) {
1141
- const diff = this.getCacheDiff();
1142
- if (
1143
- // `fromOptimisticTransaction` is not available through the `cache.diff`
1144
- // code path, so we need to check it this way
1145
- (0, equality_1.equal)(diff.result, this.getCacheDiff({ optimistic: false }).result)) {
1146
- //If this diff did not come from an optimistic transaction
1147
- // make the ObservableQuery "reobserve" the latest data
1148
- // using a temporary fetch policy of "cache-first", so complete cache
1149
- // results have a chance to be delivered without triggering additional
1150
- // network requests, even when options.fetchPolicy is "network-only"
1151
- // or "cache-and-network". All other fetch policies are preserved by
1152
- // this method, and are handled by calling oq.reobserve(). If this
1153
- // reobservation is spurious, distinctUntilChanged still has a
1154
- // chance to catch it before delivery to ObservableQuery subscribers.
1155
- this.reobserveCacheFirst();
1167
+ if (!dirty ||
1168
+ (fetchPolicy !== "cache-only" &&
1169
+ fetchPolicy !== "cache-and-network" &&
1170
+ this.activeOperations.size)) {
1171
+ return;
1172
+ }
1173
+ const diff = this.getCacheDiff();
1174
+ const current = this.getCurrentResult();
1175
+ // `fromOptimisticTransaction` is not available through the `cache.diff`
1176
+ // code path, so we need to check whether the cache result is an optimistic
1177
+ // result this way.
1178
+ const isOptimistic = !(0, equality_1.equal)(diff.result, this.getCacheDiff({ optimistic: false }).result);
1179
+ if (
1180
+ // When this diff came from an optimistic transaction, deliver the
1181
+ // current cache data to the ObservableQuery, but don't perform a
1182
+ // reobservation, since oq.reobserveCacheFirst might make a network
1183
+ // request, and we never want to trigger network requests in the
1184
+ // middle of optimistic updates.
1185
+ isOptimistic ||
1186
+ // If we get a cache update in the middle of streaming (possible with
1187
+ // cache-and-network fetch policy), just deliver the cache value without
1188
+ // going through the full reobserve which would otherwise trigger another
1189
+ // request (deduplication should kick in, but doing so replays any
1190
+ // previous emits from the link chain, which get rewritten into the cache
1191
+ // and might clobber this cache update)
1192
+ (!diff.complete && current.networkStatus === networkStatus_js_1.NetworkStatus.streaming)) {
1193
+ this.deliverCacheDiff(diff);
1194
+ return;
1195
+ }
1196
+ if (diff.complete) {
1197
+ this.lastMissing = undefined;
1198
+ }
1199
+ else if (!lastMissing ||
1200
+ // If a destructive cache method has been called since the last recorded
1201
+ // incomplete result, there's a chance fetching this data again will
1202
+ // restore what was evicted, even though the cache result looks the same
1203
+ // as before.
1204
+ lastMissing.dmCount !== destructiveMethodCounts.get(this.cache) ||
1205
+ !(0, equality_1.equal)(lastMissing.variables, this.variables) ||
1206
+ !(0, equality_1.equal)(lastMissing.missing, diff.missing?.missing)) {
1207
+ this.didWarnOnFeud = false;
1208
+ this.lastMissing = {
1209
+ variables: this.variables,
1210
+ missing: diff.missing?.missing,
1211
+ dmCount: destructiveMethodCounts.get(this.cache),
1212
+ };
1213
+ }
1214
+ else if (
1215
+ // reobserveCacheFirst with cache-only fetch policy only calls
1216
+ // reobserve which never fetches from the network so we are ok
1217
+ // allowing cache-only queries to fallthrough to reobserveCacheFirst.
1218
+ // This also prevents the feud warning which would be confusing for a
1219
+ // cache-only query anyways.
1220
+ fetchPolicy !== "cache-only") {
1221
+ // If we've fallen through to this case, a cache emit has returned the
1222
+ // same missing fields which means at least one value on the fields we've
1223
+ // already delivered have changed. We are ok delivering the updated
1224
+ // partial result in this case to keep the result as fresh as possible. We
1225
+ // NEVER want to downgrade this query from a complete query to a partial
1226
+ // query though, so we also make sure we only deliver if the previous
1227
+ // result was also partial.
1228
+ if (current.dataState === "partial") {
1229
+ this.deliverCacheDiff(diff);
1156
1230
  }
1157
- else {
1158
- // If this diff came from an optimistic transaction, deliver the
1159
- // current cache data to the ObservableQuery, but don't perform a
1160
- // reobservation, since oq.reobserveCacheFirst might make a network
1161
- // request, and we never want to trigger network requests in the
1162
- // middle of optimistic updates.
1163
- this.input.next({
1164
- kind: "N",
1165
- value: {
1166
- data: diff.result,
1167
- dataState: diff.complete ? "complete"
1168
- : diff.result ? "partial"
1169
- : "empty",
1170
- networkStatus: networkStatus_js_1.NetworkStatus.ready,
1171
- loading: false,
1172
- error: undefined,
1173
- partial: !diff.complete,
1174
- },
1175
- source: "cache",
1176
- query: this.query,
1177
- variables: this.variables,
1178
- meta: {},
1179
- });
1231
+ // If the (partial) result is the same as the last partial result
1232
+ // we recorded from a previous broadcast (and the variables match
1233
+ // too), avoid calling reobserveCacheFirst to refetch this query
1234
+ // again. If we allow refetching anytime this result becomes partial,
1235
+ // we risk feuds between queries competing to update the same data in
1236
+ // incompatible ways, which can lead to an endless cycle of cache
1237
+ // broadcasts and useless network requests. As with any
1238
+ // feud, eventually one side must step back from the brink,
1239
+ // letting the other side(s) have the last word(s). There may
1240
+ // be other points where we could break this cycle, such as
1241
+ // silencing the broadcast for cache.writeQuery (not a good
1242
+ // idea, since it just delays the feud a bit) or somehow
1243
+ // avoiding the network request that just happened (also bad,
1244
+ // because the server could return useful new data). All
1245
+ // options considered, returning early and stopping the
1246
+ // reobserveCacheFirst cycle seems to be the least damaging place to
1247
+ // break the cycle because it allows read functions/custom scalars to
1248
+ // be applied to the feuding query while avoiding the endless cycle of
1249
+ // requests.
1250
+ if (environment_1.__DEV__ && !this.didWarnOnFeud) {
1251
+ this.didWarnOnFeud = true;
1252
+ warnOnFeud(this.query, diff);
1180
1253
  }
1254
+ return;
1181
1255
  }
1256
+ //If this diff did not come from an optimistic transaction
1257
+ // make the ObservableQuery "reobserve" the latest data
1258
+ // using a temporary fetch policy of "cache-first", so complete cache
1259
+ // results have a chance to be delivered without triggering additional
1260
+ // network requests, even when options.fetchPolicy is "network-only"
1261
+ // or "cache-and-network". All other fetch policies are preserved by
1262
+ // this method, and are handled by calling oq.reobserve(). If this
1263
+ // reobservation is spurious, distinctUntilChanged still has a
1264
+ // chance to catch it before delivery to ObservableQuery subscribers.
1265
+ this.reobserveCacheFirst();
1266
+ }
1267
+ deliverCacheDiff(diff) {
1268
+ const current = this.getCurrentResult();
1269
+ this.input.next({
1270
+ kind: "N",
1271
+ value: {
1272
+ data: diff.result,
1273
+ dataState: diff.dataState,
1274
+ networkStatus: current.networkStatus,
1275
+ loading: current.loading,
1276
+ error: undefined,
1277
+ partial: !diff.complete,
1278
+ },
1279
+ source: "cache",
1280
+ query: this.query,
1281
+ variables: this.variables,
1282
+ meta: {},
1283
+ });
1182
1284
  }
1183
1285
  activeOperations = new Set();
1184
1286
  pushOperation(networkStatus) {
@@ -1241,6 +1343,7 @@ class ObservableQuery {
1241
1343
  // exception for cache-only queries - we reset them into a "ready" state
1242
1344
  // as we won't trigger a refetch for them
1243
1345
  const resetToEmpty = this.options.fetchPolicy === "cache-only";
1346
+ this.lastMissing = undefined;
1244
1347
  this.setResult(resetToEmpty ? empty : uninitialized, {
1245
1348
  shouldEmit: resetToEmpty ? 1 /* EmitBehavior.force */ : 2 /* EmitBehavior.never */,
1246
1349
  });
@@ -1262,19 +1365,55 @@ class ObservableQuery {
1262
1365
  });
1263
1366
  }
1264
1367
  operator = (0, internal_1.filterMap)((notification) => {
1265
- const { query, variables, meta } = notification;
1368
+ const { query, meta } = notification;
1266
1369
  if (notification.source === "setResult") {
1267
- return { query, variables, result: notification.value, meta };
1370
+ return {
1371
+ query,
1372
+ variables: this.variables,
1373
+ result: notification.value,
1374
+ meta,
1375
+ };
1376
+ }
1377
+ if (notification.kind === "C") {
1378
+ return;
1268
1379
  }
1269
- if (notification.kind === "C" || !isEqualQuery(notification, this)) {
1380
+ const resolvedVariables = "resolvedVariables" in notification ?
1381
+ notification.resolvedVariables
1382
+ : undefined;
1383
+ // Usually we prefer to drop notifications that don't match this query
1384
+ // but this breaks when used with `@export` queries that resolve variables
1385
+ // after the request is initiated. `notification.resolvedVariables` gives us
1386
+ // the variables the query actually resolved with during evaluation in
1387
+ // QueryManager (which is the variables value after `@export` variables have
1388
+ // been applied), but we need to update this query with those resolved
1389
+ // variables maybe in the middle of a request (updating is handled below).
1390
+ // When we update this.variables to the resolved variables, this causes
1391
+ // isEqualQuery(notification, this) to fail for future notifications since
1392
+ // the notification.variables holds the stale variables value. In this case,
1393
+ // we want to allow the notification through only if the current variables
1394
+ // value matches the resolved variables.
1395
+ //
1396
+ // Note: the check for matching resolved variables typically kicks in for
1397
+ // multi-emission fetches (such as defer, or cache-and-network, etc).
1398
+ if (notification.query !== this.query) {
1270
1399
  return;
1271
1400
  }
1401
+ if (!(0, equality_1.equal)(resolvedVariables, this.variables)) {
1402
+ if (!(0, equality_1.equal)(notification.variables, this.variables)) {
1403
+ return;
1404
+ }
1405
+ if (resolvedVariables) {
1406
+ this.options.variables = resolvedVariables;
1407
+ this.resubscribeCache();
1408
+ }
1409
+ }
1410
+ const variables = this.variables;
1272
1411
  let result;
1273
1412
  const previous = this.subject.getValue();
1274
1413
  if (notification.source === "cache") {
1275
1414
  result = notification.value;
1276
1415
  if (result.networkStatus === networkStatus_js_1.NetworkStatus.ready &&
1277
- result.partial &&
1416
+ result.dataState === "partial" &&
1278
1417
  (!this.options.returnPartialData ||
1279
1418
  previous.result.networkStatus === networkStatus_js_1.NetworkStatus.error) &&
1280
1419
  this.options.fetchPolicy !== "cache-only") {
@@ -1289,7 +1428,9 @@ class ObservableQuery {
1289
1428
  result =
1290
1429
  notification.kind === "E" ?
1291
1430
  {
1292
- ...(isEqualQuery(previous, notification) ?
1431
+ ...((isEqualQuery(previous, notification) ||
1432
+ (resolvedVariables &&
1433
+ (0, equality_1.equal)(resolvedVariables, previous.variables))) ?
1293
1434
  previous.result
1294
1435
  : { data: undefined, dataState: "empty", partial: true }),
1295
1436
  error: notification.error,
@@ -1298,7 +1439,8 @@ class ObservableQuery {
1298
1439
  }
1299
1440
  : notification.value;
1300
1441
  if (notification.kind === "E" && result.dataState === "streaming") {
1301
- result.dataState = "complete";
1442
+ result.dataState =
1443
+ dataStateErrorCache_js_1.dataStateErrorCache.get(notification.error) ?? "complete";
1302
1444
  }
1303
1445
  if (result.error) {
1304
1446
  meta.shouldEmit = 1 /* EmitBehavior.force */;
@@ -1346,7 +1488,10 @@ class ObservableQuery {
1346
1488
  reobserveCacheFirst() {
1347
1489
  const { fetchPolicy, nextFetchPolicy } = this.options;
1348
1490
  if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
1349
- this.reobserve({
1491
+ // Preserve this.lastMissing so a cache update that triggers this
1492
+ // reobserve doesn't reset feud detection. All user-initiated calls to
1493
+ // reobserve (refetch/poll/reobserve, etc) should clear it.
1494
+ this._reobserve({
1350
1495
  fetchPolicy: "cache-first",
1351
1496
  // Use a temporary nextFetchPolicy function that replaces itself with the
1352
1497
  // previous nextFetchPolicy value and returns the original fetchPolicy.
@@ -1362,10 +1507,10 @@ class ObservableQuery {
1362
1507
  // Otherwise go back to the original this.options.fetchPolicy.
1363
1508
  return fetchPolicy;
1364
1509
  },
1365
- });
1510
+ }, { keepLastMissing: true });
1366
1511
  }
1367
1512
  else {
1368
- this.reobserve();
1513
+ this._reobserve(undefined, { keepLastMissing: true });
1369
1514
  }
1370
1515
  }
1371
1516
  getVariablesWithDefaults(variables) {
@@ -1375,7 +1520,7 @@ class ObservableQuery {
1375
1520
  exports.ObservableQuery = ObservableQuery;
1376
1521
  function logMissingFieldErrors(missing) {
1377
1522
  if (environment_1.__DEV__ && missing) {
1378
- __DEV__ && invariant_1.invariant.debug(88, missing);
1523
+ __DEV__ && invariant_1.invariant.debug(89, missing);
1379
1524
  }
1380
1525
  }
1381
1526
  function isEqualQuery(a, b) {
@@ -1418,4 +1563,11 @@ function getTrackingOperatorPromise(defaultValue) {
1418
1563
  });
1419
1564
  return { promise, operator };
1420
1565
  }
1566
+ function warnOnFeud(query, diff) {
1567
+ __DEV__ && invariant_1.invariant.warn(
1568
+ 90,
1569
+ (0, internal_1.getOperationName)(query, "(anonymous)"),
1570
+ diff.missing?.missing
1571
+ );
1572
+ }
1421
1573
  //# sourceMappingURL=ObservableQuery.cjs.map