@apollo/client 3.8.7 → 3.8.9

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 (614) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +14 -0
  3. package/CHANGELOG.md +3369 -0
  4. package/apollo-client.cjs +356 -354
  5. package/apollo-client.cjs.map +1 -1
  6. package/apollo-client.min.cjs +1 -1
  7. package/cache/cache.cjs +133 -152
  8. package/cache/cache.cjs.map +1 -1
  9. package/cache/cache.cjs.native.js +133 -152
  10. package/cache/core/cache.d.ts +10 -0
  11. package/cache/core/cache.js +17 -5
  12. package/cache/core/cache.js.map +1 -1
  13. package/cache/core/types/Cache.d.ts +1 -1
  14. package/cache/core/types/Cache.js.map +1 -1
  15. package/cache/core/types/DataProxy.d.ts +92 -0
  16. package/cache/core/types/common.js +4 -1
  17. package/cache/core/types/common.js.map +1 -1
  18. package/cache/inmemory/entityStore.d.ts +1 -1
  19. package/cache/inmemory/entityStore.js +190 -29
  20. package/cache/inmemory/entityStore.js.map +1 -1
  21. package/cache/inmemory/fixPolyfills.js +9 -0
  22. package/cache/inmemory/fixPolyfills.js.map +1 -1
  23. package/cache/inmemory/fixPolyfills.native.js +12 -0
  24. package/cache/inmemory/fixPolyfills.native.js.map +1 -1
  25. package/cache/inmemory/fragmentRegistry.js +23 -12
  26. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  27. package/cache/inmemory/helpers.js +20 -11
  28. package/cache/inmemory/helpers.js.map +1 -1
  29. package/cache/inmemory/inMemoryCache.js +161 -8
  30. package/cache/inmemory/inMemoryCache.js.map +1 -1
  31. package/cache/inmemory/key-extractor.js +72 -4
  32. package/cache/inmemory/key-extractor.js.map +1 -1
  33. package/cache/inmemory/object-canon.js +91 -3
  34. package/cache/inmemory/object-canon.js.map +1 -1
  35. package/cache/inmemory/policies.js +193 -43
  36. package/cache/inmemory/policies.js.map +1 -1
  37. package/cache/inmemory/reactiveVars.js +20 -2
  38. package/cache/inmemory/reactiveVars.js.map +1 -1
  39. package/cache/inmemory/readFromStore.d.ts +4 -0
  40. package/cache/inmemory/readFromStore.js +54 -9
  41. package/cache/inmemory/readFromStore.js.map +1 -1
  42. package/cache/inmemory/types.d.ts +28 -0
  43. package/cache/inmemory/types.js.map +1 -1
  44. package/cache/inmemory/writeToStore.js +152 -25
  45. package/cache/inmemory/writeToStore.js.map +1 -1
  46. package/config/jest/setup.js +2 -0
  47. package/config/jest/setup.js.map +1 -1
  48. package/core/ApolloClient.d.ts +264 -3
  49. package/core/ApolloClient.js +235 -7
  50. package/core/ApolloClient.js.map +1 -1
  51. package/core/LocalState.d.ts +4 -6
  52. package/core/LocalState.js +56 -18
  53. package/core/LocalState.js.map +1 -1
  54. package/core/ObservableQuery.d.ts +25 -0
  55. package/core/ObservableQuery.js +239 -30
  56. package/core/ObservableQuery.js.map +1 -1
  57. package/core/QueryInfo.d.ts +3 -3
  58. package/core/QueryInfo.js +116 -13
  59. package/core/QueryInfo.js.map +1 -1
  60. package/core/QueryManager.d.ts +4 -0
  61. package/core/QueryManager.js +229 -33
  62. package/core/QueryManager.js.map +1 -1
  63. package/core/core.cjs +112 -103
  64. package/core/core.cjs.map +1 -1
  65. package/core/core.cjs.native.js +112 -103
  66. package/core/equalByQuery.js +20 -1
  67. package/core/equalByQuery.js.map +1 -1
  68. package/core/index.d.ts +1 -1
  69. package/core/index.js +19 -0
  70. package/core/index.js.map +1 -1
  71. package/core/networkStatus.d.ts +39 -0
  72. package/core/networkStatus.js +39 -0
  73. package/core/networkStatus.js.map +1 -1
  74. package/core/types.d.ts +9 -0
  75. package/core/types.js.map +1 -1
  76. package/core/watchQueryOptions.d.ts +225 -1
  77. package/core/watchQueryOptions.js.map +1 -1
  78. package/dev/dev.cjs +5 -111
  79. package/dev/dev.cjs.map +1 -1
  80. package/dev/dev.cjs.native.js +5 -111
  81. package/dev/loadErrorMessageHandler.js.map +1 -1
  82. package/errors/errors.cjs +1 -1
  83. package/errors/errors.cjs.map +1 -1
  84. package/errors/errors.cjs.native.js +1 -1
  85. package/errors/index.js +14 -1
  86. package/errors/index.js.map +1 -1
  87. package/invariantErrorCodes.js +1 -0
  88. package/link/batch/batch.cjs +2 -2
  89. package/link/batch/batch.cjs.map +1 -1
  90. package/link/batch/batch.cjs.native.js +2 -2
  91. package/link/batch/batchLink.d.ts +21 -0
  92. package/link/batch/batchLink.js +2 -1
  93. package/link/batch/batchLink.js.map +1 -1
  94. package/link/batch/batching.js +24 -1
  95. package/link/batch/batching.js.map +1 -1
  96. package/link/batch-http/batch-http.cjs +3 -2
  97. package/link/batch-http/batch-http.cjs.map +1 -1
  98. package/link/batch-http/batch-http.cjs.native.js +3 -2
  99. package/link/batch-http/batchHttpLink.d.ts +4 -0
  100. package/link/batch-http/batchHttpLink.js +53 -2
  101. package/link/batch-http/batchHttpLink.js.map +1 -1
  102. package/link/context/context.cjs.map +1 -1
  103. package/link/context/index.js +1 -0
  104. package/link/context/index.js.map +1 -1
  105. package/link/core/ApolloLink.js +12 -5
  106. package/link/core/ApolloLink.js.map +1 -1
  107. package/link/core/core.cjs +5 -5
  108. package/link/core/core.cjs.map +1 -1
  109. package/link/core/core.cjs.native.js +5 -5
  110. package/link/error/error.cjs +1 -1
  111. package/link/error/error.cjs.map +1 -1
  112. package/link/error/error.cjs.native.js +1 -1
  113. package/link/error/index.d.ts +3 -0
  114. package/link/error/index.js +4 -1
  115. package/link/error/index.js.map +1 -1
  116. package/link/http/HttpLink.d.ts +0 -2
  117. package/link/http/HttpLink.js +1 -1
  118. package/link/http/HttpLink.js.map +1 -1
  119. package/link/http/checkFetcher.d.ts +1 -1
  120. package/link/http/checkFetcher.js.map +1 -1
  121. package/link/http/createHttpLink.js +23 -1
  122. package/link/http/createHttpLink.js.map +1 -1
  123. package/link/http/createSignalIfSupported.d.ts +5 -0
  124. package/link/http/createSignalIfSupported.js +5 -0
  125. package/link/http/createSignalIfSupported.js.map +1 -1
  126. package/link/http/http.cjs +14 -15
  127. package/link/http/http.cjs.map +1 -1
  128. package/link/http/http.cjs.native.js +14 -15
  129. package/link/http/index.js +2 -1
  130. package/link/http/index.js.map +1 -1
  131. package/link/http/iterators/async.d.ts +4 -0
  132. package/link/http/iterators/async.js +4 -0
  133. package/link/http/iterators/async.js.map +1 -1
  134. package/link/http/iterators/nodeStream.d.ts +4 -0
  135. package/link/http/iterators/nodeStream.js +4 -0
  136. package/link/http/iterators/nodeStream.js.map +1 -1
  137. package/link/http/iterators/promise.d.ts +4 -0
  138. package/link/http/iterators/promise.js +4 -0
  139. package/link/http/iterators/promise.js.map +1 -1
  140. package/link/http/iterators/reader.d.ts +4 -0
  141. package/link/http/iterators/reader.js +4 -0
  142. package/link/http/iterators/reader.js.map +1 -1
  143. package/link/http/parseAndCheckHttpResponse.js +50 -13
  144. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  145. package/link/http/responseIterator.d.ts +4 -0
  146. package/link/http/responseIterator.js +6 -0
  147. package/link/http/responseIterator.js.map +1 -1
  148. package/link/http/rewriteURIForGET.d.ts +1 -1
  149. package/link/http/rewriteURIForGET.js +10 -0
  150. package/link/http/rewriteURIForGET.js.map +1 -1
  151. package/link/http/selectHttpOptionsAndBody.d.ts +46 -1
  152. package/link/http/selectHttpOptionsAndBody.js +23 -0
  153. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  154. package/link/http/selectURI.js.map +1 -1
  155. package/link/http/serializeFetchParameter.js.map +1 -1
  156. package/link/persisted-queries/index.js +34 -4
  157. package/link/persisted-queries/index.js.map +1 -1
  158. package/link/persisted-queries/persisted-queries.cjs +4 -4
  159. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  160. package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
  161. package/link/remove-typename/remove-typename.cjs +12 -9
  162. package/link/remove-typename/remove-typename.cjs.map +1 -1
  163. package/link/remove-typename/remove-typename.cjs.native.js +12 -9
  164. package/link/remove-typename/removeTypenameFromVariables.js +12 -9
  165. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  166. package/link/retry/delayFunction.d.ts +29 -0
  167. package/link/retry/delayFunction.js +6 -0
  168. package/link/retry/delayFunction.js.map +1 -1
  169. package/link/retry/retry.cjs +5 -5
  170. package/link/retry/retry.cjs.map +1 -1
  171. package/link/retry/retry.cjs.native.js +5 -5
  172. package/link/retry/retryFunction.d.ts +20 -0
  173. package/link/retry/retryLink.d.ts +6 -0
  174. package/link/retry/retryLink.js +31 -6
  175. package/link/retry/retryLink.js.map +1 -1
  176. package/link/schema/index.d.ts +13 -0
  177. package/link/schema/index.js +3 -3
  178. package/link/schema/index.js.map +1 -1
  179. package/link/schema/schema.cjs +3 -3
  180. package/link/schema/schema.cjs.map +1 -1
  181. package/link/schema/schema.cjs.native.js +3 -3
  182. package/link/subscriptions/index.js +35 -2
  183. package/link/subscriptions/index.js.map +1 -1
  184. package/link/subscriptions/subscriptions.cjs +3 -2
  185. package/link/subscriptions/subscriptions.cjs.map +1 -1
  186. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  187. package/link/utils/createOperation.js.map +1 -1
  188. package/link/utils/filterOperationVariables.js +4 -0
  189. package/link/utils/filterOperationVariables.js.map +1 -1
  190. package/link/utils/toPromise.js.map +1 -1
  191. package/link/utils/transformOperation.js +3 -2
  192. package/link/utils/transformOperation.js.map +1 -1
  193. package/link/utils/utils.cjs +2 -2
  194. package/link/utils/utils.cjs.map +1 -1
  195. package/link/utils/utils.cjs.native.js +2 -2
  196. package/link/utils/validateOperation.js.map +1 -1
  197. package/link/ws/index.d.ts +12 -0
  198. package/link/ws/index.js +1 -1
  199. package/link/ws/index.js.map +1 -1
  200. package/link/ws/ws.cjs +1 -1
  201. package/link/ws/ws.cjs.map +1 -1
  202. package/link/ws/ws.cjs.native.js +1 -1
  203. package/package.json +56 -45
  204. package/react/cache/QueryReference.d.ts +6 -1
  205. package/react/cache/QueryReference.js +26 -1
  206. package/react/cache/QueryReference.js.map +1 -1
  207. package/react/cache/SuspenseCache.d.ts +10 -0
  208. package/react/cache/SuspenseCache.js +1 -1
  209. package/react/cache/SuspenseCache.js.map +1 -1
  210. package/react/cache/getSuspenseCache.js.map +1 -1
  211. package/react/context/ApolloContext.d.ts +5 -0
  212. package/react/context/ApolloContext.js +10 -3
  213. package/react/context/ApolloContext.js.map +1 -1
  214. package/react/context/context.cjs +1 -3
  215. package/react/context/context.cjs.map +1 -1
  216. package/react/context/context.cjs.native.js +1 -3
  217. package/react/hoc/graphql.js.map +1 -1
  218. package/react/hoc/hoc-utils.js +3 -1
  219. package/react/hoc/hoc-utils.js.map +1 -1
  220. package/react/hoc/hoc.cjs +9 -17
  221. package/react/hoc/hoc.cjs.map +1 -1
  222. package/react/hoc/hoc.cjs.native.js +9 -17
  223. package/react/hoc/mutation-hoc.js +9 -4
  224. package/react/hoc/mutation-hoc.js.map +1 -1
  225. package/react/hoc/query-hoc.js +10 -4
  226. package/react/hoc/query-hoc.js.map +1 -1
  227. package/react/hoc/subscription-hoc.js +10 -4
  228. package/react/hoc/subscription-hoc.js.map +1 -1
  229. package/react/hoc/withApollo.js +3 -4
  230. package/react/hoc/withApollo.js.map +1 -1
  231. package/react/hooks/hooks.cjs +72 -57
  232. package/react/hooks/hooks.cjs.map +1 -1
  233. package/react/hooks/hooks.cjs.native.js +72 -57
  234. package/react/hooks/internal/__use.js +5 -0
  235. package/react/hooks/internal/__use.js.map +1 -1
  236. package/react/hooks/internal/index.d.ts +1 -0
  237. package/react/hooks/internal/index.js +2 -0
  238. package/react/hooks/internal/index.js.map +1 -1
  239. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  240. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  241. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  242. package/react/hooks/internal/useLazyRef.d.ts +3 -0
  243. package/react/hooks/internal/useLazyRef.js +10 -0
  244. package/react/hooks/internal/useLazyRef.js.map +1 -0
  245. package/react/hooks/useBackgroundQuery.js +6 -0
  246. package/react/hooks/useBackgroundQuery.js.map +1 -1
  247. package/react/hooks/useFragment.js +21 -17
  248. package/react/hooks/useFragment.js.map +1 -1
  249. package/react/hooks/useLazyQuery.js +13 -4
  250. package/react/hooks/useLazyQuery.js.map +1 -1
  251. package/react/hooks/useMutation.js +8 -3
  252. package/react/hooks/useMutation.js.map +1 -1
  253. package/react/hooks/useQuery.d.ts +11 -0
  254. package/react/hooks/useQuery.js +137 -5
  255. package/react/hooks/useQuery.js.map +1 -1
  256. package/react/hooks/useReactiveVar.js +5 -0
  257. package/react/hooks/useReactiveVar.js.map +1 -1
  258. package/react/hooks/useReadQuery.d.ts +19 -0
  259. package/react/hooks/useReadQuery.js.map +1 -1
  260. package/react/hooks/useSubscription.js +5 -0
  261. package/react/hooks/useSubscription.js.map +1 -1
  262. package/react/hooks/useSuspenseQuery.js +11 -5
  263. package/react/hooks/useSuspenseQuery.js.map +1 -1
  264. package/react/hooks/useSyncExternalStore.js +53 -1
  265. package/react/hooks/useSyncExternalStore.js.map +1 -1
  266. package/react/parser/index.js +4 -5
  267. package/react/parser/index.js.map +1 -1
  268. package/react/parser/parser.cjs +2 -4
  269. package/react/parser/parser.cjs.map +1 -1
  270. package/react/parser/parser.cjs.native.js +2 -4
  271. package/react/ssr/RenderPromises.js +21 -1
  272. package/react/ssr/RenderPromises.js.map +1 -1
  273. package/react/ssr/getDataFromTree.js +18 -3
  274. package/react/ssr/getDataFromTree.js.map +1 -1
  275. package/react/ssr/ssr.cjs +6 -4
  276. package/react/ssr/ssr.cjs.map +1 -1
  277. package/react/ssr/ssr.cjs.native.js +6 -4
  278. package/react/types/types.d.ts +66 -0
  279. package/testing/core/core.cjs +18 -13
  280. package/testing/core/core.cjs.map +1 -1
  281. package/testing/core/core.cjs.native.js +18 -13
  282. package/testing/core/itAsync.d.ts +1 -1
  283. package/testing/core/itAsync.js.map +1 -1
  284. package/testing/core/mocking/mockFetch.d.ts +2 -2
  285. package/testing/core/mocking/mockFetch.js +8 -4
  286. package/testing/core/mocking/mockFetch.js.map +1 -1
  287. package/testing/core/mocking/mockLink.js +25 -9
  288. package/testing/core/mocking/mockLink.js.map +1 -1
  289. package/testing/core/mocking/mockQueryManager.js +2 -0
  290. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  291. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  292. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  293. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  294. package/testing/core/mocking/mockWatchQuery.js +1 -1
  295. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  296. package/testing/core/observableToPromise.d.ts +17 -3
  297. package/testing/core/observableToPromise.js +5 -0
  298. package/testing/core/observableToPromise.js.map +1 -1
  299. package/testing/core/subscribeAndCount.js +3 -0
  300. package/testing/core/subscribeAndCount.js.map +1 -1
  301. package/testing/core/wait.js +2 -2
  302. package/testing/core/wait.js.map +1 -1
  303. package/testing/core/withConsoleSpy.d.ts +3 -0
  304. package/testing/core/withConsoleSpy.js +7 -1
  305. package/testing/core/withConsoleSpy.js.map +1 -1
  306. package/testing/core/wrap.js +2 -0
  307. package/testing/core/wrap.js.map +1 -1
  308. package/testing/internal/ObservableStream.js +14 -14
  309. package/testing/internal/ObservableStream.js.map +1 -1
  310. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  311. package/testing/internal/disposables/spyOnConsole.js +2 -0
  312. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  313. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  314. package/testing/internal/disposables/withCleanup.js +3 -0
  315. package/testing/internal/disposables/withCleanup.js.map +1 -1
  316. package/testing/internal/profile/Render.d.ts +28 -0
  317. package/testing/internal/profile/Render.js +12 -1
  318. package/testing/internal/profile/Render.js.map +1 -1
  319. package/testing/internal/profile/profile.d.ts +44 -7
  320. package/testing/internal/profile/profile.js +63 -51
  321. package/testing/internal/profile/profile.js.map +1 -1
  322. package/testing/internal/profile/traces.d.ts +4 -0
  323. package/testing/internal/profile/traces.js +9 -5
  324. package/testing/internal/profile/traces.js.map +1 -1
  325. package/testing/matchers/ProfiledComponent.js +27 -22
  326. package/testing/matchers/ProfiledComponent.js.map +1 -1
  327. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  328. package/testing/matchers/toMatchDocument.js.map +1 -1
  329. package/testing/react/MockedProvider.d.ts +4 -0
  330. package/testing/react/MockedProvider.js +6 -2
  331. package/testing/react/MockedProvider.js.map +1 -1
  332. package/testing/testing.cjs +4 -2
  333. package/testing/testing.cjs.map +1 -1
  334. package/testing/testing.cjs.native.js +4 -2
  335. package/utilities/common/arrays.js +1 -0
  336. package/utilities/common/arrays.js.map +1 -1
  337. package/utilities/common/canUse.js +16 -1
  338. package/utilities/common/canUse.js.map +1 -1
  339. package/utilities/common/cloneDeep.d.ts +3 -0
  340. package/utilities/common/cloneDeep.js +5 -0
  341. package/utilities/common/cloneDeep.js.map +1 -1
  342. package/utilities/common/compact.d.ts +4 -0
  343. package/utilities/common/compact.js +4 -0
  344. package/utilities/common/compact.js.map +1 -1
  345. package/utilities/common/errorHandling.js +1 -3
  346. package/utilities/common/errorHandling.js.map +1 -1
  347. package/utilities/common/incrementalResult.js +3 -0
  348. package/utilities/common/incrementalResult.js.map +1 -1
  349. package/utilities/common/makeUniqueId.js +2 -0
  350. package/utilities/common/makeUniqueId.js.map +1 -1
  351. package/utilities/common/maybeDeepFreeze.js +3 -0
  352. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  353. package/utilities/common/mergeDeep.js +12 -1
  354. package/utilities/common/mergeDeep.js.map +1 -1
  355. package/utilities/common/mergeOptions.d.ts +1 -1
  356. package/utilities/common/mergeOptions.js.map +1 -1
  357. package/utilities/common/omitDeep.js.map +1 -1
  358. package/utilities/globals/global.js +7 -1
  359. package/utilities/globals/global.js.map +1 -1
  360. package/utilities/globals/globals.cjs +4 -5
  361. package/utilities/globals/globals.cjs.map +1 -1
  362. package/utilities/globals/globals.cjs.native.js +4 -5
  363. package/utilities/globals/index.d.ts +4 -0
  364. package/utilities/globals/index.js +7 -0
  365. package/utilities/globals/index.js.map +1 -1
  366. package/utilities/globals/invariantWrappers.d.ts +40 -0
  367. package/utilities/globals/invariantWrappers.js +11 -3
  368. package/utilities/globals/invariantWrappers.js.map +1 -1
  369. package/utilities/globals/maybe.js.map +1 -1
  370. package/utilities/graphql/DocumentTransform.js +19 -6
  371. package/utilities/graphql/DocumentTransform.js.map +1 -1
  372. package/utilities/graphql/directives.js +3 -0
  373. package/utilities/graphql/directives.js.map +1 -1
  374. package/utilities/graphql/fragments.d.ts +25 -0
  375. package/utilities/graphql/fragments.js +36 -0
  376. package/utilities/graphql/fragments.js.map +1 -1
  377. package/utilities/graphql/getFromAST.d.ts +5 -0
  378. package/utilities/graphql/getFromAST.js +9 -0
  379. package/utilities/graphql/getFromAST.js.map +1 -1
  380. package/utilities/graphql/print.js.map +1 -1
  381. package/utilities/graphql/storeUtils.d.ts +14 -0
  382. package/utilities/graphql/storeUtils.js +7 -2
  383. package/utilities/graphql/storeUtils.js.map +1 -1
  384. package/utilities/graphql/transform.js +106 -7
  385. package/utilities/graphql/transform.js.map +1 -1
  386. package/utilities/observables/Concast.d.ts +1 -1
  387. package/utilities/observables/Concast.js +84 -1
  388. package/utilities/observables/Concast.js.map +1 -1
  389. package/utilities/observables/Observable.js +6 -0
  390. package/utilities/observables/Observable.js.map +1 -1
  391. package/utilities/observables/asyncMap.js +12 -3
  392. package/utilities/observables/asyncMap.js.map +1 -1
  393. package/utilities/observables/iteration.js +3 -0
  394. package/utilities/observables/iteration.js.map +1 -1
  395. package/utilities/observables/subclassing.js +14 -0
  396. package/utilities/observables/subclassing.js.map +1 -1
  397. package/utilities/policies/pagination.js +47 -3
  398. package/utilities/policies/pagination.js.map +1 -1
  399. package/utilities/promises/decoration.js +1 -0
  400. package/utilities/promises/decoration.js.map +1 -1
  401. package/utilities/types/DeepOmit.js.map +1 -1
  402. package/utilities/types/DeepPartial.d.ts +1 -1
  403. package/utilities/types/DeepPartial.js +4 -0
  404. package/utilities/types/DeepPartial.js.map +1 -1
  405. package/utilities/types/IsStrictlyAny.js.map +1 -1
  406. package/utilities/types/TODO.d.ts +3 -0
  407. package/utilities/types/TODO.js +2 -0
  408. package/utilities/types/TODO.js.map +1 -0
  409. package/utilities/utilities.cjs +31 -27
  410. package/utilities/utilities.cjs.map +1 -1
  411. package/utilities/utilities.cjs.native.js +31 -27
  412. package/version.js +1 -1
  413. package/cache/core/cache.d.ts.map +0 -1
  414. package/cache/core/types/Cache.d.ts.map +0 -1
  415. package/cache/core/types/DataProxy.d.ts.map +0 -1
  416. package/cache/core/types/common.d.ts.map +0 -1
  417. package/cache/index.d.ts.map +0 -1
  418. package/cache/inmemory/entityStore.d.ts.map +0 -1
  419. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  420. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  421. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  422. package/cache/inmemory/helpers.d.ts.map +0 -1
  423. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  424. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  425. package/cache/inmemory/object-canon.d.ts.map +0 -1
  426. package/cache/inmemory/policies.d.ts.map +0 -1
  427. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  428. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  429. package/cache/inmemory/types.d.ts.map +0 -1
  430. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  431. package/config/jest/setup.d.ts.map +0 -1
  432. package/core/ApolloClient.d.ts.map +0 -1
  433. package/core/LocalState.d.ts.map +0 -1
  434. package/core/ObservableQuery.d.ts.map +0 -1
  435. package/core/QueryInfo.d.ts.map +0 -1
  436. package/core/QueryManager.d.ts.map +0 -1
  437. package/core/equalByQuery.d.ts.map +0 -1
  438. package/core/index.d.ts.map +0 -1
  439. package/core/networkStatus.d.ts.map +0 -1
  440. package/core/types.d.ts.map +0 -1
  441. package/core/watchQueryOptions.d.ts.map +0 -1
  442. package/dev/index.d.ts.map +0 -1
  443. package/dev/loadDevMessages.d.ts.map +0 -1
  444. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  445. package/dev/loadErrorMessages.d.ts.map +0 -1
  446. package/errors/index.d.ts.map +0 -1
  447. package/index.d.ts.map +0 -1
  448. package/invariantErrorCodes.d.ts.map +0 -1
  449. package/link/batch/batchLink.d.ts.map +0 -1
  450. package/link/batch/batching.d.ts.map +0 -1
  451. package/link/batch/index.d.ts.map +0 -1
  452. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  453. package/link/batch-http/index.d.ts.map +0 -1
  454. package/link/context/index.d.ts.map +0 -1
  455. package/link/core/ApolloLink.d.ts.map +0 -1
  456. package/link/core/concat.d.ts.map +0 -1
  457. package/link/core/empty.d.ts.map +0 -1
  458. package/link/core/execute.d.ts.map +0 -1
  459. package/link/core/from.d.ts.map +0 -1
  460. package/link/core/index.d.ts.map +0 -1
  461. package/link/core/split.d.ts.map +0 -1
  462. package/link/core/types.d.ts.map +0 -1
  463. package/link/error/index.d.ts.map +0 -1
  464. package/link/http/HttpLink.d.ts.map +0 -1
  465. package/link/http/checkFetcher.d.ts.map +0 -1
  466. package/link/http/createHttpLink.d.ts.map +0 -1
  467. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  468. package/link/http/index.d.ts.map +0 -1
  469. package/link/http/iterators/async.d.ts.map +0 -1
  470. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  471. package/link/http/iterators/promise.d.ts.map +0 -1
  472. package/link/http/iterators/reader.d.ts.map +0 -1
  473. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  474. package/link/http/responseIterator.d.ts.map +0 -1
  475. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  476. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  477. package/link/http/selectURI.d.ts.map +0 -1
  478. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  479. package/link/persisted-queries/index.d.ts.map +0 -1
  480. package/link/remove-typename/index.d.ts.map +0 -1
  481. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  482. package/link/retry/delayFunction.d.ts.map +0 -1
  483. package/link/retry/index.d.ts.map +0 -1
  484. package/link/retry/retryFunction.d.ts.map +0 -1
  485. package/link/retry/retryLink.d.ts.map +0 -1
  486. package/link/schema/index.d.ts.map +0 -1
  487. package/link/subscriptions/index.d.ts.map +0 -1
  488. package/link/utils/createOperation.d.ts.map +0 -1
  489. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  490. package/link/utils/fromError.d.ts.map +0 -1
  491. package/link/utils/fromPromise.d.ts.map +0 -1
  492. package/link/utils/index.d.ts.map +0 -1
  493. package/link/utils/throwServerError.d.ts.map +0 -1
  494. package/link/utils/toPromise.d.ts.map +0 -1
  495. package/link/utils/transformOperation.d.ts.map +0 -1
  496. package/link/utils/validateOperation.d.ts.map +0 -1
  497. package/link/ws/index.d.ts.map +0 -1
  498. package/react/cache/QueryReference.d.ts.map +0 -1
  499. package/react/cache/SuspenseCache.d.ts.map +0 -1
  500. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  501. package/react/cache/index.d.ts.map +0 -1
  502. package/react/cache/types.d.ts.map +0 -1
  503. package/react/components/Mutation.d.ts.map +0 -1
  504. package/react/components/Query.d.ts.map +0 -1
  505. package/react/components/Subscription.d.ts.map +0 -1
  506. package/react/components/index.d.ts.map +0 -1
  507. package/react/components/types.d.ts.map +0 -1
  508. package/react/context/ApolloConsumer.d.ts.map +0 -1
  509. package/react/context/ApolloContext.d.ts.map +0 -1
  510. package/react/context/ApolloProvider.d.ts.map +0 -1
  511. package/react/context/index.d.ts.map +0 -1
  512. package/react/hoc/graphql.d.ts.map +0 -1
  513. package/react/hoc/hoc-utils.d.ts.map +0 -1
  514. package/react/hoc/index.d.ts.map +0 -1
  515. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  516. package/react/hoc/query-hoc.d.ts.map +0 -1
  517. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  518. package/react/hoc/types.d.ts.map +0 -1
  519. package/react/hoc/withApollo.d.ts.map +0 -1
  520. package/react/hooks/constants.d.ts.map +0 -1
  521. package/react/hooks/index.d.ts.map +0 -1
  522. package/react/hooks/internal/__use.d.ts.map +0 -1
  523. package/react/hooks/internal/index.d.ts.map +0 -1
  524. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  525. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  526. package/react/hooks/useApolloClient.d.ts.map +0 -1
  527. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  528. package/react/hooks/useFragment.d.ts.map +0 -1
  529. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  530. package/react/hooks/useMutation.d.ts.map +0 -1
  531. package/react/hooks/useQuery.d.ts.map +0 -1
  532. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  533. package/react/hooks/useReadQuery.d.ts.map +0 -1
  534. package/react/hooks/useSubscription.d.ts.map +0 -1
  535. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  536. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  537. package/react/index.d.ts.map +0 -1
  538. package/react/parser/index.d.ts.map +0 -1
  539. package/react/ssr/RenderPromises.d.ts.map +0 -1
  540. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  541. package/react/ssr/index.d.ts.map +0 -1
  542. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  543. package/react/types/types.d.ts.map +0 -1
  544. package/testing/core/index.d.ts.map +0 -1
  545. package/testing/core/itAsync.d.ts.map +0 -1
  546. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  547. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  548. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  549. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  550. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  551. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  552. package/testing/core/observableToPromise.d.ts.map +0 -1
  553. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  554. package/testing/core/wait.d.ts.map +0 -1
  555. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  556. package/testing/core/wrap.d.ts.map +0 -1
  557. package/testing/index.d.ts.map +0 -1
  558. package/testing/internal/ObservableStream.d.ts.map +0 -1
  559. package/testing/internal/disposables/index.d.ts.map +0 -1
  560. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  561. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  562. package/testing/internal/index.d.ts.map +0 -1
  563. package/testing/internal/profile/Render.d.ts.map +0 -1
  564. package/testing/internal/profile/index.d.ts.map +0 -1
  565. package/testing/internal/profile/profile.d.ts.map +0 -1
  566. package/testing/internal/profile/traces.d.ts.map +0 -1
  567. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  568. package/testing/matchers/index.d.ts.map +0 -1
  569. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  570. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  571. package/testing/react/MockedProvider.d.ts.map +0 -1
  572. package/utilities/common/arrays.d.ts.map +0 -1
  573. package/utilities/common/canUse.d.ts.map +0 -1
  574. package/utilities/common/cloneDeep.d.ts.map +0 -1
  575. package/utilities/common/compact.d.ts.map +0 -1
  576. package/utilities/common/errorHandling.d.ts.map +0 -1
  577. package/utilities/common/filterInPlace.d.ts +0 -2
  578. package/utilities/common/filterInPlace.d.ts.map +0 -1
  579. package/utilities/common/filterInPlace.js +0 -11
  580. package/utilities/common/filterInPlace.js.map +0 -1
  581. package/utilities/common/incrementalResult.d.ts.map +0 -1
  582. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  583. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  584. package/utilities/common/mergeDeep.d.ts.map +0 -1
  585. package/utilities/common/mergeOptions.d.ts.map +0 -1
  586. package/utilities/common/objects.d.ts.map +0 -1
  587. package/utilities/common/omitDeep.d.ts.map +0 -1
  588. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  589. package/utilities/common/stripTypename.d.ts.map +0 -1
  590. package/utilities/globals/global.d.ts.map +0 -1
  591. package/utilities/globals/index.d.ts.map +0 -1
  592. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  593. package/utilities/globals/maybe.d.ts.map +0 -1
  594. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  595. package/utilities/graphql/directives.d.ts.map +0 -1
  596. package/utilities/graphql/fragments.d.ts.map +0 -1
  597. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  598. package/utilities/graphql/operations.d.ts.map +0 -1
  599. package/utilities/graphql/print.d.ts.map +0 -1
  600. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  601. package/utilities/graphql/transform.d.ts.map +0 -1
  602. package/utilities/index.d.ts.map +0 -1
  603. package/utilities/observables/Concast.d.ts.map +0 -1
  604. package/utilities/observables/Observable.d.ts.map +0 -1
  605. package/utilities/observables/asyncMap.d.ts.map +0 -1
  606. package/utilities/observables/iteration.d.ts.map +0 -1
  607. package/utilities/observables/subclassing.d.ts.map +0 -1
  608. package/utilities/policies/pagination.d.ts.map +0 -1
  609. package/utilities/promises/decoration.d.ts.map +0 -1
  610. package/utilities/types/DeepOmit.d.ts.map +0 -1
  611. package/utilities/types/DeepPartial.d.ts.map +0 -1
  612. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  613. package/utilities/types/Primitive.d.ts.map +0 -1
  614. package/version.d.ts.map +0 -1
