@apollo/client 4.1.0-alpha.2 → 4.1.0-alpha.4

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 (250) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/__cjs/cache/core/cache.cjs +148 -50
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +72 -23
  5. package/__cjs/cache/core/types/common.cjs.map +1 -1
  6. package/__cjs/cache/core/types/common.d.cts +1 -1
  7. package/__cjs/cache/inmemory/fragmentRegistry.cjs +1 -1
  8. package/__cjs/cache/inmemory/fragmentRegistry.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/inMemoryCache.cjs +12 -1
  10. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  11. package/__cjs/core/ApolloClient.cjs +24 -27
  12. package/__cjs/core/ApolloClient.cjs.map +1 -1
  13. package/__cjs/core/ApolloClient.d.cts +94 -5
  14. package/__cjs/core/ObservableQuery.cjs +8 -4
  15. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  16. package/__cjs/core/ObservableQuery.d.cts +2 -2
  17. package/__cjs/core/QueryManager.cjs +1 -1
  18. package/__cjs/core/QueryManager.cjs.map +1 -1
  19. package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
  20. package/__cjs/dev/setErrorMessageHandler.d.cts +1 -1
  21. package/__cjs/incremental/handlers/defer20220824.cjs +6 -2
  22. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  23. package/__cjs/incremental/handlers/defer20220824.d.cts +0 -2
  24. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +9 -3
  25. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  26. package/__cjs/link/schema/index.cjs +1 -1
  27. package/__cjs/link/schema/index.cjs.map +1 -1
  28. package/__cjs/link/schema/index.d.cts +1 -1
  29. package/__cjs/link/subscriptions/index.cjs +2 -1
  30. package/__cjs/link/subscriptions/index.cjs.map +1 -1
  31. package/__cjs/masking/maskDefinition.cjs +1 -1
  32. package/__cjs/masking/maskDefinition.cjs.map +1 -1
  33. package/__cjs/masking/types.d.cts +2 -1
  34. package/__cjs/react/hooks/internal/index.cjs +3 -1
  35. package/__cjs/react/hooks/internal/index.cjs.map +1 -1
  36. package/__cjs/react/hooks/internal/index.d.cts +1 -0
  37. package/__cjs/react/hooks/internal/useDeepMemo.cjs +2 -0
  38. package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
  39. package/__cjs/react/hooks/internal/useRenderGuard.cjs +1 -1
  40. package/__cjs/react/hooks/internal/useRenderGuard.cjs.map +1 -1
  41. package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs +28 -0
  42. package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs.map +1 -0
  43. package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.d.cts +11 -0
  44. package/__cjs/react/hooks/useBackgroundQuery.cjs +3 -11
  45. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  46. package/__cjs/react/hooks/useFragment.cjs +38 -87
  47. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  48. package/__cjs/react/hooks/useFragment.d.cts +65 -6
  49. package/__cjs/react/hooks/useLazyQuery.cjs +2 -0
  50. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  51. package/__cjs/react/hooks/useLazyQuery.d.cts +1 -1
  52. package/__cjs/react/hooks/useMutation.d.cts +3 -1
  53. package/__cjs/react/hooks/useQuery.cjs +1 -4
  54. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  55. package/__cjs/react/hooks/useQuery.d.cts +2 -2
  56. package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -3
  57. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  58. package/__cjs/react/hooks/useReactiveVar.cjs +2 -1
  59. package/__cjs/react/hooks/useReactiveVar.cjs.map +1 -1
  60. package/__cjs/react/hooks/useReactiveVar.d.cts +2 -1
  61. package/__cjs/react/hooks/useReadQuery.cjs +1 -3
  62. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  63. package/__cjs/react/hooks/useReadQuery.d.cts +1 -1
  64. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  65. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  66. package/__cjs/react/hooks/useSuspenseFragment.cjs +16 -16
  67. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  68. package/__cjs/react/hooks/useSuspenseFragment.d.cts +33 -7
  69. package/__cjs/react/hooks/useSuspenseQuery.cjs +6 -12
  70. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  71. package/__cjs/react/hooks/useSuspenseQuery.d.cts +1 -1
  72. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  73. package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
  74. package/__cjs/react/internal/cache/FragmentReference.cjs +3 -22
  75. package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
  76. package/__cjs/react/internal/cache/FragmentReference.d.cts +2 -4
  77. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  78. package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
  79. package/__cjs/react/internal/cache/QueryReference.d.cts +4 -0
  80. package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
  81. package/__cjs/react/internal/cache/SuspenseCache.d.cts +1 -1
  82. package/__cjs/react/internal/cache/types.d.cts +2 -2
  83. package/__cjs/react/ssr/useSSRQuery.cjs +1 -0
  84. package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
  85. package/__cjs/react/types/types.documentation.d.cts +4 -16
  86. package/__cjs/testing/core/mocking/mockLink.cjs +2 -2
  87. package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
  88. package/__cjs/testing/core/mocking/mockLink.d.cts +3 -1
  89. package/__cjs/utilities/DeepPartial.cjs.map +1 -1
  90. package/__cjs/utilities/DeepPartial.d.cts +1 -1
  91. package/__cjs/utilities/internal/combineLatestBatched.cjs +71 -0
  92. package/__cjs/utilities/internal/combineLatestBatched.cjs.map +1 -0
  93. package/__cjs/utilities/internal/combineLatestBatched.d.cts +14 -0
  94. package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
  95. package/__cjs/utilities/internal/index.cjs +4 -2
  96. package/__cjs/utilities/internal/index.cjs.map +1 -1
  97. package/__cjs/utilities/internal/index.d.cts +1 -0
  98. package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +1 -1
  99. package/__cjs/version.cjs +1 -1
  100. package/cache/core/cache.d.ts +72 -23
  101. package/cache/core/cache.js +151 -53
  102. package/cache/core/cache.js.map +1 -1
  103. package/cache/core/types/common.d.ts +1 -1
  104. package/cache/core/types/common.js.map +1 -1
  105. package/cache/inmemory/fragmentRegistry.js +1 -1
  106. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  107. package/cache/inmemory/inMemoryCache.js +12 -1
  108. package/cache/inmemory/inMemoryCache.js.map +1 -1
  109. package/core/ApolloClient.d.ts +94 -5
  110. package/core/ApolloClient.js +24 -27
  111. package/core/ApolloClient.js.map +1 -1
  112. package/core/ObservableQuery.d.ts +2 -2
  113. package/core/ObservableQuery.js +8 -4
  114. package/core/ObservableQuery.js.map +1 -1
  115. package/core/QueryManager.js +1 -1
  116. package/core/QueryManager.js.map +1 -1
  117. package/dev/setErrorMessageHandler.d.ts +1 -1
  118. package/dev/setErrorMessageHandler.js.map +1 -1
  119. package/incremental/handlers/defer20220824.d.ts +0 -2
  120. package/incremental/handlers/defer20220824.js +6 -2
  121. package/incremental/handlers/defer20220824.js.map +1 -1
  122. package/incremental/handlers/graphql17Alpha9.js +9 -3
  123. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  124. package/link/schema/index.d.ts +1 -1
  125. package/link/schema/index.js +1 -1
  126. package/link/schema/index.js.map +1 -1
  127. package/link/subscriptions/index.js +2 -1
  128. package/link/subscriptions/index.js.map +1 -1
  129. package/masking/internal/types.js.map +1 -1
  130. package/masking/maskDefinition.js +1 -1
  131. package/masking/maskDefinition.js.map +1 -1
  132. package/masking/types.d.ts +2 -1
  133. package/masking/types.js.map +1 -1
  134. package/package.json +1 -1
  135. package/react/hooks/internal/index.d.ts +1 -0
  136. package/react/hooks/internal/index.js +1 -0
  137. package/react/hooks/internal/index.js.map +1 -1
  138. package/react/hooks/internal/useDeepMemo.js +2 -0
  139. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  140. package/react/hooks/internal/useRenderGuard.js +1 -1
  141. package/react/hooks/internal/useRenderGuard.js.map +1 -1
  142. package/react/hooks/internal/useSuspenseHookCacheKey.d.ts +11 -0
  143. package/react/hooks/internal/useSuspenseHookCacheKey.js +24 -0
  144. package/react/hooks/internal/useSuspenseHookCacheKey.js.map +1 -0
  145. package/react/hooks/useBackgroundQuery.js +4 -12
  146. package/react/hooks/useBackgroundQuery.js.map +1 -1
  147. package/react/hooks/useFragment.d.ts +65 -6
  148. package/react/hooks/useFragment.js +38 -87
  149. package/react/hooks/useFragment.js.map +1 -1
  150. package/react/hooks/useLazyQuery.d.ts +1 -1
  151. package/react/hooks/useLazyQuery.js +2 -0
  152. package/react/hooks/useLazyQuery.js.map +1 -1
  153. package/react/hooks/useMutation.d.ts +3 -1
  154. package/react/hooks/useQuery.d.ts +1 -1
  155. package/react/hooks/useQuery.js +1 -4
  156. package/react/hooks/useQuery.js.map +1 -1
  157. package/react/hooks/useQueryRefHandlers.js +1 -3
  158. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  159. package/react/hooks/useReactiveVar.d.ts +2 -1
  160. package/react/hooks/useReactiveVar.js +2 -1
  161. package/react/hooks/useReactiveVar.js.map +1 -1
  162. package/react/hooks/useReadQuery.d.ts +1 -1
  163. package/react/hooks/useReadQuery.js +1 -3
  164. package/react/hooks/useReadQuery.js.map +1 -1
  165. package/react/hooks/useSubscription.js +1 -1
  166. package/react/hooks/useSubscription.js.map +1 -1
  167. package/react/hooks/useSuspenseFragment.d.ts +33 -7
  168. package/react/hooks/useSuspenseFragment.js +17 -17
  169. package/react/hooks/useSuspenseFragment.js.map +1 -1
  170. package/react/hooks/useSuspenseQuery.d.ts +1 -1
  171. package/react/hooks/useSuspenseQuery.js +7 -13
  172. package/react/hooks/useSuspenseQuery.js.map +1 -1
  173. package/react/hooks/useSyncExternalStore.js +1 -1
  174. package/react/hooks/useSyncExternalStore.js.map +1 -1
  175. package/react/hooks-compiled/internal/index.d.ts +1 -0
  176. package/react/hooks-compiled/internal/index.js +1 -0
  177. package/react/hooks-compiled/internal/index.js.map +1 -1
  178. package/react/hooks-compiled/internal/useDeepMemo.js +2 -0
  179. package/react/hooks-compiled/internal/useDeepMemo.js.map +1 -1
  180. package/react/hooks-compiled/internal/useRenderGuard.js +1 -1
  181. package/react/hooks-compiled/internal/useRenderGuard.js.map +1 -1
  182. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.d.ts +11 -0
  183. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js +71 -0
  184. package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js.map +1 -0
  185. package/react/hooks-compiled/useBackgroundQuery.js +6 -14
  186. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  187. package/react/hooks-compiled/useFragment.d.ts +65 -6
  188. package/react/hooks-compiled/useFragment.js +110 -88
  189. package/react/hooks-compiled/useFragment.js.map +1 -1
  190. package/react/hooks-compiled/useLazyQuery.d.ts +1 -1
  191. package/react/hooks-compiled/useLazyQuery.js +2 -0
  192. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  193. package/react/hooks-compiled/useLoadableQuery.js +69 -75
  194. package/react/hooks-compiled/useMutation.d.ts +3 -1
  195. package/react/hooks-compiled/useMutation.js +0 -12
  196. package/react/hooks-compiled/useMutation.js.map +1 -1
  197. package/react/hooks-compiled/useQuery.d.ts +1 -1
  198. package/react/hooks-compiled/useQuery.js +44 -56
  199. package/react/hooks-compiled/useQuery.js.map +1 -1
  200. package/react/hooks-compiled/useQueryRefHandlers.js +1 -5
  201. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  202. package/react/hooks-compiled/useReactiveVar.d.ts +2 -1
  203. package/react/hooks-compiled/useReactiveVar.js +2 -1
  204. package/react/hooks-compiled/useReactiveVar.js.map +1 -1
  205. package/react/hooks-compiled/useReadQuery.d.ts +1 -1
  206. package/react/hooks-compiled/useReadQuery.js +77 -14
  207. package/react/hooks-compiled/useReadQuery.js.map +1 -1
  208. package/react/hooks-compiled/useSubscription.js +237 -93
  209. package/react/hooks-compiled/useSubscription.js.map +1 -1
  210. package/react/hooks-compiled/useSuspenseFragment.d.ts +33 -7
  211. package/react/hooks-compiled/useSuspenseFragment.js +17 -17
  212. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  213. package/react/hooks-compiled/useSuspenseQuery.d.ts +1 -1
  214. package/react/hooks-compiled/useSuspenseQuery.js +9 -19
  215. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  216. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  217. package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
  218. package/react/index.compiled.d.ts +1 -1
  219. package/react/index.compiled.js +1 -1
  220. package/react/index.compiled.js.map +1 -1
  221. package/react/internal/cache/FragmentReference.d.ts +2 -4
  222. package/react/internal/cache/FragmentReference.js +3 -22
  223. package/react/internal/cache/FragmentReference.js.map +1 -1
  224. package/react/internal/cache/QueryReference.d.ts +4 -0
  225. package/react/internal/cache/QueryReference.js +1 -1
  226. package/react/internal/cache/QueryReference.js.map +1 -1
  227. package/react/internal/cache/SuspenseCache.d.ts +1 -1
  228. package/react/internal/cache/SuspenseCache.js.map +1 -1
  229. package/react/internal/cache/types.d.ts +2 -2
  230. package/react/internal/cache/types.js.map +1 -1
  231. package/react/ssr/useSSRQuery.js +1 -0
  232. package/react/ssr/useSSRQuery.js.map +1 -1
  233. package/react/types/types.documentation.d.ts +4 -16
  234. package/react/types/types.documentation.js.map +1 -1
  235. package/testing/core/mocking/mockLink.d.ts +3 -1
  236. package/testing/core/mocking/mockLink.js +2 -2
  237. package/testing/core/mocking/mockLink.js.map +1 -1
  238. package/utilities/DeepPartial.d.ts +1 -1
  239. package/utilities/DeepPartial.js.map +1 -1
  240. package/utilities/internal/combineLatestBatched.d.ts +14 -0
  241. package/utilities/internal/combineLatestBatched.js +68 -0
  242. package/utilities/internal/combineLatestBatched.js.map +1 -0
  243. package/utilities/internal/getMemoryInternals.js.map +1 -1
  244. package/utilities/internal/globals/global.js +2 -2
  245. package/utilities/internal/globals/global.js.map +1 -1
  246. package/utilities/internal/index.d.ts +1 -0
  247. package/utilities/internal/index.js +1 -0
  248. package/utilities/internal/index.js.map +1 -1
  249. package/utilities/internal/types/DocumentationTypes.d.ts +1 -1
  250. package/version.js +1 -1
@@ -1,10 +1,11 @@
1
+ import type { DocumentTypeDecoration } from "@graphql-typed-document-node/core";
1
2
  import type { TypeOverrides } from "@apollo/client";
2
3
  import type { ApplyHKTImplementationWithDefault } from "@apollo/client/utilities/internal";
3
4
  import type { PreserveTypes } from "./PreserveTypes.js";
4
5
  /**
5
6
  * Type used with [fragments](https://apollographql.com/docs/react/data/fragments#using-with-fragments) to ensure parent objects contain the fragment spread from the type.
6
7
  */
7
- export type FragmentType<TFragmentData> = ApplyHKTImplementationWithDefault<TypeOverrides, "FragmentType", PreserveTypes.TypeOverrides, TFragmentData>;
8
+ export type FragmentType<TFragmentDataOrTypedDocumentNode> = ApplyHKTImplementationWithDefault<TypeOverrides, "FragmentType", PreserveTypes.TypeOverrides, TFragmentDataOrTypedDocumentNode extends (DocumentTypeDecoration<infer TFragmentData, any>) ? TFragmentData : TFragmentDataOrTypedDocumentNode>;
8
9
  /** Unwraps `TData` into its unmasked type. */
9
10
  export type Unmasked<TData> = ApplyHKTImplementationWithDefault<TypeOverrides, "Unmasked", PreserveTypes.TypeOverrides, TData>;