@@ -1,9 +1,39 @@
1
1
  import { InvariantError } from "ts-invariant";
2
2
  import type { ErrorCodes } from "../../invariantErrorCodes.js";
3
3
  type LogFunction = {
4
+ /**
5
+ * Logs a `$level` message if the user used `ts-invariant`'s `setVerbosity` to set
6
+ * a verbosity level of `$level` or lower. (defaults to `"log"`).
7
+ *
8
+ * The user will either be presented with a link to the documentation for the message,
9
+ * or they can use the `loadDevMessages` to add the message strings to the bundle.
10
+ * The documentation will display the message without argument substitution.
11
+ * Instead, the arguments will be printed on the console after the link.
12
+ *
13
+ * `message` can only be a string, a concatenation of strings, or a ternary statement
14
+ * that results in a string. This will be enforced on build, where the message will
15
+ * be replaced with a message number.
16
+ *
17
+ * String substitutions like %s, %o, %d or %f are supported.
18
+ */
4
19
  (message?: any, ...optionalParams: unknown[]): void;
5
20
  };
6
21
  type WrappedInvariant = {
22
+ /**
23
+ * Throws and InvariantError with the given message if the condition is false.
24
+ *
25
+ * `message` can only be a string, a concatenation of strings, or a ternary statement
26
+ * that results in a string. This will be enforced on build, where the message will
27
+ * be replaced with a message number.
28
+ *
29
+ * The user will either be presented with a link to the documentation for the message,
30
+ * or they can use the `loadErrorMessages` to add the message strings to the bundle.
31
+ * The documentation will display the message with the arguments substituted.
32
+ *
33
+ * String substitutions with %s are supported and will also return
34
+ * pretty-stringified objects.
35
+ * Excess `optionalParams` will be swallowed.
36
+ */
7
37
  (condition: any, message?: string | number, ...optionalParams: unknown[]): asserts condition;
8
38
  debug: LogFunction;
9
39
  log: LogFunction;
@@ -11,6 +41,16 @@ type WrappedInvariant = {
11
41
  error: LogFunction;
12
42
  };
13
43
  declare const invariant: WrappedInvariant;
44
+ /**
45
+ * Returns an InvariantError.
46
+ *
47
+ * `message` can only be a string, a concatenation of strings, or a ternary statement
48
+ * that results in a string. This will be enforced on build, where the message will
49
+ * be replaced with a message number.
50
+ * String substitutions with %s are supported and will also return
51
+ * pretty-stringified objects.
52
+ * Excess `optionalParams` will be swallowed.
53
+ */
14
54
  declare function newInvariantError(message?: string | number, ...optionalParams: unknown[]): InvariantError;
15
55
  declare const ApolloErrorMessageHandler: unique symbol;
16
56
  declare global {
@@ -33,6 +33,16 @@ var invariant = Object.assign(function invariant(condition, message) {
33
33
  warn: wrap(originalInvariant.warn),
34
34
  error: wrap(originalInvariant.error),
35
35
  });
36
+ /**
37
+ * Returns an InvariantError.
38
+ *
39
+ * `message` can only be a string, a concatenation of strings, or a ternary statement
40
+ * that results in a string. This will be enforced on build, where the message will
41
+ * be replaced with a message number.
42
+ * String substitutions with %s are supported and will also return
43
+ * pretty-stringified objects.
44
+ * Excess `optionalParams` will be swallowed.
45
+ */
36
46
  function newInvariantError(message) {
37
47
  var optionalParams = [];
38
48
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -43,9 +53,7 @@ function newInvariantError(message) {
43
53
  }
44
54
  var ApolloErrorMessageHandler = Symbol.for("ApolloErrorMessageHandler_" + version);
45
55
  function stringify(arg) {
46
- return typeof arg == "string"
47
- ? arg
48
- : stringifyForDisplay(arg, 2).slice(0, 1000);
56
+ return typeof arg == "string" ? arg : (stringifyForDisplay(arg, 2).slice(0, 1000));
49
57
  }
50
58
  function getHandledErrorMsg(message, messageArgs) {
51
59
  if (messageArgs === void 0) { messageArgs = []; }
@@ -1 +1 @@
1
- {"version":3,"file":"invariantWrappers.js","sourceRoot":"","sources":["../../../src/utilities/globals/invariantWrappers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,SAAS,IAAI,CAAC,EAA0C;IACtD,OAAO,UAAU,OAAyB;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QACxD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,IAAM,IAAI,GAAG,OAAO,CAAC;YACrB,OAAO,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,GAAG,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC1C,IAAI,GAAG,EAAE,CAAC;aACX;SACF;QACD,EAAE,eAA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AAyB,EACzB,WAA2B;IAA3B,4BAAA,EAAA,gBAA2B;IAE3B,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CACL,MAAM,CAAC,yBAAyB,CAAC;QACjC,MAAM,CAAC,yBAAyB,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAC1B,OAAyB,EACzB,WAA2B;IAA3B,4BAAA,EAAA,gBAA2B;IAE3B,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,sGAA+F,kBAAkB,CACtH,IAAI,CAAC,SAAS,CAAC;QACb,OAAO,SAAA;QACP,OAAO,SAAA;QACP,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC;KACjC,CAAC,CACH,CAAE,CAAC;AACN,CAAC;AAED,OAAO,EACL,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,yBAAyB,GAC1B,CAAC","sourcesContent":["import { invariant as originalInvariant, InvariantError } from \"ts-invariant\";\nimport { version } from \"../../version.js\";\nimport global from \"./global.js\";\nimport type { ErrorCodes } from \"../../invariantErrorCodes.js\";\nimport { stringifyForDisplay } from \"../common/stringifyForDisplay.js\";\n\nfunction wrap(fn: (msg?: string, ...args: any[]) => void) {\n return function (message?: string | number, ...args: any[]) {\n if (typeof message === \"number\") {\n const arg0 = message;\n message = getHandledErrorMsg(arg0);\n if (!message) {\n message = getFallbackErrorMsg(arg0, args);\n args = [];\n }\n }\n fn(...[message].concat(args));\n };\n}\n\ntype LogFunction = {\n /**\n * Logs a `$level` message if the user used `ts-invariant`'s `setVerbosity` to set\n * a verbosity level of `$level` or lower. (defaults to `\"log\"`).\n *\n * The user will either be presented with a link to the documentation for the message,\n * or they can use the `loadDevMessages` to add the message strings to the bundle.\n * The documentation will display the message without argument substitution.\n * Instead, the arguments will be printed on the console after the link.\n *\n * `message` can only be a string, a concatenation of strings, or a ternary statement\n * that results in a string. This will be enforced on build, where the message will\n * be replaced with a message number.\n *\n * String substitutions like %s, %o, %d or %f are supported.\n */\n (message?: any, ...optionalParams: unknown[]): void;\n};\n\ntype WrappedInvariant = {\n /**\n * Throws and InvariantError with the given message if the condition is false.\n *\n * `message` can only be a string, a concatenation of strings, or a ternary statement\n * that results in a string. This will be enforced on build, where the message will\n * be replaced with a message number.\n *\n * The user will either be presented with a link to the documentation for the message,\n * or they can use the `loadErrorMessages` to add the message strings to the bundle.\n * The documentation will display the message with the arguments substituted.\n *\n * String substitutions with %s are supported and will also return\n * pretty-stringified objects.\n * Excess `optionalParams` will be swallowed.\n */\n (\n condition: any,\n message?: string | number,\n ...optionalParams: unknown[]\n ): asserts condition;\n\n debug: LogFunction;\n log: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n};\nconst invariant: WrappedInvariant = Object.assign(\n function invariant(\n condition: any,\n message?: string | number,\n ...args: unknown[]\n ): asserts condition {\n if (!condition) {\n originalInvariant(\n condition,\n getHandledErrorMsg(message, args) || getFallbackErrorMsg(message, args)\n );\n }\n },\n {\n debug: wrap(originalInvariant.debug),\n log: wrap(originalInvariant.log),\n warn: wrap(originalInvariant.warn),\n error: wrap(originalInvariant.error),\n }\n);\n\n/**\n * Returns an InvariantError.\n *\n * `message` can only be a string, a concatenation of strings, or a ternary statement\n * that results in a string. This will be enforced on build, where the message will\n * be replaced with a message number.\n * String substitutions with %s are supported and will also return\n * pretty-stringified objects.\n * Excess `optionalParams` will be swallowed.\n */\nfunction newInvariantError(\n message?: string | number,\n ...optionalParams: unknown[]\n) {\n return new InvariantError(\n getHandledErrorMsg(message, optionalParams) ||\n getFallbackErrorMsg(message, optionalParams)\n );\n}\n\nconst ApolloErrorMessageHandler = Symbol.for(\n \"ApolloErrorMessageHandler_\" + version\n);\ndeclare global {\n interface Window {\n [ApolloErrorMessageHandler]?: {\n (message: string | number, args: unknown[]): string | undefined;\n } & ErrorCodes;\n }\n}\n\nfunction stringify(arg: any) {\n return typeof arg == \"string\"\n ? arg\n : stringifyForDisplay(arg, 2).slice(0, 1000);\n}\n\nfunction getHandledErrorMsg(\n message?: string | number,\n messageArgs: unknown[] = []\n) {\n if (!message) return;\n return (\n global[ApolloErrorMessageHandler] &&\n global[ApolloErrorMessageHandler](message, messageArgs.map(stringify))\n );\n}\n\nfunction getFallbackErrorMsg(\n message?: string | number,\n messageArgs: unknown[] = []\n) {\n if (!message) return;\n return `An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#${encodeURIComponent(\n JSON.stringify({\n version,\n message,\n args: messageArgs.map(stringify),\n })\n )}`;\n}\n\nexport {\n invariant,\n InvariantError,\n newInvariantError,\n ApolloErrorMessageHandler,\n};\n"]}
1
+ {"version":3,"file":"invariantWrappers.js","sourceRoot":"","sources":["../../../src/utilities/globals/invariantWrappers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,SAAS,IAAI,CAAC,EAA0C;IACtD,OAAO,UAAU,OAAyB;QAAE,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,6BAAc;;QACxD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAM,IAAI,GAAG,OAAO,CAAC;YACrB,OAAO,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC1C,IAAI,GAAG,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QACD,EAAE,eAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;IAChC,CAAC,C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,4BAAA,EAAA,gBAA2B;IAE3B,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CACL,MAAM,CAAC,yBAAyB,CAAC;QACjC,MAAM,CAAC,yBAAyB,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAC1B,OAAyB,EACzB,WAA2B;IAA3B,4BAAA,EAAA,gBAA2B;IAE3B,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,sGAA+F,kBAAkB,CACtH,IAAI,CAAC,SAAS,CAAC;QACb,OAAO,SAAA;QACP,OAAO,SAAA;QACP,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC;KACjC,CAAC,CACH,CAAE,CAAC;AACN,CAAC;AAED,OAAO,EACL,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,yBAAyB,GAC1B,CAAC","sourcesContent":["import { invariant as originalInvariant, InvariantError } from \"ts-invariant\";\nimport { version } from \"../../version.js\";\nimport global from \"./global.js\";\nimport type { ErrorCodes } from \"../../invariantErrorCodes.js\";\nimport { stringifyForDisplay } from \"../common/stringifyForDisplay.js\";\n\nfunction wrap(fn: (msg?: string, ...args: any[]) => void) {\n return function (message?: string | number, ...args: any[]) {\n if (typeof message === \"number\") {\n const arg0 = message;\n message = getHandledErrorMsg(arg0);\n if (!message) {\n message = getFallbackErrorMsg(arg0, args);\n args = [];\n }\n }\n fn(...[message].concat(args));\n };\n}\n\ntype LogFunction = {\n /**\n * Logs a `$level` message if the user used `ts-invariant`'s `setVerbosity` to set\n * a verbosity level of `$level` or lower. (defaults to `\"log\"`).\n *\n * The user will either be presented with a link to the documentation for the message,\n * or they can use the `loadDevMessages` to add the message strings to the bundle.\n * The documentation will display the message without argument substitution.\n * Instead, the arguments will be printed on the console after the link.\n *\n * `message` can only be a string, a concatenation of strings, or a ternary statement\n * that results in a string. This will be enforced on build, where the message will\n * be replaced with a message number.\n *\n * String substitutions like %s, %o, %d or %f are supported.\n */\n (message?: any, ...optionalParams: unknown[]): void;\n};\n\ntype WrappedInvariant = {\n /**\n * Throws and InvariantError with the given message if the condition is false.\n *\n * `message` can only be a string, a concatenation of strings, or a ternary statement\n * that results in a string. This will be enforced on build, where the message will\n * be replaced with a message number.\n *\n * The user will either be presented with a link to the documentation for the message,\n * or they can use the `loadErrorMessages` to add the message strings to the bundle.\n * The documentation will display the message with the arguments substituted.\n *\n * String substitutions with %s are supported and will also return\n * pretty-stringified objects.\n * Excess `optionalParams` will be swallowed.\n */\n (\n condition: any,\n message?: string | number,\n ...optionalParams: unknown[]\n ): asserts condition;\n\n debug: LogFunction;\n log: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n};\nconst invariant: WrappedInvariant = Object.assign(\n function invariant(\n condition: any,\n message?: string | number,\n ...args: unknown[]\n ): asserts condition {\n if (!condition) {\n originalInvariant(\n condition,\n getHandledErrorMsg(message, args) || getFallbackErrorMsg(message, args)\n );\n }\n },\n {\n debug: wrap(originalInvariant.debug),\n log: wrap(originalInvariant.log),\n warn: wrap(originalInvariant.warn),\n error: wrap(originalInvariant.error),\n }\n);\n\n/**\n * Returns an InvariantError.\n *\n * `message` can only be a string, a concatenation of strings, or a ternary statement\n * that results in a string. This will be enforced on build, where the message will\n * be replaced with a message number.\n * String substitutions with %s are supported and will also return\n * pretty-stringified objects.\n * Excess `optionalParams` will be swallowed.\n */\nfunction newInvariantError(\n message?: string | number,\n ...optionalParams: unknown[]\n) {\n return new InvariantError(\n getHandledErrorMsg(message, optionalParams) ||\n getFallbackErrorMsg(message, optionalParams)\n );\n}\n\nconst ApolloErrorMessageHandler = Symbol.for(\n \"ApolloErrorMessageHandler_\" + version\n);\ndeclare global {\n interface Window {\n [ApolloErrorMessageHandler]?: {\n (message: string | number, args: unknown[]): string | undefined;\n } & ErrorCodes;\n }\n}\n\nfunction stringify(arg: any) {\n return typeof arg == \"string\" ? arg : (\n stringifyForDisplay(arg, 2).slice(0, 1000)\n );\n}\n\nfunction getHandledErrorMsg(\n message?: string | number,\n messageArgs: unknown[] = []\n) {\n if (!message) return;\n return (\n global[ApolloErrorMessageHandler] &&\n global[ApolloErrorMessageHandler](message, messageArgs.map(stringify))\n );\n}\n\nfunction getFallbackErrorMsg(\n message?: string | number,\n messageArgs: unknown[] = []\n) {\n if (!message) return;\n return `An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#${encodeURIComponent(\n JSON.stringify({\n version,\n message,\n args: messageArgs.map(stringify),\n })\n )}`;\n}\n\nexport {\n invariant,\n InvariantError,\n newInvariantError,\n ApolloErrorMessageHandler,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"maybe.js","sourceRoot":"","sources":["../../../src/utilities/globals/maybe.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAI,KAAc;IACrC,IAAI;QACF,OAAO,KAAK,EAAE,CAAC;KAChB;IAAC,WAAM,GAAE;AACZ,CAAC","sourcesContent":["export function maybe<T>(thunk: () => T): T | undefined {\n try {\n return thunk();\n } catch {}\n}\n"]}
1
+ {"version":3,"file":"maybe.js","sourceRoot":"","sources":["../../../src/utilities/globals/maybe.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAI,KAAc;IACrC,IAAI,CAAC;QACH,OAAO,KAAK,EAAE,CAAC;IACjB,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;AACZ,CAAC","sourcesContent":["export function maybe<T>(thunk: () => T): T | undefined {\n try {\n return thunk();\n } catch {}\n}\n"]}
@@ -5,24 +5,31 @@ import { invariant } from "../globals/index.js";
5
5
  function identity(document) {
6
6
  return document;
7
7
  }
8
- var DocumentTransform = (function () {
8
+ var DocumentTransform = /** @class */ (function () {
9
9
  function DocumentTransform(transform, options) {
10
10
  if (options === void 0) { options = Object.create(null); }
11
- this.resultCache = canUseWeakSet
12
- ? new WeakSet()
13
- : new Set();
11
+ this.resultCache = canUseWeakSet ? new WeakSet() : new Set();
14
12
  this.transform = transform;
15
13
  if (options.getCacheKey) {
14
+ // Override default `getCacheKey` function, which returns [document].
16
15
  this.getCacheKey = options.getCacheKey;
17
16
  }
18
17
  if (options.cache !== false) {
19
18
  this.stableCacheKeys = new Trie(canUseWeakMap, function (key) { return ({ key: key }); });
20
19
  }
21
20
  }
21
+ // This default implementation of getCacheKey can be overridden by providing
22
+ // options.getCacheKey to the DocumentTransform constructor. In general, a
23
+ // getCacheKey function may either return an array of keys (often including
24
+ // the document) to be used as a cache key, or undefined to indicate the
25
+ // transform for this document should not be cached.
22
26
  DocumentTransform.prototype.getCacheKey = function (document) {
23
27
  return [document];
24
28
  };
25
29
  DocumentTransform.identity = function () {
30
+ // No need to cache this transform since it just returns the document
31
+ // unchanged. This should save a bit of memory that would otherwise be
32
+ // needed to populate the `documentCache` of this transform.
26
33
  return new DocumentTransform(identity, { cache: false });
27
34
  };
28
35
  DocumentTransform.split = function (predicate, left, right) {
@@ -30,9 +37,13 @@ var DocumentTransform = (function () {
30
37
  return new DocumentTransform(function (document) {
31
38
  var documentTransform = predicate(document) ? left : right;
32
39
  return documentTransform.transformDocument(document);
33
- }, { cache: false });
40
+ },
41
+ // Reasonably assume both `left` and `right` transforms handle their own caching
42
+ { cache: false });
34
43
  };
35
44
  DocumentTransform.prototype.transformDocument = function (document) {
45
+ // If a user passes an already transformed result back to this function,
46
+ // immediately return it.
36
47
  if (this.resultCache.has(document)) {
37
48
  return document;
38
49
  }
@@ -52,7 +63,9 @@ var DocumentTransform = (function () {
52
63
  var _this = this;
53
64
  return new DocumentTransform(function (document) {
54
65
  return otherTransform.transformDocument(_this.transformDocument(document));
55
- }, { cache: false });
66
+ },
67
+ // Reasonably assume both transforms handle their own caching
68
+ { cache: false });
56
69
  };
57
70
  DocumentTransform.prototype.getStableCacheEntry = function (document) {
58
71
  if (!this.stableCacheKeys)
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentTransform.js","sourceRoot":"","sources":["../../../src/utilities/graphql/DocumentT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AAI,SAAS,EAAE;YACb,SAAS,CACP,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EACxB,iDAAiD,CAClD,CAAC;YACF,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;SACpD;IACH,CAAC;IACH,wBAAC;AAAD,CAAC,AA9GD,IA8GC","sourcesContent":["import { Trie } from \"@wry/trie\";\nimport { canUseWeakMap, canUseWeakSet } from \"../common/canUse.js\";\nimport { checkDocument } from \"./getFromAST.js\";\nimport { invariant } from \"../globals/index.js\";\nimport type { DocumentNode } from \"graphql\";\n\nexport type DocumentTransformCacheKey = ReadonlyArray<unknown>;\n\ntype TransformFn = (document: DocumentNode) => DocumentNode;\n\ninterface DocumentTransformOptions {\n cache?: boolean;\n getCacheKey?: (\n document: DocumentNode\n ) => DocumentTransformCacheKey | undefined;\n}\n\nfunction identity(document: DocumentNode) {\n return document;\n}\n\nexport class DocumentTransform {\n private readonly transform: TransformFn;\n\n private readonly resultCache = canUseWeakSet\n ? new WeakSet<DocumentNode>()\n : new Set<DocumentNode>();\n\n private stableCacheKeys:\n | Trie<{ key: DocumentTransformCacheKey; value?: DocumentNode }>\n | undefined;\n\n // This default implementation of getCacheKey can be overridden by providing\n // options.getCacheKey to the DocumentTransform constructor. In general, a\n // getCacheKey function may either return an array of keys (often including\n // the document) to be used as a cache key, or undefined to indicate the\n // transform for this document should not be cached.\n private getCacheKey(\n document: DocumentNode\n ): DocumentTransformCacheKey | undefined {\n return [document];\n }\n\n static identity() {\n // No need to cache this transform since it just returns the document\n // unchanged. This should save a bit of memory that would otherwise be\n // needed to populate the `documentCache` of this transform.\n return new DocumentTransform(identity, { cache: false });\n }\n\n static split(\n predicate: (document: DocumentNode) => boolean,\n left: DocumentTransform,\n right: DocumentTransform = DocumentTransform.identity()\n ) {\n return new DocumentTransform(\n (document) => {\n const documentTransform = predicate(document) ? left : right;\n\n return documentTransform.transformDocument(document);\n },\n // Reasonably assume both `left` and `right` transforms handle their own caching\n { cache: false }\n );\n }\n\n constructor(\n transform: TransformFn,\n options: DocumentTransformOptions = Object.create(null)\n ) {\n this.transform = transform;\n\n if (options.getCacheKey) {\n // Override default `getCacheKey` function, which returns [document].\n this.getCacheKey = options.getCacheKey;\n }\n\n if (options.cache !== false) {\n this.stableCacheKeys = new Trie(canUseWeakMap, (key) => ({ key }));\n }\n }\n\n transformDocument(document: DocumentNode) {\n // If a user passes an already transformed result back to this function,\n // immediately return it.\n if (this.resultCache.has(document)) {\n return document;\n }\n\n const cacheEntry = this.getStableCacheEntry(document);\n\n if (cacheEntry && cacheEntry.value) {\n return cacheEntry.value;\n }\n\n checkDocument(document);\n\n const transformedDocument = this.transform(document);\n\n this.resultCache.add(transformedDocument);\n\n if (cacheEntry) {\n cacheEntry.value = transformedDocument;\n }\n\n return transformedDocument;\n }\n\n concat(otherTransform: DocumentTransform) {\n return new DocumentTransform(\n (document) => {\n return otherTransform.transformDocument(\n this.transformDocument(document)\n );\n },\n // Reasonably assume both transforms handle their own caching\n { cache: false }\n );\n }\n\n getStableCacheEntry(document: DocumentNode) {\n if (!this.stableCacheKeys) return;\n const cacheKeys = this.getCacheKey(document);\n if (cacheKeys) {\n invariant(\n Array.isArray(cacheKeys),\n \"`getCacheKey` must return an array or undefined\"\n );\n return this.stableCacheKeys.lookupArray(cacheKeys);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"DocumentTransform.js","sourceRoot":"","sources":["../../../src/utilities/graphql/DocumentTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAchD,SAAS,QAAQ,CAAC,QAAsB;IACtC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;IA4CE,2BACE,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AAC,EACxB,iDAAiD,CAClD,CAAC;YACF,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IACH,wBAAC;AAAD,CAAC,AA7GD,IA6GC","sourcesContent":["import { Trie } from \"@wry/trie\";\nimport { canUseWeakMap, canUseWeakSet } from \"../common/canUse.js\";\nimport { checkDocument } from \"./getFromAST.js\";\nimport { invariant } from \"../globals/index.js\";\nimport type { DocumentNode } from \"graphql\";\n\nexport type DocumentTransformCacheKey = ReadonlyArray<unknown>;\n\ntype TransformFn = (document: DocumentNode) => DocumentNode;\n\ninterface DocumentTransformOptions {\n cache?: boolean;\n getCacheKey?: (\n document: DocumentNode\n ) => DocumentTransformCacheKey | undefined;\n}\n\nfunction identity(document: DocumentNode) {\n return document;\n}\n\nexport class DocumentTransform {\n private readonly transform: TransformFn;\n\n private readonly resultCache =\n canUseWeakSet ? new WeakSet<DocumentNode>() : new Set<DocumentNode>();\n\n private stableCacheKeys:\n | Trie<{ key: DocumentTransformCacheKey; value?: DocumentNode }>\n | undefined;\n\n // This default implementation of getCacheKey can be overridden by providing\n // options.getCacheKey to the DocumentTransform constructor. In general, a\n // getCacheKey function may either return an array of keys (often including\n // the document) to be used as a cache key, or undefined to indicate the\n // transform for this document should not be cached.\n private getCacheKey(\n document: DocumentNode\n ): DocumentTransformCacheKey | undefined {\n return [document];\n }\n\n static identity() {\n // No need to cache this transform since it just returns the document\n // unchanged. This should save a bit of memory that would otherwise be\n // needed to populate the `documentCache` of this transform.\n return new DocumentTransform(identity, { cache: false });\n }\n\n static split(\n predicate: (document: DocumentNode) => boolean,\n left: DocumentTransform,\n right: DocumentTransform = DocumentTransform.identity()\n ) {\n return new DocumentTransform(\n (document) => {\n const documentTransform = predicate(document) ? left : right;\n\n return documentTransform.transformDocument(document);\n },\n // Reasonably assume both `left` and `right` transforms handle their own caching\n { cache: false }\n );\n }\n\n constructor(\n transform: TransformFn,\n options: DocumentTransformOptions = Object.create(null)\n ) {\n this.transform = transform;\n\n if (options.getCacheKey) {\n // Override default `getCacheKey` function, which returns [document].\n this.getCacheKey = options.getCacheKey;\n }\n\n if (options.cache !== false) {\n this.stableCacheKeys = new Trie(canUseWeakMap, (key) => ({ key }));\n }\n }\n\n transformDocument(document: DocumentNode) {\n // If a user passes an already transformed result back to this function,\n // immediately return it.\n if (this.resultCache.has(document)) {\n return document;\n }\n\n const cacheEntry = this.getStableCacheEntry(document);\n\n if (cacheEntry && cacheEntry.value) {\n return cacheEntry.value;\n }\n\n checkDocument(document);\n\n const transformedDocument = this.transform(document);\n\n this.resultCache.add(transformedDocument);\n\n if (cacheEntry) {\n cacheEntry.value = transformedDocument;\n }\n\n return transformedDocument;\n }\n\n concat(otherTransform: DocumentTransform) {\n return new DocumentTransform(\n (document) => {\n return otherTransform.transformDocument(\n this.transformDocument(document)\n );\n },\n // Reasonably assume both transforms handle their own caching\n { cache: false }\n );\n }\n\n getStableCacheEntry(document: DocumentNode) {\n if (!this.stableCacheKeys) return;\n const cacheKeys = this.getCacheKey(document);\n if (cacheKeys) {\n invariant(\n Array.isArray(cacheKeys),\n \"`getCacheKey` must return an array or undefined\"\n );\n return this.stableCacheKeys.lookupArray(cacheKeys);\n }\n }\n}\n"]}
@@ -44,6 +44,8 @@ export function hasDirectives(names, root, all) {
44
44
  }
45
45
  },
46
46
  });
47
+ // If we found all the names, nameSet will be empty. If we only care about
48
+ // finding some of them, the < condition is sufficient.
47
49
  return all ? !nameSet.size : nameSet.size < uniqueCount;
48
50
  }
49
51
  export function hasClientExports(document) {
@@ -65,6 +67,7 @@ export function getInclusionDirectives(directives) {
65
67
  var ifArgument = directiveArguments[0];
66
68
  invariant(ifArgument.name && ifArgument.name.value === "if", 68, directiveName);
67
69
  var ifValue = ifArgument.value;
70
+ // means it has to be a variable value if this is a valid @skip or @include directive
68
71
  invariant(ifValue &&
69
72
  (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 69, directiveName);
70
73
  result.push({ directive: directive, ifArgument: ifArgument });
@@ -1 +1 @@
1
- {"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../src/utilities/graphql/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAchD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMvC,MAAM,UAAU,aAAa,CAC3B,EAA6B,EAC7B,SAA+B;QAD7B,UAAU,gBAAA;IAGZ,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;QACrC,OAAO,IAAI,CAAC;KACb;IACD,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC,KAAK,CAC7C,UAAC,EAAyB;YAAvB,SAAS,eAAA,EAAE,UAAU,gBAAA;QACtB,IAAI,WAAW,GAAY,KAAK,CAAC;QACjC,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE;YACxC,WAAW;gBACT,SAAS,IAAI,SAAS,CAAE,UAAU,CAAC,KAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACxE,SAAS,CACP,WAAW,KAAK,KAAK,CAAC,EACtB,+CAA+C,EAC/C,SAAS,CAAC,IAAI,CAAC,KAAK,CACrB,CAAC;SACH;aAAM;YACL,WAAW,GAAI,UAAU,CAAC,KAA0B,CAAC,KAAK,CAAC;SAC5D;QACD,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;IACtE,CAAC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAa;IAC7C,IAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,EAAE;QACV,SAAS,YAAC,IAAmB;YAC3B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,CAA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M,GAAwB,EAAE,CAAC;IAEvC,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,EAAE;QACnC,UAAU,CAAC,OAAO,CAAC,UAAC,SAAS;YAC3B,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC;gBAAE,OAAO;YAE7C,IAAM,kBAAkB,GAAG,SAAS,CAAC,SAAS,CAAC;YAC/C,IAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;YAE3C,SAAS,CACP,kBAAkB,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EACrD,sDAAsD,EACtD,aAAa,CACd,CAAC;YAEF,IAAM,UAAU,GAAG,kBAAmB,CAAC,CAAC,CAAC,CAAC;YAC1C,SAAS,CACP,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EACjD,yCAAyC,EACzC,aAAa,CACd,CAAC;YAEF,IAAM,OAAO,GAAc,UAAU,CAAC,KAAK,CAAC;YAG5C,SAAS,CACP,OAAO;gBACL,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,EAClE,uEAAuE,EACvE,aAAa,CACd,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,WAAA,EAAE,UAAU,YAAA,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { invariant } from \"../globals/index.js\";\n\n// Provides the methods that allow QueryManager to handle the `skip` and\n// `include` directives within GraphQL.\nimport type {\n SelectionNode,\n VariableNode,\n BooleanValueNode,\n DirectiveNode,\n DocumentNode,\n ArgumentNode,\n ValueNode,\n ASTNode,\n} from \"graphql\";\nimport { visit, BREAK } from \"graphql\";\n\nexport type DirectiveInfo = {\n [fieldName: string]: { [argName: string]: any };\n};\n\nexport function shouldInclude(\n { directives }: SelectionNode,\n variables?: Record<string, any>\n): boolean {\n if (!directives || !directives.length) {\n return true;\n }\n return getInclusionDirectives(directives).every(\n ({ directive, ifArgument }) => {\n let evaledValue: boolean = false;\n if (ifArgument.value.kind === \"Variable\") {\n evaledValue =\n variables && variables[(ifArgument.value as VariableNode).name.value];\n invariant(\n evaledValue !== void 0,\n `Invalid variable referenced in @%s directive.`,\n directive.name.value\n );\n } else {\n evaledValue = (ifArgument.value as BooleanValueNode).value;\n }\n return directive.name.value === \"skip\" ? !evaledValue : evaledValue;\n }\n );\n}\n\nexport function getDirectiveNames(root: ASTNode) {\n const names: string[] = [];\n\n visit(root, {\n Directive(node: DirectiveNode) {\n names.push(node.name.value);\n },\n });\n\n return names;\n}\n\nexport const hasAnyDirectives = (names: string[], root: ASTNode) =>\n hasDirectives(names, root, false);\n\nexport const hasAllDirectives = (names: string[], root: ASTNode) =>\n hasDirectives(names, root, true);\n\nexport function hasDirectives(names: string[], root: ASTNode, all?: boolean) {\n const nameSet = new Set(names);\n const uniqueCount = nameSet.size;\n\n visit(root, {\n Directive(node) {\n if (nameSet.delete(node.name.value) && (!all || !nameSet.size)) {\n return BREAK;\n }\n },\n });\n\n // If we found all the names, nameSet will be empty. If we only care about\n // finding some of them, the < condition is sufficient.\n return all ? !nameSet.size : nameSet.size < uniqueCount;\n}\n\nexport function hasClientExports(document: DocumentNode) {\n return document && hasDirectives([\"client\", \"export\"], document, true);\n}\n\nexport type InclusionDirectives = Array<{\n directive: DirectiveNode;\n ifArgument: ArgumentNode;\n}>;\n\nfunction isInclusionDirective({ name: { value } }: DirectiveNode): boolean {\n return value === \"skip\" || value === \"include\";\n}\n\nexport function getInclusionDirectives(\n directives: ReadonlyArray<DirectiveNode>\n): InclusionDirectives {\n const result: InclusionDirectives = [];\n\n if (directives && directives.length) {\n directives.forEach((directive) => {\n if (!isInclusionDirective(directive)) return;\n\n const directiveArguments = directive.arguments;\n const directiveName = directive.name.value;\n\n invariant(\n directiveArguments && directiveArguments.length === 1,\n `Incorrect number of arguments for the @%s directive.`,\n directiveName\n );\n\n const ifArgument = directiveArguments![0];\n invariant(\n ifArgument.name && ifArgument.name.value === \"if\",\n `Invalid argument for the @%s directive.`,\n directiveName\n );\n\n const ifValue: ValueNode = ifArgument.value;\n\n // means it has to be a variable value if this is a valid @skip or @include directive\n invariant(\n ifValue &&\n (ifValue.kind === \"Variable\" || ifValue.kind === \"BooleanValue\"),\n `Argument for the @%s directive must be a variable or a boolean value.`,\n directiveName\n );\n\n result.push({ directive, ifArgument });\n });\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../src/utilities/graphql/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAchD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMvC,MAAM,UAAU,aAAa,CAC3B,EAA6B,EAC7B,SAA+B;QAD7B,UAAU,gBAAA;IAGZ,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC,KAAK,CAC7C,UAAC,EAAyB;YAAvB,SAAS,eAAA,EAAE,UAAU,gBAAA;QACtB,IAAI,WAAW,GAAY,KAAK,CAAC;QACjC,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACzC,WAAW;gBACT,SAAS,IAAI,SAAS,CAAE,UAAU,CAAC,KAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACxE,SAAS,CACP,WAAW,KAAK,KAAK,CAAC,EACtB,+CAA+C,EAC/C,SAAS,CAAC,IAAI,CAAC,KAAK,CACrB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,WAAW,GAAI,UAAU,CAAC,KAA0B,CAAC,KAAK,CAAC;QAC7D,CAAC;QACD,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,KA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AAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { invariant } from \"../globals/index.js\";\n\n// Provides the methods that allow QueryManager to handle the `skip` and\n// `include` directives within GraphQL.\nimport type {\n SelectionNode,\n VariableNode,\n BooleanValueNode,\n DirectiveNode,\n DocumentNode,\n ArgumentNode,\n ValueNode,\n ASTNode,\n} from \"graphql\";\nimport { visit, BREAK } from \"graphql\";\n\nexport type DirectiveInfo = {\n [fieldName: string]: { [argName: string]: any };\n};\n\nexport function shouldInclude(\n { directives }: SelectionNode,\n variables?: Record<string, any>\n): boolean {\n if (!directives || !directives.length) {\n return true;\n }\n return getInclusionDirectives(directives).every(\n ({ directive, ifArgument }) => {\n let evaledValue: boolean = false;\n if (ifArgument.value.kind === \"Variable\") {\n evaledValue =\n variables && variables[(ifArgument.value as VariableNode).name.value];\n invariant(\n evaledValue !== void 0,\n `Invalid variable referenced in @%s directive.`,\n directive.name.value\n );\n } else {\n evaledValue = (ifArgument.value as BooleanValueNode).value;\n }\n return directive.name.value === \"skip\" ? !evaledValue : evaledValue;\n }\n );\n}\n\nexport function getDirectiveNames(root: ASTNode) {\n const names: string[] = [];\n\n visit(root, {\n Directive(node: DirectiveNode) {\n names.push(node.name.value);\n },\n });\n\n return names;\n}\n\nexport const hasAnyDirectives = (names: string[], root: ASTNode) =>\n hasDirectives(names, root, false);\n\nexport const hasAllDirectives = (names: string[], root: ASTNode) =>\n hasDirectives(names, root, true);\n\nexport function hasDirectives(names: string[], root: ASTNode, all?: boolean) {\n const nameSet = new Set(names);\n const uniqueCount = nameSet.size;\n\n visit(root, {\n Directive(node) {\n if (nameSet.delete(node.name.value) && (!all || !nameSet.size)) {\n return BREAK;\n }\n },\n });\n\n // If we found all the names, nameSet will be empty. If we only care about\n // finding some of them, the < condition is sufficient.\n return all ? !nameSet.size : nameSet.size < uniqueCount;\n}\n\nexport function hasClientExports(document: DocumentNode) {\n return document && hasDirectives([\"client\", \"export\"], document, true);\n}\n\nexport type InclusionDirectives = Array<{\n directive: DirectiveNode;\n ifArgument: ArgumentNode;\n}>;\n\nfunction isInclusionDirective({ name: { value } }: DirectiveNode): boolean {\n return value === \"skip\" || value === \"include\";\n}\n\nexport function getInclusionDirectives(\n directives: ReadonlyArray<DirectiveNode>\n): InclusionDirectives {\n const result: InclusionDirectives = [];\n\n if (directives && directives.length) {\n directives.forEach((directive) => {\n if (!isInclusionDirective(directive)) return;\n\n const directiveArguments = directive.arguments;\n const directiveName = directive.name.value;\n\n invariant(\n directiveArguments && directiveArguments.length === 1,\n `Incorrect number of arguments for the @%s directive.`,\n directiveName\n );\n\n const ifArgument = directiveArguments![0];\n invariant(\n ifArgument.name && ifArgument.name.value === \"if\",\n `Invalid argument for the @%s directive.`,\n directiveName\n );\n\n const ifValue: ValueNode = ifArgument.value;\n\n // means it has to be a variable value if this is a valid @skip or @include directive\n invariant(\n ifValue &&\n (ifValue.kind === \"Variable\" || ifValue.kind === \"BooleanValue\"),\n `Argument for the @%s directive must be a variable or a boolean value.`,\n directiveName\n );\n\n result.push({ directive, ifArgument });\n });\n }\n\n return result;\n}\n"]}
@@ -1,5 +1,30 @@
1
1
  import type { DocumentNode, FragmentDefinitionNode, InlineFragmentNode, SelectionNode } from "graphql";
2
+ /**
3
+ * Returns a query document which adds a single query operation that only
4
+ * spreads the target fragment inside of it.
5
+ *
6
+ * So for example a document of:
7
+ *
8
+ * ```graphql
9
+ * fragment foo on Foo { a b c }
10
+ * ```
11
+ *
12
+ * Turns into:
13
+ *
14
+ * ```graphql
15
+ * { ...foo }
16
+ *
17
+ * fragment foo on Foo { a b c }
18
+ * ```
19
+ *
20
+ * The target fragment will either be the only fragment in the document, or a
21
+ * fragment specified by the provided `fragmentName`. If there is more than one
22
+ * fragment, but a `fragmentName` was not defined then an error will be thrown.
23
+ */
2
24
  export declare function getFragmentQueryDocument(document: DocumentNode, fragmentName?: string): DocumentNode;
25
+ /**
26
+ * This is an interface that describes a map from fragment names to fragment definitions.
27
+ */
3
28
  export interface FragmentMap {
4
29
  [fragmentName: string]: FragmentDefinitionNode;
5
30
  }
@@ -1,9 +1,36 @@
1
1
  import { __assign, __spreadArray } from "tslib";
2
2
  import { invariant, newInvariantError } from "../globals/index.js";
3
+ /**
4
+ * Returns a query document which adds a single query operation that only
5
+ * spreads the target fragment inside of it.
6
+ *
7
+ * So for example a document of:
8
+ *
9
+ * ```graphql
10
+ * fragment foo on Foo { a b c }
11
+ * ```
12
+ *
13
+ * Turns into:
14
+ *
15
+ * ```graphql
16
+ * { ...foo }
17
+ *
18
+ * fragment foo on Foo { a b c }
19
+ * ```
20
+ *
21
+ * The target fragment will either be the only fragment in the document, or a
22
+ * fragment specified by the provided `fragmentName`. If there is more than one
23
+ * fragment, but a `fragmentName` was not defined then an error will be thrown.
24
+ */
3
25
  export function getFragmentQueryDocument(document, fragmentName) {
4
26
  var actualFragmentName = fragmentName;
27
+ // Build an array of all our fragment definitions that will be used for
28
+ // validations. We also do some validations on the other definitions in the
29
+ // document while building this list.
5
30
  var fragments = [];
6
31
  document.definitions.forEach(function (definition) {
32
+ // Throw an error if we encounter an operation definition because we will
33
+ // define our own operation definition later on.
7
34
  if (definition.kind === "OperationDefinition") {
8
35
  throw newInvariantError(
9
36
  70,
@@ -11,17 +38,24 @@ export function getFragmentQueryDocument(document, fragmentName) {
11
38
  definition.name ? " named '".concat(definition.name.value, "'") : ""
12
39
  );
13
40
  }
41
+ // Add our definition to the fragments array if it is a fragment
42
+ // definition.
14
43
  if (definition.kind === "FragmentDefinition") {
15
44
  fragments.push(definition);
16
45
  }
17
46
  });
47
+ // If the user did not give us a fragment name then let us try to get a
48
+ // name from a single fragment in the definition.
18
49
  if (typeof actualFragmentName === "undefined") {
19
50
  invariant(fragments.length === 1, 71, fragments.length);
20
51
  actualFragmentName = fragments[0].name.value;
21
52
  }
53
+ // Generate a query document with an operation that simply spreads the
54
+ // fragment inside of it.
22
55
  var query = __assign(__assign({}, document), { definitions: __spreadArray([
23
56
  {
24
57
  kind: "OperationDefinition",
58
+ // OperationTypeNode is an enum
25
59
  operation: "query",
26
60
  selectionSet: {
27
61
  kind: "SelectionSet",
@@ -39,6 +73,8 @@ export function getFragmentQueryDocument(document, fragmentName) {
39
73
  ], document.definitions, true) });
40
74
  return query;
41
75
  }
76
+ // Utility function that takes a list of fragment definitions and makes a hash out of them
77
+ // that maps the name of the fragment to the fragment definition.
42
78
  export function createFragmentMap(fragments) {
43
79
  if (fragments === void 0) { fragments = []; }
44
80
  var symTable = {};
@@ -1 +1 @@
1
- {"version":3,"file":"fragments.js","sourceRoot":"","sources":["../../../src/utilities/graphql/fragments.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAkCnE,MAAM,UAAU,wBAAwB,CACtC,QAAsB,EACtB,YAAqB;IAErB,IAAI,kBAAkB,GAAG,YAAY,CAAC;IAKtC,IAAM,SAAS,GAAkC,EAAE,CAAC;IACpD,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,UAAC,UAAU;QAGtC,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAE;YAC7C,MAAM,iBAAiB,CACrB,0BAA0B;gBACxB,yFAAyF,EAC3F,UAAU,CAAC,SAAS,EACpB,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAW,UAAU,CAAC,IAAI,CAAC,KAAK,MAAG,CAAC,CAAC,CAAC,EAAE,CAC3D,CAAC;SACH;QAGD,IAAI,UAAU,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC5C,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAC5B;IACH,CAAC,CAAC,CAAC;IAIH,IAAI,OAAO,kBAAkB,KAAK,WAAW,EAAE;QAC7C,SAAS,CACP,SAAS,CAAC,MAAM,KAAK,CAAC,EACtB,2FAA6F,EAC7F,SAAS,CAAC,MAAM,CACjB,CAAC;QACF,kBAAkB,GAAG,SAAS,CAAC,CA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;KACf;AACH,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../globals/index.js\";\n\nimport type {\n DocumentNode,\n FragmentDefinitionNode,\n InlineFragmentNode,\n SelectionNode,\n} from \"graphql\";\n\n// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)\ntype Kind = any;\ntype OperationTypeNode = any;\n/**\n * Returns a query document which adds a single query operation that only\n * spreads the target fragment inside of it.\n *\n * So for example a document of:\n *\n * ```graphql\n * fragment foo on Foo { a b c }\n * ```\n *\n * Turns into:\n *\n * ```graphql\n * { ...foo }\n *\n * fragment foo on Foo { a b c }\n * ```\n *\n * The target fragment will either be the only fragment in the document, or a\n * fragment specified by the provided `fragmentName`. If there is more than one\n * fragment, but a `fragmentName` was not defined then an error will be thrown.\n */\nexport function getFragmentQueryDocument(\n document: DocumentNode,\n fragmentName?: string\n): DocumentNode {\n let actualFragmentName = fragmentName;\n\n // Build an array of all our fragment definitions that will be used for\n // validations. We also do some validations on the other definitions in the\n // document while building this list.\n const fragments: Array<FragmentDefinitionNode> = [];\n document.definitions.forEach((definition) => {\n // Throw an error if we encounter an operation definition because we will\n // define our own operation definition later on.\n if (definition.kind === \"OperationDefinition\") {\n throw newInvariantError(\n `Found a %s operation%s. ` +\n \"No operations are allowed when using a fragment as a query. Only fragments are allowed.\",\n definition.operation,\n definition.name ? ` named '${definition.name.value}'` : \"\"\n );\n }\n // Add our definition to the fragments array if it is a fragment\n // definition.\n if (definition.kind === \"FragmentDefinition\") {\n fragments.push(definition);\n }\n });\n\n // If the user did not give us a fragment name then let us try to get a\n // name from a single fragment in the definition.\n if (typeof actualFragmentName === \"undefined\") {\n invariant(\n fragments.length === 1,\n `Found %s fragments. \\`fragmentName\\` must be provided when there is not exactly 1 fragment.`,\n fragments.length\n );\n actualFragmentName = fragments[0].name.value;\n }\n\n // Generate a query document with an operation that simply spreads the\n // fragment inside of it.\n const query: DocumentNode = {\n ...document,\n definitions: [\n {\n kind: \"OperationDefinition\" as Kind,\n // OperationTypeNode is an enum\n operation: \"query\" as OperationTypeNode,\n selectionSet: {\n kind: \"SelectionSet\" as Kind,\n selections: [\n {\n kind: \"FragmentSpread\" as Kind,\n name: {\n kind: \"Name\" as Kind,\n value: actualFragmentName,\n },\n },\n ],\n },\n },\n ...document.definitions,\n ],\n };\n\n return query;\n}\n\n/**\n * This is an interface that describes a map from fragment names to fragment definitions.\n */\nexport interface FragmentMap {\n [fragmentName: string]: FragmentDefinitionNode;\n}\n\nexport type FragmentMapFunction = (\n fragmentName: string\n) => FragmentDefinitionNode | null;\n\n// Utility function that takes a list of fragment definitions and makes a hash out of them\n// that maps the name of the fragment to the fragment definition.\nexport function createFragmentMap(\n fragments: FragmentDefinitionNode[] = []\n): FragmentMap {\n const symTable: FragmentMap = {};\n fragments.forEach((fragment) => {\n symTable[fragment.name.value] = fragment;\n });\n return symTable;\n}\n\nexport function getFragmentFromSelection(\n selection: SelectionNode,\n fragmentMap?: FragmentMap | FragmentMapFunction\n): InlineFragmentNode | FragmentDefinitionNode | null {\n switch (selection.kind) {\n case \"InlineFragment\":\n return selection;\n case \"FragmentSpread\": {\n const fragmentName = selection.name.value;\n if (typeof fragmentMap === \"function\") {\n return fragmentMap(fragmentName);\n }\n const fragment = fragmentMap && fragmentMap[fragmentName];\n invariant(fragment, `No fragment named %s`, fragmentName);\n return fragment || null;\n }\n default:\n return null;\n }\n}\n"]}
1
+ {"version":3,"file":"fragments.js","sourceRoot":"","sources":["../../../src/utilities/graphql/fragments.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAYnE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAsB,EACtB,YAAqB;IAErB,IAAI,kBAAkB,GAAG,YAAY,CAAC;IAEtC,uEAAuE;IACvE,2EAA2E;IAC3E,qCAAqC;IACrC,IAAM,SAAS,GAAkC,EAAE,CAAC;IACpD,QAAQ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AM,UAAU,iBAAiB,CAC/B,SAAwC;IAAxC,0BAAA,EAAA,cAAwC;IAExC,IAAM,QAAQ,GAAgB,EAAE,CAAC;IACjC,SAAS,CAAC,OAAO,CAAC,UAAC,QAAQ;QACzB,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,SAAwB,EACxB,WAA+C;IAE/C,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,gBAAgB;YACnB,OAAO,SAAS,CAAC;QACnB,KAAK,gBAAgB,CAAC,CAAC,CAAC;YACtB,IAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;YAC1C,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;gBACtC,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC;YACnC,CAAC;YACD,IAAM,QAAQ,GAAG,WAAW,IAAI,WAAW,CAAC,YAAY,CAAC,CAAC;YAC1D,SAAS,CAAC,QAAQ,EAAE,sBAAsB,EAAE,YAAY,CAAC,CAAC;YAC1D,OAAO,QAAQ,IAAI,IAAI,CAAC;QAC1B,CAAC;QACD;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../globals/index.js\";\n\nimport type {\n DocumentNode,\n FragmentDefinitionNode,\n InlineFragmentNode,\n SelectionNode,\n} from \"graphql\";\n\n// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)\ntype Kind = any;\ntype OperationTypeNode = any;\n/**\n * Returns a query document which adds a single query operation that only\n * spreads the target fragment inside of it.\n *\n * So for example a document of:\n *\n * ```graphql\n * fragment foo on Foo { a b c }\n * ```\n *\n * Turns into:\n *\n * ```graphql\n * { ...foo }\n *\n * fragment foo on Foo { a b c }\n * ```\n *\n * The target fragment will either be the only fragment in the document, or a\n * fragment specified by the provided `fragmentName`. If there is more than one\n * fragment, but a `fragmentName` was not defined then an error will be thrown.\n */\nexport function getFragmentQueryDocument(\n document: DocumentNode,\n fragmentName?: string\n): DocumentNode {\n let actualFragmentName = fragmentName;\n\n // Build an array of all our fragment definitions that will be used for\n // validations. We also do some validations on the other definitions in the\n // document while building this list.\n const fragments: Array<FragmentDefinitionNode> = [];\n document.definitions.forEach((definition) => {\n // Throw an error if we encounter an operation definition because we will\n // define our own operation definition later on.\n if (definition.kind === \"OperationDefinition\") {\n throw newInvariantError(\n `Found a %s operation%s. ` +\n \"No operations are allowed when using a fragment as a query. Only fragments are allowed.\",\n definition.operation,\n definition.name ? ` named '${definition.name.value}'` : \"\"\n );\n }\n // Add our definition to the fragments array if it is a fragment\n // definition.\n if (definition.kind === \"FragmentDefinition\") {\n fragments.push(definition);\n }\n });\n\n // If the user did not give us a fragment name then let us try to get a\n // name from a single fragment in the definition.\n if (typeof actualFragmentName === \"undefined\") {\n invariant(\n fragments.length === 1,\n `Found %s fragments. \\`fragmentName\\` must be provided when there is not exactly 1 fragment.`,\n fragments.length\n );\n actualFragmentName = fragments[0].name.value;\n }\n\n // Generate a query document with an operation that simply spreads the\n // fragment inside of it.\n const query: DocumentNode = {\n ...document,\n definitions: [\n {\n kind: \"OperationDefinition\" as Kind,\n // OperationTypeNode is an enum\n operation: \"query\" as OperationTypeNode,\n selectionSet: {\n kind: \"SelectionSet\" as Kind,\n selections: [\n {\n kind: \"FragmentSpread\" as Kind,\n name: {\n kind: \"Name\" as Kind,\n value: actualFragmentName,\n },\n },\n ],\n },\n },\n ...document.definitions,\n ],\n };\n\n return query;\n}\n\n/**\n * This is an interface that describes a map from fragment names to fragment definitions.\n */\nexport interface FragmentMap {\n [fragmentName: string]: FragmentDefinitionNode;\n}\n\nexport type FragmentMapFunction = (\n fragmentName: string\n) => FragmentDefinitionNode | null;\n\n// Utility function that takes a list of fragment definitions and makes a hash out of them\n// that maps the name of the fragment to the fragment definition.\nexport function createFragmentMap(\n fragments: FragmentDefinitionNode[] = []\n): FragmentMap {\n const symTable: FragmentMap = {};\n fragments.forEach((fragment) => {\n symTable[fragment.name.value] = fragment;\n });\n return symTable;\n}\n\nexport function getFragmentFromSelection(\n selection: SelectionNode,\n fragmentMap?: FragmentMap | FragmentMapFunction\n): InlineFragmentNode | FragmentDefinitionNode | null {\n switch (selection.kind) {\n case \"InlineFragment\":\n return selection;\n case \"FragmentSpread\": {\n const fragmentName = selection.name.value;\n if (typeof fragmentMap === \"function\") {\n return fragmentMap(fragmentName);\n }\n const fragment = fragmentMap && fragmentMap[fragmentName];\n invariant(fragment, `No fragment named %s`, fragmentName);\n return fragment || null;\n }\n default:\n return null;\n }\n}\n"]}
@@ -5,6 +5,11 @@ export declare function getOperationName(doc: DocumentNode): string | null;
5
5
  export declare function getFragmentDefinitions(doc: DocumentNode): FragmentDefinitionNode[];
6
6
  export declare function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode;
7
7
  export declare function getFragmentDefinition(doc: DocumentNode): FragmentDefinitionNode;
8
+ /**
9
+ * Returns the first operation definition found in this document.
10
+ * If no operation definition is found, the first fragment definition will be returned.
11
+ * If no definitions are found, an error will be thrown.
12
+ */
8
13
  export declare function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode;
9
14
  export declare function getDefaultValues(definition: OperationDefinitionNode | undefined): Record<string, any>;
10
15
  //# sourceMappingURL=getFromAST.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { invariant, newInvariantError } from "../globals/index.js";
2
2
  import { valueToObjectRepresentation } from "./storeUtils.js";
3
+ // Checks the document for errors and throws an exception if there is an error.
3
4
  export function checkDocument(doc) {
4
5
  invariant(doc && doc.kind === "Document", 73);
5
6
  var operations = doc.definitions
@@ -26,6 +27,7 @@ export function getOperationName(doc) {
26
27
  })
27
28
  .map(function (x) { return x.name.value; })[0] || null);
28
29
  }
30
+ // Returns the FragmentDefinitions from a particular document as an array
29
31
  export function getFragmentDefinitions(doc) {
30
32
  return doc.definitions.filter(function (definition) {
31
33
  return definition.kind === "FragmentDefinition";
@@ -43,6 +45,11 @@ export function getFragmentDefinition(doc) {
43
45
  invariant(fragmentDef.kind === "FragmentDefinition", 79);
44
46
  return fragmentDef;
45
47
  }
48
+ /**
49
+ * Returns the first operation definition found in this document.
50
+ * If no operation definition is found, the first fragment definition will be returned.
51
+ * If no definitions are found, an error will be thrown.
52
+ */
46
53
  export function getMainDefinition(queryDoc) {
47
54
  checkDocument(queryDoc);
48
55
  var fragmentDefinition;
@@ -57,6 +64,8 @@ export function getMainDefinition(queryDoc) {
57
64
  }
58
65
  }
59
66
  if (definition.kind === "FragmentDefinition" && !fragmentDefinition) {
67
+ // we do this because we want to allow multiple fragment definitions
68
+ // to precede an operation definition.
60
69
  fragmentDefinition = definition;
61
70
  }
62
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getFromAST.js","sourceRoot":"","sources":["../../../src/utilities/graphql/getFromAST.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAO9D,MAAM,UAAU,aAAa,CAAC,GAAiB;IAC7C,SAAS,CACP,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,UAAU,EAC9B,0JAC2E,CAC5E,CAAC;IAEF,IAAM,UAAU,GAAG,GAAG,CAAC,WAAW;SAC/B,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,oBAAoB,EAA/B,CAA+B,CAAC;SAC9C,GAAG,CAAC,UAAC,UAAU;QACd,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAE;YAC7C,MAAM,iBAAiB,CACrB,+DAA6D,EAC7D,UAAU,CAAC,IAAI,CAChB,CAAC;SACH;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAA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G,CAAC,YAAY,EAAE;gBACpB,2BAA2B,CACzB,aAAa,EACb,GAAG,CAAC,QAAQ,CAAC,IAAI,EACjB,GAAG,CAAC,YAAyB,CAC9B,CAAC;aACH;QACH,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../globals/index.js\";\n\nimport type {\n DocumentNode,\n OperationDefinitionNode,\n FragmentDefinitionNode,\n ValueNode,\n} from \"graphql\";\n\nimport { valueToObjectRepresentation } from \"./storeUtils.js\";\n\ntype OperationDefinitionWithName = OperationDefinitionNode & {\n name: NonNullable<OperationDefinitionNode[\"name\"]>;\n};\n\n// Checks the document for errors and throws an exception if there is an error.\nexport function checkDocument(doc: DocumentNode) {\n invariant(\n doc && doc.kind === \"Document\",\n `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \\\nstring in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql`\n );\n\n const operations = doc.definitions\n .filter((d) => d.kind !== \"FragmentDefinition\")\n .map((definition) => {\n if (definition.kind !== \"OperationDefinition\") {\n throw newInvariantError(\n `Schema type definitions not allowed in queries. Found: \"%s\"`,\n definition.kind\n );\n }\n return definition;\n });\n\n invariant(\n operations.length <= 1,\n `Ambiguous GraphQL document: contains %s operations`,\n operations.length\n );\n\n return doc;\n}\n\nexport function getOperationDefinition(\n doc: DocumentNode\n): OperationDefinitionNode | undefined {\n checkDocument(doc);\n return doc.definitions.filter(\n (definition): definition is OperationDefinitionNode =>\n definition.kind === \"OperationDefinition\"\n )[0];\n}\n\nexport function getOperationName(doc: DocumentNode): string | null {\n return (\n doc.definitions\n .filter(\n (definition): definition is OperationDefinitionWithName =>\n definition.kind === \"OperationDefinition\" && !!definition.name\n )\n .map((x) => x.name.value)[0] || null\n );\n}\n\n// Returns the FragmentDefinitions from a particular document as an array\nexport function getFragmentDefinitions(\n doc: DocumentNode\n): FragmentDefinitionNode[] {\n return doc.definitions.filter(\n (definition): definition is FragmentDefinitionNode =>\n definition.kind === \"FragmentDefinition\"\n );\n}\n\nexport function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode {\n const queryDef = getOperationDefinition(doc)!;\n\n invariant(\n queryDef && queryDef.operation === \"query\",\n \"Must contain a query definition.\"\n );\n\n return queryDef;\n}\n\nexport function getFragmentDefinition(\n doc: DocumentNode\n): FragmentDefinitionNode {\n invariant(\n doc.kind === \"Document\",\n `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \\\nstring in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql`\n );\n\n invariant(\n doc.definitions.length <= 1,\n \"Fragment must have exactly one definition.\"\n );\n\n const fragmentDef = doc.definitions[0] as FragmentDefinitionNode;\n\n invariant(\n fragmentDef.kind === \"FragmentDefinition\",\n \"Must be a fragment definition.\"\n );\n\n return fragmentDef as FragmentDefinitionNode;\n}\n\n/**\n * Returns the first operation definition found in this document.\n * If no operation definition is found, the first fragment definition will be returned.\n * If no definitions are found, an error will be thrown.\n */\nexport function getMainDefinition(\n queryDoc: DocumentNode\n): OperationDefinitionNode | FragmentDefinitionNode {\n checkDocument(queryDoc);\n\n let fragmentDefinition;\n\n for (let definition of queryDoc.definitions) {\n if (definition.kind === \"OperationDefinition\") {\n const operation = (definition as OperationDefinitionNode).operation;\n if (\n operation === \"query\" ||\n operation === \"mutation\" ||\n operation === \"subscription\"\n ) {\n return definition as OperationDefinitionNode;\n }\n }\n if (definition.kind === \"FragmentDefinition\" && !fragmentDefinition) {\n // we do this because we want to allow multiple fragment definitions\n // to precede an operation definition.\n fragmentDefinition = definition as FragmentDefinitionNode;\n }\n }\n\n if (fragmentDefinition) {\n return fragmentDefinition;\n }\n\n throw newInvariantError(\n \"Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.\"\n );\n}\n\nexport function getDefaultValues(\n definition: OperationDefinitionNode | undefined\n): Record<string, any> {\n const defaultValues = Object.create(null);\n const defs = definition && definition.variableDefinitions;\n if (defs && defs.length) {\n defs.forEach((def) => {\n if (def.defaultValue) {\n valueToObjectRepresentation(\n defaultValues,\n def.variable.name,\n def.defaultValue as ValueNode\n );\n }\n });\n }\n return defaultValues;\n}\n"]}
1
+ {"version":3,"file":"getFromAST.js","sourceRoot":"","sources":["../../../src/utilities/graphql/getFromAST.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAM9D,+EAA+E;AAC/E,MAAM,UAAU,aAAa,CAAC,GAAiB;IAC7C,SAAS,CACP,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,UAAU,EAC9B,0JAC2E,CAC5E,CAAC;IAEF,IAAM,UAAU,GAAG,GAAG,CAAC,WAAW;SAC/B,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,oBAAoB,EAA/B,CAA+B,CAAC;SAC9C,GAAG,CAAC,UAAC,UAAU;QACd,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;YAC9C,MAAM,iBAAiB,CACrB,+DAA6D,EAC7D,UAAU,CAAC,IAAI,CAChB,CAAC;QACJ,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;IAEL,SAAS,CACP,UAAU,CAAC,MAAM,IAAI,CAAC,EACtB,oDAAoD,EACpD,UAAU,CAAC,MAAM,CAClB,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,GAAiB;IAEjB,aAAa,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,GAAG,CAAC,WAAW,CAAC,MAAM,CAC3B,UAAC,UAAU;QACT,OAAA,UAAU,CAAC,IAAI,KAAK,qBAAqB;IAAzC,CAAyC,CAC5C,CAAC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAiB;IACh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AEvB,KAAuB,UAAoB,EAApB,KAAA,QAAQ,CAAC,WAAW,EAApB,cAAoB,EAApB,IAAoB,EAAE,CAAC;QAAzC,IAAI,UAAU,SAAA;QACjB,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;YAC9C,IAAM,SAAS,GAAI,UAAsC,CAAC,SAAS,CAAC;YACpE,IACE,SAAS,KAAK,OAAO;gBACrB,SAAS,KAAK,UAAU;gBACxB,SAAS,KAAK,cAAc,EAC5B,CAAC;gBACD,OAAO,UAAqC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,KAAK,oBAAoB,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACpE,oEAAoE;YACpE,sCAAsC;YACtC,kBAAkB,GAAG,UAAoC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,MAAM,iBAAiB,CACrB,sFAAsF,CACvF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,UAA+C;IAE/C,IAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAM,IAAI,GAAG,UAAU,IAAI,UAAU,CAAC,mBAAmB,CAAC;IAC1D,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,UAAC,GAAG;YACf,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;gBACrB,2BAA2B,CACzB,aAAa,EACb,GAAG,CAAC,QAAQ,CAAC,IAAI,EACjB,GAAG,CAAC,YAAyB,CAC9B,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../globals/index.js\";\n\nimport type {\n DocumentNode,\n OperationDefinitionNode,\n FragmentDefinitionNode,\n ValueNode,\n} from \"graphql\";\n\nimport { valueToObjectRepresentation } from \"./storeUtils.js\";\n\ntype OperationDefinitionWithName = OperationDefinitionNode & {\n name: NonNullable<OperationDefinitionNode[\"name\"]>;\n};\n\n// Checks the document for errors and throws an exception if there is an error.\nexport function checkDocument(doc: DocumentNode) {\n invariant(\n doc && doc.kind === \"Document\",\n `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \\\nstring in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql`\n );\n\n const operations = doc.definitions\n .filter((d) => d.kind !== \"FragmentDefinition\")\n .map((definition) => {\n if (definition.kind !== \"OperationDefinition\") {\n throw newInvariantError(\n `Schema type definitions not allowed in queries. Found: \"%s\"`,\n definition.kind\n );\n }\n return definition;\n });\n\n invariant(\n operations.length <= 1,\n `Ambiguous GraphQL document: contains %s operations`,\n operations.length\n );\n\n return doc;\n}\n\nexport function getOperationDefinition(\n doc: DocumentNode\n): OperationDefinitionNode | undefined {\n checkDocument(doc);\n return doc.definitions.filter(\n (definition): definition is OperationDefinitionNode =>\n definition.kind === \"OperationDefinition\"\n )[0];\n}\n\nexport function getOperationName(doc: DocumentNode): string | null {\n return (\n doc.definitions\n .filter(\n (definition): definition is OperationDefinitionWithName =>\n definition.kind === \"OperationDefinition\" && !!definition.name\n )\n .map((x) => x.name.value)[0] || null\n );\n}\n\n// Returns the FragmentDefinitions from a particular document as an array\nexport function getFragmentDefinitions(\n doc: DocumentNode\n): FragmentDefinitionNode[] {\n return doc.definitions.filter(\n (definition): definition is FragmentDefinitionNode =>\n definition.kind === \"FragmentDefinition\"\n );\n}\n\nexport function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode {\n const queryDef = getOperationDefinition(doc)!;\n\n invariant(\n queryDef && queryDef.operation === \"query\",\n \"Must contain a query definition.\"\n );\n\n return queryDef;\n}\n\nexport function getFragmentDefinition(\n doc: DocumentNode\n): FragmentDefinitionNode {\n invariant(\n doc.kind === \"Document\",\n `Expecting a parsed GraphQL document. Perhaps you need to wrap the query \\\nstring in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql`\n );\n\n invariant(\n doc.definitions.length <= 1,\n \"Fragment must have exactly one definition.\"\n );\n\n const fragmentDef = doc.definitions[0] as FragmentDefinitionNode;\n\n invariant(\n fragmentDef.kind === \"FragmentDefinition\",\n \"Must be a fragment definition.\"\n );\n\n return fragmentDef as FragmentDefinitionNode;\n}\n\n/**\n * Returns the first operation definition found in this document.\n * If no operation definition is found, the first fragment definition will be returned.\n * If no definitions are found, an error will be thrown.\n */\nexport function getMainDefinition(\n queryDoc: DocumentNode\n): OperationDefinitionNode | FragmentDefinitionNode {\n checkDocument(queryDoc);\n\n let fragmentDefinition;\n\n for (let definition of queryDoc.definitions) {\n if (definition.kind === \"OperationDefinition\") {\n const operation = (definition as OperationDefinitionNode).operation;\n if (\n operation === \"query\" ||\n operation === \"mutation\" ||\n operation === \"subscription\"\n ) {\n return definition as OperationDefinitionNode;\n }\n }\n if (definition.kind === \"FragmentDefinition\" && !fragmentDefinition) {\n // we do this because we want to allow multiple fragment definitions\n // to precede an operation definition.\n fragmentDefinition = definition as FragmentDefinitionNode;\n }\n }\n\n if (fragmentDefinition) {\n return fragmentDefinition;\n }\n\n throw newInvariantError(\n \"Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.\"\n );\n}\n\nexport function getDefaultValues(\n definition: OperationDefinitionNode | undefined\n): Record<string, any> {\n const defaultValues = Object.create(null);\n const defs = definition && definition.variableDefinitions;\n if (defs && defs.length) {\n defs.forEach((def) => {\n if (def.defaultValue) {\n valueToObjectRepresentation(\n defaultValues,\n def.variable.name,\n def.defaultValue as ValueNode\n );\n }\n });\n }\n return defaultValues;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"print.js","sourceRoot":"","sources":["../../../src/utilities/graphql/print.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,IAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,MAAM,CAAC,IAAM,KAAK,GAAqB,UAAC,GAAG;IACzC,IAAI,MAAM,CAAC;IACX,MAAM,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAE9B,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QACxB,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;KAC9B;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { print as origPrint } from \"graphql\";\nimport { canUseWeakMap } from \"../common/canUse.js\";\n\nconst printCache = canUseWeakMap ? new WeakMap() : undefined;\nexport const print: typeof origPrint = (ast) => {\n let result;\n result = printCache?.get(ast);\n\n if (!result) {\n result = origPrint(ast);\n printCache?.set(ast, result);\n }\n return result;\n};\n"]}
1
+ {"version":3,"file":"print.js","sourceRoot":"","sources":["../../../src/utilities/graphql/print.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,IAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,MAAM,CAAC,IAAM,KAAK,GAAqB,UAAC,GAAG;IACzC,IAAI,MAAM,CAAC;IACX,MAAM,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAE9B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QACxB,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { print as origPrint } from \"graphql\";\nimport { canUseWeakMap } from \"../common/canUse.js\";\n\nconst printCache = canUseWeakMap ? new WeakMap() : undefined;\nexport const print: typeof origPrint = (ast) => {\n let result;\n result = printCache?.get(ast);\n\n if (!result) {\n result = origPrint(ast);\n printCache?.set(ast, result);\n }\n return result;\n};\n"]}
@@ -10,6 +10,20 @@ export interface StoreObject {
10
10
  __typename?: string;
11
11
  [storeFieldName: string]: StoreValue;
12
12
  }
13
+ /**
14
+ * Workaround for a TypeScript quirk:
15
+ * types per default have an implicit index signature that makes them
16
+ * assignable to `StoreObject`.
17
+ * interfaces do not have that implicit index signature, so they cannot
18
+ * be assigned to `StoreObject`.
19
+ * This type just maps over a type or interface that is passed in,
20
+ * implicitly adding the index signature.
21
+ * That way, the result can be assigned to `StoreObject`.
22
+ *
23
+ * This is important if some user-defined interface is used e.g.
24
+ * in cache.modify, where the `toReference` method expects a
25
+ * `StoreObject` as input.
26
+ */
13
27
  export type AsStoreObject<T extends {
14
28
  __typename?: string;
15
29
  }> = {
@@ -114,8 +114,8 @@ export var getStoreKeyName = Object.assign(function (fieldName, args, directives
114
114
  directives["connection"]["key"]) {
115
115
  if (directives["connection"]["filter"] &&
116
116
  directives["connection"]["filter"].length > 0) {
117
- var filterKeys = directives["connection"]["filter"]
118
- ? directives["connection"]["filter"]
117
+ var filterKeys = directives["connection"]["filter"] ?
118
+ directives["connection"]["filter"]
119
119
  : [];
120
120
  filterKeys.sort();
121
121
  var filteredArgs_1 = {};
@@ -130,6 +130,9 @@ export var getStoreKeyName = Object.assign(function (fieldName, args, directives
130
130
  }
131
131
  var completeFieldName = fieldName;
132
132
  if (args) {
133
+ // We can't use `JSON.stringify` here since it's non-deterministic,
134
+ // and can lead to different store key names being created even though
135
+ // the `args` object used during creation has the same properties/values.
133
136
  var stringifiedArgs = stringify(args);
134
137
  completeFieldName += "(".concat(stringifiedArgs, ")");
135
138
  }
@@ -153,6 +156,8 @@ export var getStoreKeyName = Object.assign(function (fieldName, args, directives
153
156
  return previous;
154
157
  },
155
158
  });
159
+ // Default stable JSON.stringify implementation. Can be updated/replaced with
160
+ // something better by calling getStoreKeyName.setStringify.
156
161
  var stringify = function defaultStringify(value) {
157
162
  return JSON.stringify(value, stringifyReplacer);
158
163
  };