10
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/masking/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypeOverrides } from \"@apollo/client\";\nimport type { ApplyHKTImplementationWithDefault } from \"@apollo/client/utilities/internal\";\n\nimport type { PreserveTypes } from \"./PreserveTypes.js\";\n\n/**\n * Type used with [fragments](https://apollographql.com/docs/react/data/fragments#using-with-fragments) to ensure parent objects contain the fragment spread from the type.\n */\nexport type FragmentType<TFragmentData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"FragmentType\",\n PreserveTypes.TypeOverrides,\n TFragmentData\n>;\n\n/** Unwraps `TData` into its unmasked type. */\nexport type Unmasked<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Unmasked\",\n PreserveTypes.TypeOverrides,\n TData\n>;\n\n/**\n * Returns TData as either masked or unmasked depending on whether masking is\n * enabled.\n */\nexport type MaybeMasked<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"MaybeMasked\",\n PreserveTypes.TypeOverrides,\n TData\n>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/masking/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentTypeDecoration } from \"@graphql-typed-document-node/core\";\n\nimport type { TypeOverrides } from \"@apollo/client\";\nimport type { ApplyHKTImplementationWithDefault } from \"@apollo/client/utilities/internal\";\n\nimport type { PreserveTypes } from \"./PreserveTypes.js\";\n\n/**\n * Type used with [fragments](https://apollographql.com/docs/react/data/fragments#using-with-fragments) to ensure parent objects contain the fragment spread from the type.\n */\nexport type FragmentType<TFragmentDataOrTypedDocumentNode> =\n ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"FragmentType\",\n PreserveTypes.TypeOverrides,\n TFragmentDataOrTypedDocumentNode extends (\n DocumentTypeDecoration<infer TFragmentData, any>\n ) ?\n TFragmentData\n : TFragmentDataOrTypedDocumentNode\n >;\n\n/** Unwraps `TData` into its unmasked type. */\nexport type Unmasked<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"Unmasked\",\n PreserveTypes.TypeOverrides,\n TData\n>;\n\n/**\n * Returns TData as either masked or unmasked depending on whether masking is\n * enabled.\n */\nexport type MaybeMasked<TData> = ApplyHKTImplementationWithDefault<\n TypeOverrides,\n \"MaybeMasked\",\n PreserveTypes.TypeOverrides,\n TData\n>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "4.1.0-alpha.2",
3
+ "version": "4.1.0-alpha.4",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -1,5 +1,6 @@
1
1
  export { useDeepMemo } from "./useDeepMemo.js";
2
2
  export { useRenderGuard } from "./useRenderGuard.js";
3
+ export { useSuspenseHookCacheKey } from "./useSuspenseHookCacheKey.js";
3
4
  export { __use } from "./__use.js";
4
5
  export { wrapHook } from "./wrapHook.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,7 @@
1
1
  // These hooks are used internally and are not exported publicly by the library
2
2
  export { useDeepMemo } from "./useDeepMemo.js";
3
3
  export { useRenderGuard } from "./useRenderGuard.js";
4
+ export { useSuspenseHookCacheKey } from "./useSuspenseHookCacheKey.js";
4
5
  export { __use } from "./__use.js";
5
6
  export { wrapHook } from "./wrapHook.js";
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC","sourcesContent":["// These hooks are used internally and are not exported publicly by the library\nexport { useDeepMemo } from \"./useDeepMemo.js\";\nexport { useRenderGuard } from \"./useRenderGuard.js\";\nexport { __use } from \"./__use.js\";\nexport { wrapHook } from \"./wrapHook.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC","sourcesContent":["// These hooks are used internally and are not exported publicly by the library\nexport { useDeepMemo } from \"./useDeepMemo.js\";\nexport { useRenderGuard } from \"./useRenderGuard.js\";\nexport { useSuspenseHookCacheKey } from \"./useSuspenseHookCacheKey.js\";\nexport { __use } from \"./__use.js\";\nexport { wrapHook } from \"./wrapHook.js\";\n"]}
@@ -2,9 +2,11 @@ import { equal } from "@wry/equality";
2
2
  import * as React from "react";
3
3
  export function useDeepMemo(memoFn, deps) {
4
4
  const ref = React.useRef(void 0);
5
+ // eslint-disable-next-line react-hooks/refs
5
6
  if (!ref.current || !equal(ref.current.deps, deps)) {
6
7
  ref.current = { value: memoFn(), deps };
7
8
  }
9
+ // eslint-disable-next-line react-hooks/refs
8
10
  return ref.current.value;
9
11
  }
10
12
  //# sourceMappingURL=useDeepMemo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDeepMemo.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useDeepMemo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,UAAU,WAAW,CACzB,MAAoB,EACpB,IAAoB;IAEpB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAA0C,KAAK,CAAC,CAAC,CAAC;IAC1E,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;AAC3B,CAAC","sourcesContent":["import { equal } from \"@wry/equality\";\nimport type { DependencyList } from \"react\";\nimport * as React from \"react\";\n\nexport function useDeepMemo<TValue>(\n memoFn: () => TValue,\n deps: DependencyList\n) {\n const ref = React.useRef<{ deps: DependencyList; value: TValue }>(void 0);\n if (!ref.current || !equal(ref.current.deps, deps)) {\n ref.current = { value: memoFn(), deps };\n }\n return ref.current.value;\n}\n"]}
1
+ {"version":3,"file":"useDeepMemo.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useDeepMemo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,UAAU,WAAW,CACzB,MAAoB,EACpB,IAAoB;IAEpB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAA0C,KAAK,CAAC,CAAC,CAAC;IAC1E,4CAA4C;IAC5C,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC;IAC1C,CAAC;IACD,4CAA4C;IAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;AAC3B,CAAC","sourcesContent":["import { equal } from \"@wry/equality\";\nimport type { DependencyList } from \"react\";\nimport * as React from \"react\";\n\nexport function useDeepMemo<TValue>(\n memoFn: () => TValue,\n deps: DependencyList\n) {\n const ref = React.useRef<{ deps: DependencyList; value: TValue }>(void 0);\n // eslint-disable-next-line react-hooks/refs\n if (!ref.current || !equal(ref.current.deps, deps)) {\n ref.current = { value: memoFn(), deps };\n }\n // eslint-disable-next-line react-hooks/refs\n return ref.current.value;\n}\n"]}
@@ -3,7 +3,7 @@ let Ctx;
3
3
  function noop() { }
4
4
  export function useRenderGuard() {
5
5
  if (!Ctx) {
6
- // we want the intialization to be lazy because `createContext` would error on import in a RSC
6
+ // we want the initialization to be lazy because `createContext` would error on import in a RSC
7
7
  Ctx = React.createContext(null);
8
8
  }
9
9
  return React.useCallback(
@@ -1 +1 @@
1
- {"version":3,"file":"useRenderGuard.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useRenderGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,IAAI,GAAwB,CAAC;AAE7B,SAAS,IAAI,KAAI,CAAC;AAClB,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,8FAA8F;QAC9F,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC,WAAW;IACtB;;OAEG,CAAC,GAAG,EAAE;QACP,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC;YACH,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YAErB;;;;;;;;;;;;;;eAcG;YACH,KAAK,CAAC,YAAY,CAAC,+BAA+B,CAAC,CAAC,GAAG,CAAC,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;QACvB,CAAC;IACH,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nlet Ctx: React.Context<null>;\n\nfunction noop() {}\nexport function useRenderGuard() {\n if (!Ctx) {\n // we want the intialization to be lazy because `createContext` would error on import in a RSC\n Ctx = React.createContext(null);\n }\n\n return React.useCallback(\n /**\n * @returns true if the hook was called during render\n */ () => {\n const orig = console.error;\n try {\n console.error = noop;\n\n /**\n * `useContext` can be called conditionally during render, so this is safe.\n * (Also, during render we would want to throw as a reaction to this anyways, so it\n * wouldn't even matter if we got the order of hooks mixed up...)\n *\n * They cannot however be called outside of Render, and that's what we're testing here.\n *\n * Different versions of React have different behaviour on an invalid hook call:\n *\n * React 16.8 - 17: throws an error\n * https://github.com/facebook/react/blob/2b93d686e359c7afa299e2ec5cf63160a32a1155/packages/react/src/ReactHooks.js#L18-L26\n *\n * React 18 & 19: `console.error` in development, then `resolveDispatcher` returns `null` and a member access on `null` throws.\n * https://github.com/facebook/react/blob/58e8304483ebfadd02a295339b5e9a989ac98c6e/packages/react/src/ReactHooks.js#L28-L35\n */\n React[\"useContext\" /* hide this from the linter */](Ctx);\n return true;\n } catch (e) {\n return false;\n } finally {\n console.error = orig;\n }\n },\n []\n );\n}\n"]}
1
+ {"version":3,"file":"useRenderGuard.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useRenderGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,IAAI,GAAwB,CAAC;AAE7B,SAAS,IAAI,KAAI,CAAC;AAClB,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,+FAA+F;QAC/F,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC,WAAW;IACtB;;OAEG,CAAC,GAAG,EAAE;QACP,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC;YACH,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YAErB;;;;;;;;;;;;;;eAcG;YACH,KAAK,CAAC,YAAY,CAAC,+BAA+B,CAAC,CAAC,GAAG,CAAC,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;QACvB,CAAC;IACH,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nlet Ctx: React.Context<null>;\n\nfunction noop() {}\nexport function useRenderGuard() {\n if (!Ctx) {\n // we want the initialization to be lazy because `createContext` would error on import in a RSC\n Ctx = React.createContext(null);\n }\n\n return React.useCallback(\n /**\n * @returns true if the hook was called during render\n */ () => {\n const orig = console.error;\n try {\n console.error = noop;\n\n /**\n * `useContext` can be called conditionally during render, so this is safe.\n * (Also, during render we would want to throw as a reaction to this anyways, so it\n * wouldn't even matter if we got the order of hooks mixed up...)\n *\n * They cannot however be called outside of Render, and that's what we're testing here.\n *\n * Different versions of React have different behaviour on an invalid hook call:\n *\n * React 16.8 - 17: throws an error\n * https://github.com/facebook/react/blob/2b93d686e359c7afa299e2ec5cf63160a32a1155/packages/react/src/ReactHooks.js#L18-L26\n *\n * React 18 & 19: `console.error` in development, then `resolveDispatcher` returns `null` and a member access on `null` throws.\n * https://github.com/facebook/react/blob/58e8304483ebfadd02a295339b5e9a989ac98c6e/packages/react/src/ReactHooks.js#L28-L35\n */\n React[\"useContext\" /* hide this from the linter */](Ctx);\n return true;\n } catch (e) {\n return false;\n } finally {\n console.error = orig;\n }\n },\n []\n );\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import type { DocumentNode } from "graphql";
2
+ import type { OperationVariables } from "@apollo/client";
3
+ import type { SkipToken } from "../constants.js";
4
+ export declare namespace useSuspenseHookCacheKey {
5
+ interface Options {
6
+ variables?: OperationVariables;
7
+ queryKey?: string | number | any[];
8
+ }
9
+ }
10
+ export declare function useSuspenseHookCacheKey(query: DocumentNode, options: (SkipToken & Partial<useSuspenseHookCacheKey.Options>) | useSuspenseHookCacheKey.Options): [DocumentNode, string, ...any[]];
11
+ //# sourceMappingURL=useSuspenseHookCacheKey.d.ts.map
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import { canonicalStringify } from "@apollo/client/utilities";
3
+ import { skipToken } from "../constants.js";
4
+ export function useSuspenseHookCacheKey(query, options) {
5
+ const { queryKey = [], variables } = options;
6
+ const canonicalVariables = canonicalStringify(variables);
7
+ // This state value let's us maintain the variables used for the cache key
8
+ // when `skipToken` is used to skip a query after its been executed.
9
+ // Since options aren't provided when using `skipToken`, `variables` would
10
+ // otherwise disappear which means we'd return a new cache key without a
11
+ // variables value which creates a new `ObservableQuery` instance. This was
12
+ // particularly problematic when `refetchQueries` was used because it meant
13
+ // refetching against an `ObservableQuery` instance that had no variables.
14
+ let [cacheKeyVariables, setCacheKeyVariables] = React.useState(canonicalVariables);
15
+ if (options !== skipToken && cacheKeyVariables !== canonicalVariables) {
16
+ setCacheKeyVariables((cacheKeyVariables = canonicalVariables));
17
+ }
18
+ return [
19
+ query,
20
+ cacheKeyVariables,
21
+ ...[].concat(queryKey),
22
+ ];
23
+ }
24
+ //# sourceMappingURL=useSuspenseHookCacheKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSuspenseHookCacheKey.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useSuspenseHookCacheKey.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,UAAU,uBAAuB,CACrC,KAAmB,EACnB,OAEmC;IAEnC,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC7C,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEzD,0EAA0E;IAC1E,oEAAoE;IACpE,0EAA0E;IAC1E,wEAAwE;IACxE,2EAA2E;IAC3E,2EAA2E;IAC3E,0EAA0E;IAC1E,IAAI,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAC3C,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAErC,IAAI,OAAO,KAAK,SAAS,IAAI,iBAAiB,KAAK,kBAAkB,EAAE,CAAC;QACtE,oBAAoB,CAAC,CAAC,iBAAiB,GAAG,kBAAkB,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,OAAO;QACL,KAAK;QACL,iBAAiB;QACjB,GAAI,EAAY,CAAC,MAAM,CAAC,QAAQ,CAAC;KACf,CAAC;AACvB,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport * as React from \"react\";\n\nimport type { OperationVariables } from \"@apollo/client\";\nimport type { CacheKey } from \"@apollo/client/react/internal\";\nimport { canonicalStringify } from \"@apollo/client/utilities\";\n\nimport type { SkipToken } from \"../constants.js\";\nimport { skipToken } from \"../constants.js\";\n\nexport declare namespace useSuspenseHookCacheKey {\n export interface Options {\n variables?: OperationVariables;\n queryKey?: string | number | any[];\n }\n}\n\nexport function useSuspenseHookCacheKey(\n query: DocumentNode,\n options:\n | (SkipToken & Partial<useSuspenseHookCacheKey.Options>)\n | useSuspenseHookCacheKey.Options\n) {\n const { queryKey = [], variables } = options;\n const canonicalVariables = canonicalStringify(variables);\n\n // This state value let's us maintain the variables used for the cache key\n // when `skipToken` is used to skip a query after its been executed.\n // Since options aren't provided when using `skipToken`, `variables` would\n // otherwise disappear which means we'd return a new cache key without a\n // variables value which creates a new `ObservableQuery` instance. This was\n // particularly problematic when `refetchQueries` was used because it meant\n // refetching against an `ObservableQuery` instance that had no variables.\n let [cacheKeyVariables, setCacheKeyVariables] =\n React.useState(canonicalVariables);\n\n if (options !== skipToken && cacheKeyVariables !== canonicalVariables) {\n setCacheKeyVariables((cacheKeyVariables = canonicalVariables));\n }\n\n return [\n query,\n cacheKeyVariables,\n ...([] as any[]).concat(queryKey),\n ] satisfies CacheKey;\n}\n"]}
@@ -1,21 +1,18 @@
1
1
  import * as React from "react";
2
- import { canonicalStringify } from "@apollo/client/cache";
3
2
  import { getSuspenseCache, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "@apollo/client/react/internal";
4
- import { wrapHook } from "./internal/index.js";
3
+ import { useSuspenseHookCacheKey, wrapHook } from "./internal/index.js";
5
4
  import { useApolloClient } from "./useApolloClient.js";
6
5
  import { useWatchQueryOptions } from "./useSuspenseQuery.js";
7
6
  export function useBackgroundQuery(query, options) {
8
7
  "use no memo";
9
- return wrapHook("useBackgroundQuery",
10
- // eslint-disable-next-line react-compiler/react-compiler
11
- useBackgroundQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options ?? {});
8
+ return wrapHook("useBackgroundQuery", useBackgroundQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options ?? {});
12
9
  }
13
10
  function useBackgroundQuery_(query, options) {
14
11
  const client = useApolloClient(options.client);
15
12
  const suspenseCache = getSuspenseCache(client);
16
13
  const watchQueryOptions = useWatchQueryOptions({ client, query, options });
17
- const { fetchPolicy, variables } = watchQueryOptions;
18
- const { queryKey = [] } = options;
14
+ const { fetchPolicy } = watchQueryOptions;
15
+ const cacheKey = useSuspenseHookCacheKey(query, options);
19
16
  // This ref tracks the first time query execution is enabled to determine
20
17
  // whether to return a query ref or `undefined`. When initialized
21
18
  // in a skipped state (either via `skip: true` or `skipToken`) we return
@@ -24,11 +21,6 @@ function useBackgroundQuery_(query, options) {
24
21
  // skipped again later.
25
22
  const didFetchResult = React.useRef(fetchPolicy !== "standby");
26
23
  didFetchResult.current ||= fetchPolicy !== "standby";
27
- const cacheKey = [
28
- query,
29
- canonicalStringify(variables),
30
- ...[].concat(queryKey),
31
- ];
32
24
  const queryRef = suspenseCache.getQueryRef(cacheKey, () => client.watchQuery(watchQueryOptions));
33
25
  const [wrappedQueryRef, setWrappedQueryRef] = React.useState(wrapQueryRef(queryRef));
34
26
  if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {
@@ -1 +1 @@
1
- {"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport { canonicalStringify } from \"@apollo/client/cache\";\nimport type { QueryRef } from \"@apollo/client/react\";\nimport type {\n CacheKey,\n FetchMoreFunction,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\n\nexport declare namespace useBackgroundQuery {\n import _self = useBackgroundQuery;\n export type FetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n >;\n\n export namespace Base {\n export interface Options {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: FetchPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#queryKey:member} */\n queryKey?: string | number | any[];\n\n /**\n * {@inheritDoc @apollo/client!QueryOptionsDocumentation#skip_deprecated:member}\n *\n * @example Recommended usage of `skipToken`:\n *\n * ```ts\n * import { skipToken, useBackgroundQuery } from \"@apollo/client\";\n *\n * const [queryRef] = useBackgroundQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#refetch:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n refetch: RefetchFunction<TData, TVariables>;\n }\n\n namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Result<TData, TVariables> {}\n }\n }\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\n export function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n}\n\n/**\n * For a detailed explanation of useBackgroundQuery, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @returns A tuple containing:\n *\n * 1. A `QueryRef` that can be passed to `useReadQuery` to read the query result. The `queryRef` is `undefined` if the query is skipped.\n * 2. An object containing helper functions for the query:\n * - `refetch`: A function to re-execute the query\n * - `fetchMore`: A function to fetch more results for pagination\n * - `subscribeToMore`: A function to subscribe to updates\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\";\n * import { useBackgroundQuery, useReadQuery } from \"@apollo/client/react\";\n *\n * const query = gql`\n * foo {\n * bar\n * }\n * `;\n *\n * const client = new ApolloClient({\n * link: new HttpLink({ uri: \"http://localhost:4000/graphql\" }),\n * cache: new InMemoryCache(),\n * });\n *\n * function SuspenseFallback() {\n * return <div>Loading...</div>;\n * }\n *\n * function Child({ queryRef }) {\n * const { data } = useReadQuery(queryRef);\n *\n * return <div>{data.foo.bar}</div>;\n * }\n *\n * function Parent() {\n * const [queryRef] = useBackgroundQuery(query);\n *\n * return (\n * <Suspense fallback={<SuspenseFallback />}>\n * <Child queryRef={queryRef} />\n * </Suspense>\n * );\n * }\n *\n * function App() {\n * return (\n * <ApolloProvider client={client}>\n * <Parent />\n * </ApolloProvider>\n * );\n * }\n * ```\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - An optional object containing options for the query. Instead of passing a `useBackgroundQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useBackgroundQuery` hook from executing the query or suspending.\n */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n /** @deprecated `returnPartialData` has no effect on `no-cache` queries */\n returnPartialData: boolean;\n fetchPolicy: \"no-cache\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: false;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, useBackgroundQuery.Result<TData, TVariables>];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n })\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n })\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: useBackgroundQuery.Options<NoInfer<TVariables>>]\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, DataState<TData>[\"dataState\"]> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n \"use no memo\";\n return wrapHook(\n \"useBackgroundQuery\",\n // eslint-disable-next-line react-compiler/react-compiler\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n}\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useBackgroundQuery.Options<NoInfer<TVariables>>>)\n | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, TStates> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef<TData, TStates>(cacheKey, () =>\n client.watchQuery(\n watchQueryOptions as ApolloClient.WatchQueryOptions<any, any>\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
1
+ {"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport type { QueryRef } from \"@apollo/client/react\";\nimport type {\n FetchMoreFunction,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { useSuspenseHookCacheKey, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\n\nexport declare namespace useBackgroundQuery {\n import _self = useBackgroundQuery;\n export type FetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n >;\n\n export namespace Base {\n export interface Options {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: FetchPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#queryKey:member} */\n queryKey?: string | number | any[];\n\n /**\n * {@inheritDoc @apollo/client!QueryOptionsDocumentation#skip_deprecated:member}\n *\n * @example Recommended usage of `skipToken`:\n *\n * ```ts\n * import { skipToken, useBackgroundQuery } from \"@apollo/client\";\n *\n * const [queryRef] = useBackgroundQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#refetch:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n refetch: RefetchFunction<TData, TVariables>;\n }\n\n namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Result<TData, TVariables> {}\n }\n }\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\n export function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n}\n\n/**\n * For a detailed explanation of useBackgroundQuery, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @returns A tuple containing:\n *\n * 1. A `QueryRef` that can be passed to `useReadQuery` to read the query result. The `queryRef` is `undefined` if the query is skipped.\n * 2. An object containing helper functions for the query:\n * - `refetch`: A function to re-execute the query\n * - `fetchMore`: A function to fetch more results for pagination\n * - `subscribeToMore`: A function to subscribe to updates\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\";\n * import { useBackgroundQuery, useReadQuery } from \"@apollo/client/react\";\n *\n * const query = gql`\n * foo {\n * bar\n * }\n * `;\n *\n * const client = new ApolloClient({\n * link: new HttpLink({ uri: \"http://localhost:4000/graphql\" }),\n * cache: new InMemoryCache(),\n * });\n *\n * function SuspenseFallback() {\n * return <div>Loading...</div>;\n * }\n *\n * function Child({ queryRef }) {\n * const { data } = useReadQuery(queryRef);\n *\n * return <div>{data.foo.bar}</div>;\n * }\n *\n * function Parent() {\n * const [queryRef] = useBackgroundQuery(query);\n *\n * return (\n * <Suspense fallback={<SuspenseFallback />}>\n * <Child queryRef={queryRef} />\n * </Suspense>\n * );\n * }\n *\n * function App() {\n * return (\n * <ApolloProvider client={client}>\n * <Parent />\n * </ApolloProvider>\n * );\n * }\n * ```\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - An optional object containing options for the query. Instead of passing a `useBackgroundQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useBackgroundQuery` hook from executing the query or suspending.\n */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n /** @deprecated `returnPartialData` has no effect on `no-cache` queries */\n returnPartialData: boolean;\n fetchPolicy: \"no-cache\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: false;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, useBackgroundQuery.Result<TData, TVariables>];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n })\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n })\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: useBackgroundQuery.Options<NoInfer<TVariables>>]\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, DataState<TData>[\"dataState\"]> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n \"use no memo\";\n return wrapHook(\n \"useBackgroundQuery\",\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n}\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useBackgroundQuery.Options<NoInfer<TVariables>>>)\n | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, TStates> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy } = watchQueryOptions;\n const cacheKey = useSuspenseHookCacheKey(query, options);\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const queryRef = suspenseCache.getQueryRef<TData, TStates>(cacheKey, () =>\n client.watchQuery(\n watchQueryOptions as ApolloClient.WatchQueryOptions<any, any>\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { ApolloClient, DataValue, DocumentNode, GetDataState, OperationVariables, TypedDocumentNode } from "@apollo/client";
2
- import type { MissingTree, Reference, StoreObject } from "@apollo/client/cache";
3
- import type { FragmentType, MaybeMasked } from "@apollo/client/masking";
2
+ import type { ApolloCache, MissingTree } from "@apollo/client/cache";
3
+ import type { MaybeMasked } from "@apollo/client/masking";
4
4
  import type { NoInfer } from "@apollo/client/utilities/internal";
5
5
  export declare namespace useFragment {
6
6
  import _self = useFragment;
@@ -23,9 +23,11 @@ export declare namespace useFragment {
23
23
  */
24
24
  variables?: NoInfer<TVariables>;
25
25
  /**
26
- * An object containing a `__typename` and primary key fields (such as `id`) identifying the entity object from which the fragment will be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID (uncommon).
26
+ * An object or array containing a `__typename` and primary key fields
27
+ * (such as `id`) identifying the entity object from which the fragment will
28
+ * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID (uncommon).
27
29
  */
28
- from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string | null;
30
+ from: useFragment.FromValue<TData> | Array<useFragment.FromValue<TData>>;
29
31
  /**
30
32
  * Whether to read from optimistic or non-optimistic cache data. If
31
33
  * this named option is provided, the optimistic parameter of the
@@ -50,6 +52,10 @@ export declare namespace useFragment {
50
52
  }
51
53
  }
52
54
  }
55
+ /**
56
+ * Acceptable values provided to the `from` option.
57
+ */
58
+ type FromValue<TData> = ApolloCache.WatchFragmentFromValue<TData>;
53
59
  type Result<TData> = ({
54
60
  /**
55
61
  *
@@ -59,7 +65,7 @@ export declare namespace useFragment {
59
65
  * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.
60
66
  */
61
67
  missing?: never;
62
- } & GetDataState<MaybeMasked<TData>, "complete">) | ({
68
+ } & GetDataState<MaybeMasked<TData>, "complete">) | {
63
69
  /**
64
70
  *
65
71
  */
@@ -68,7 +74,30 @@ export declare namespace useFragment {
68
74
  * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.
69
75
  */
70
76
  missing?: MissingTree;
71
- } & GetDataState<MaybeMasked<TData>, "partial">);
77
+ /**
78
+ * An object containing the result of your GraphQL query after it completes.
79
+ *
80
+ * This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
81
+ *
82
+ * @docGroup 1. Operation data
83
+ */
84
+ data: TData extends Array<infer TItem> ? Array<DataValue.Partial<TItem> | null> : DataValue.Partial<TData>;
85
+ /**
86
+ * Describes the completeness of `data`.
87
+ *
88
+ * - `empty`: No data could be fulfilled from the cache or the result is
89
+ * incomplete. `data` is `undefined`.
90
+ * - `partial`: Some data could be fulfilled from the cache but `data` is
91
+ * incomplete. This is only possible when `returnPartialData` is `true`.
92
+ * - `streaming`: `data` is incomplete as a result of a deferred query and
93
+ * the result is still streaming in.
94
+ * - `complete`: `data` is a fully satisfied query result fulfilled
95
+ * either from the cache or network.
96
+ *
97
+ * @docGroup 1. Operation data
98
+ */
99
+ dataState: "partial";
100
+ };
72
101
  namespace DocumentationTypes {
73
102
  namespace useFragment {
74
103
  interface Result<TData> {
@@ -99,5 +128,35 @@ export declare namespace useFragment {
99
128
  *
100
129
  * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.
101
130
  */
131
+ export declare function useFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: useFragment.Options<TData, TVariables> & {
132
+ from: Array<NonNullable<useFragment.FromValue<TData>>>;
133
+ }): useFragment.Result<Array<TData>>;
134
+ /**
135
+ * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.
136
+ *
137
+ * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.
138
+ *
139
+ * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.
140
+ */
141
+ export declare function useFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: useFragment.Options<TData, TVariables> & {
142
+ from: Array<null>;
143
+ }): useFragment.Result<Array<null>>;
144
+ /**
145
+ * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.
146
+ *
147
+ * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.
148
+ *
149
+ * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.
150
+ */
151
+ export declare function useFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: useFragment.Options<TData, TVariables> & {
152
+ from: Array<useFragment.FromValue<TData>>;
153
+ }): useFragment.Result<Array<TData | null>>;
154
+ /**
155
+ * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.
156
+ *
157
+ * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.
158
+ *
159
+ * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.
160
+ */
102
161
  export declare function useFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;
103
162
  //# sourceMappingURL=useFragment.d.ts.map
@@ -1,103 +1,54 @@
1
- import { equal } from "@wry/equality";
2
1
  import * as React from "react";
3
2
  import { useDeepMemo, wrapHook } from "./internal/index.js";
4
3
  import { useApolloClient } from "./useApolloClient.js";
5
4
  import { useSyncExternalStore } from "./useSyncExternalStore.js";
6
- /**
7
- * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.
8
- *
9
- * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.
10
- *
11
- * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.
12
- */
13
5
  export function useFragment(options) {
14
6
  "use no memo";
15
- return wrapHook("useFragment",
16
- // eslint-disable-next-line react-compiler/react-compiler
17
- useFragment_, useApolloClient(options.client))(options);
7
+ return wrapHook("useFragment", useFragment_, useApolloClient(options.client))(options);
18
8
  }
19
9
  function useFragment_(options) {
20
10
  const client = useApolloClient(options.client);
21
- const { cache } = client;
22
11
  const { from, ...rest } = options;
23
- // We calculate the cache id seperately from `stableOptions` because we don't
24
- // want changes to non key fields in the `from` property to affect
25
- // `stableOptions` and retrigger our subscription. If the cache identifier
26
- // stays the same between renders, we want to reuse the existing subscription.
27
- const id = React.useMemo(() => typeof from === "string" ? from
28
- : from === null ? null
29
- : cache.identify(from), [cache, from]);
30
- const stableOptions = useDeepMemo(() => ({ ...rest, from: id }), [rest, id]);
31
- // Since .next is async, we need to make sure that we
32
- // get the correct diff on the next render given new diffOptions
33
- const diff = React.useMemo(() => {
34
- const { fragment, fragmentName, from, optimistic = true } = stableOptions;
35
- if (from === null) {
36
- return {
37
- result: diffToResult({
38
- result: {},
39
- complete: false,
40
- }),
41
- };
42
- }
43
- const { cache } = client;
44
- const diff = cache.diff({
45
- ...stableOptions,
46
- returnPartialData: true,
47
- id: from,
48
- query: cache["getFragmentDoc"](client["transform"](fragment), fragmentName),
49
- optimistic,
50
- });
51
- return {
52
- result: diffToResult({
53
- ...diff,
54
- result: client["queryManager"].maskFragment({
55
- fragment,
56
- fragmentName,
57
- // TODO: Revert to `diff.result` once `useFragment` supports `null` as
58
- // valid return value
59
- data: diff.result === null ? {} : diff.result,
60
- }),
61
- }),
62
- };
63
- }, [client, stableOptions]);
64
- // Used for both getSnapshot and getServerSnapshot
65
- const getSnapshot = React.useCallback(() => diff.result, [diff]);
66
- return useSyncExternalStore(React.useCallback((forceUpdate) => {
12
+ const { cache } = client;
13
+ // We calculate the cache id seperately because we don't want changes to non
14
+ // key fields in the `from` property to recreate the observable. If the cache
15
+ // identifier stays the same between renders, we want to reuse the existing
16
+ // subscription.
17
+ const ids = useDeepMemo(() => {
18
+ const fromArray = Array.isArray(from) ? from : [from];
19
+ const ids = fromArray.map((value) => typeof value === "string" ? value
20
+ : value === null ? null
21
+ : cache.identify(value));
22
+ return Array.isArray(from) ? ids : ids[0];
23
+ }, [cache, from]);
24
+ const stableOptions = useDeepMemo(() => ({ ...rest, from: ids }), [rest, ids]);
25
+ const observable = React.useMemo(() => client.watchFragment(stableOptions), [client, stableOptions]);
26
+ // Unfortunately we forgot to update the use case of `from: null` on
27
+ // useFragment in 4.0 to match `useSuspenseFragment`. As such, we need to
28
+ // fallback to data: {} with complete: false when `from` is `null` to maintain
29
+ // backwards compatibility. We should plan to change this in v5.
30
+ const getSnapshot = React.useCallback(() => (from === null ? nullResult : observable.getCurrentResult()), [from, observable]);
31
+ return useSyncExternalStore(React.useCallback((update) => {
67
32
  let lastTimeout = 0;
68
- const subscription = stableOptions.from === null ?
69
- null
70
- : client.watchFragment(stableOptions).subscribe({
71
- next: (result) => {
72
- // Avoid unnecessarily rerendering this hook for the initial result
73
- // emitted from watchFragment which should be equal to
74
- // `diff.result`.
75
- if (equal(result, diff.result))
76
- return;
77
- diff.result = result;
78
- // If we get another update before we've re-rendered, bail out of
79
- // the update and try again. This ensures that the relative timing
80
- // between useQuery and useFragment stays roughly the same as
81
- // fixed in https://github.com/apollographql/apollo-client/pull/11083
82
- clearTimeout(lastTimeout);
83
- lastTimeout = setTimeout(forceUpdate);
84
- },
85
- });
33
+ const subscription = observable.subscribe({
34
+ next: () => {
35
+ // If we get another update before we've re-rendered, bail out of
36
+ // the update and try again. This ensures that the relative timing
37
+ // between useQuery and useFragment stays roughly the same as
38
+ // fixed in https://github.com/apollographql/apollo-client/pull/11083
39
+ clearTimeout(lastTimeout);
40
+ lastTimeout = setTimeout(update);
41
+ },
42
+ });
86
43
  return () => {
87
- subscription?.unsubscribe();
44
+ subscription.unsubscribe();
88
45
  clearTimeout(lastTimeout);
89
46
  };
90
- }, [client, stableOptions, diff]), getSnapshot, getSnapshot);
91
- }
92
- function diffToResult(diff) {
93
- const result = {
94
- data: diff.result,
95
- complete: !!diff.complete,
96
- dataState: diff.complete ? "complete" : "partial",
97
- }; // TODO: Remove assertion once useFragment returns null
98
- if (diff.missing) {
99
- result.missing = diff.missing.missing;
100
- }
101
- return result;
47
+ }, [observable]), getSnapshot, getSnapshot);
102
48
  }
49
+ const nullResult = Object.freeze({
50
+ data: {},
51
+ dataState: "partial",
52
+ complete: false,
53
+ });
103
54
  //# sourceMappingURL=useFragment.js.map