@graphql-hive/federation-gateway-audit 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/.changeset/@graphql-hive_federation-gateway-audit-293-dependencies.md +5 -0
  2. package/.changeset/README.md +9 -0
  3. package/.changeset/config.json +18 -0
  4. package/.changeset/funky-times-cry.md +5 -0
  5. package/.github/CONTRIBUTING.md +9 -0
  6. package/.github/workflows/ci.yaml +97 -0
  7. package/.github/workflows/release.yml +58 -0
  8. package/LICENSE +21 -0
  9. package/README.md +113 -0
  10. package/REPORT.md +812 -0
  11. package/dist/cli.js +547 -0
  12. package/dist/env-Dj2M4ll3.cjs +15 -0
  13. package/dist/env-j1f_SZtG.js +13 -0
  14. package/dist/env-j1f_SZtG.mjs +13 -0
  15. package/dist/index--3rcSZqA.js +227 -0
  16. package/dist/index-0MDIXUzP.cjs +589 -0
  17. package/dist/index-19eD5lFk.mjs +163 -0
  18. package/dist/index-1ZtG04bN.js +222 -0
  19. package/dist/index-1nZTfbJn.cjs +168 -0
  20. package/dist/index-1smMXABT.mjs +227 -0
  21. package/dist/index-2oy7cA9A.js +225 -0
  22. package/dist/index-3BM15w2Y.mjs +234 -0
  23. package/dist/index-3CyAnc7j.js +234 -0
  24. package/dist/index-4Vj-ND7j.mjs +213 -0
  25. package/dist/index-4swHVe9x.cjs +507 -0
  26. package/dist/index-6itLA31k.js +382 -0
  27. package/dist/index-6qNpP2wc.mjs +238 -0
  28. package/dist/index-81CiuWlP.mjs +333 -0
  29. package/dist/index-8FxjbyOU.cjs +236 -0
  30. package/dist/index-A2YbwKzc.mjs +288 -0
  31. package/dist/index-B-YHHt9g.js +333 -0
  32. package/dist/index-B0coRevy.mjs +337 -0
  33. package/dist/index-B1NAc0TI.cjs +215 -0
  34. package/dist/index-B1WvIzTg.js +371 -0
  35. package/dist/index-B38OpRtf.js +166 -0
  36. package/dist/index-B3aDw4Tt.js +359 -0
  37. package/dist/index-B55AdoQy.js +273 -0
  38. package/dist/index-B7cr8XE-.js +194 -0
  39. package/dist/index-B7zN3YzE.cjs +683 -0
  40. package/dist/index-B8X923W3.mjs +262 -0
  41. package/dist/index-B958BFYC.cjs +224 -0
  42. package/dist/index-B9T896rB.mjs +163 -0
  43. package/dist/index-BA3ERnyq.mjs +234 -0
  44. package/dist/index-BDMi6sOm.cjs +252 -0
  45. package/dist/index-BDNWXFb_.mjs +304 -0
  46. package/dist/index-BEMScD_X.cjs +173 -0
  47. package/dist/index-BF0H5kP0.cjs +384 -0
  48. package/dist/index-BGC0_vWj.cjs +335 -0
  49. package/dist/index-BGNmWPAk.js +381 -0
  50. package/dist/index-BGUm947D.cjs +229 -0
  51. package/dist/index-BJB0tRA1.js +550 -0
  52. package/dist/index-BKcwbRZx.cjs +339 -0
  53. package/dist/index-BKpVb_h9.cjs +236 -0
  54. package/dist/index-BPFol6Ww.mjs +129 -0
  55. package/dist/index-BPza8i2Q.mjs +213 -0
  56. package/dist/index-BQQgQaGz.cjs +552 -0
  57. package/dist/index-BReFIfq_.cjs +361 -0
  58. package/dist/index-BS7JyQSU.js +250 -0
  59. package/dist/index-BSWSgZCO.cjs +252 -0
  60. package/dist/index-BStXx4OK.js +705 -0
  61. package/dist/index-BSwOAvti.js +288 -0
  62. package/dist/index-BWO8QbMB.mjs +587 -0
  63. package/dist/index-BYEdADrG.cjs +227 -0
  64. package/dist/index-B_eGT6oX.js +225 -0
  65. package/dist/index-B_u5Boud.js +333 -0
  66. package/dist/index-BaH3FI9i.cjs +361 -0
  67. package/dist/index-BaluTf1I.cjs +707 -0
  68. package/dist/index-BblYlZ3A.cjs +131 -0
  69. package/dist/index-BcZC0OIN.js +234 -0
  70. package/dist/index-Bcjyyjhh.mjs +259 -0
  71. package/dist/index-BcoW0aPo.cjs +165 -0
  72. package/dist/index-BdNZKlDU.js +284 -0
  73. package/dist/index-Bf81cAA1.mjs +444 -0
  74. package/dist/index-Bg3H3fgZ.js +259 -0
  75. package/dist/index-Bgl_1Y6Q.mjs +681 -0
  76. package/dist/index-BgmItHIB.mjs +129 -0
  77. package/dist/index-BgryMCqm.mjs +213 -0
  78. package/dist/index-Bh6a3eXK.mjs +227 -0
  79. package/dist/index-BhPDIfmU.js +304 -0
  80. package/dist/index-BiTzMTFn.js +304 -0
  81. package/dist/index-BjbmOyBP.cjs +215 -0
  82. package/dist/index-BjwZX2iS.mjs +273 -0
  83. package/dist/index-Bm8hqSRd.cjs +168 -0
  84. package/dist/index-BmOn6xYL.js +228 -0
  85. package/dist/index-BmQrhPXB.cjs +131 -0
  86. package/dist/index-Bnb8TpOO.js +280 -0
  87. package/dist/index-BndUB2KV.mjs +381 -0
  88. package/dist/index-Bo74nI4n.js +129 -0
  89. package/dist/index-BoGmP6Cy.cjs +230 -0
  90. package/dist/index-BodMjESw.mjs +250 -0
  91. package/dist/index-BpJZCoVH.mjs +250 -0
  92. package/dist/index-Br-Y1qC_.cjs +446 -0
  93. package/dist/index-BrFtcRgi.mjs +194 -0
  94. package/dist/index-BsPxDJAB.mjs +238 -0
  95. package/dist/index-Bu7pZnPO.cjs +170 -0
  96. package/dist/index-Bu8SXnTf.mjs +227 -0
  97. package/dist/index-BuNNRp3W.mjs +117 -0
  98. package/dist/index-Bwh8HVkw.cjs +384 -0
  99. package/dist/index-BxK3Y72_.js +227 -0
  100. package/dist/index-BxPUzymh.cjs +208 -0
  101. package/dist/index-ByUUB7Zn.js +250 -0
  102. package/dist/index-ByUr80PD.cjs +306 -0
  103. package/dist/index-ByZa9qm8.mjs +273 -0
  104. package/dist/index-BzPCjhuQ.cjs +264 -0
  105. package/dist/index-Bz_LTy1A.mjs +222 -0
  106. package/dist/index-C05_HMLC.js +225 -0
  107. package/dist/index-C15P-_1j.cjs +229 -0
  108. package/dist/index-C1GgHOiD.js +228 -0
  109. package/dist/index-C4Pk-zTm.mjs +227 -0
  110. package/dist/index-C4dnTlBf.js +262 -0
  111. package/dist/index-C6LW00iX.mjs +505 -0
  112. package/dist/index-C6nkQ480.js +225 -0
  113. package/dist/index-C8Mu4K9Q.cjs +383 -0
  114. package/dist/index-C8mB7yWC.mjs +288 -0
  115. package/dist/index-C9Eh7qBC.js +273 -0
  116. package/dist/index-CAJ9YPxc.js +681 -0
  117. package/dist/index-CD03pVUt.cjs +373 -0
  118. package/dist/index-CD8GiuIg.js +227 -0
  119. package/dist/index-CHB_0VqK.mjs +333 -0
  120. package/dist/index-CKEgb_R7.cjs +215 -0
  121. package/dist/index-CLsasg69.js +228 -0
  122. package/dist/index-CMdC_Cah.js +213 -0
  123. package/dist/index-CNOcqGKC.cjs +227 -0
  124. package/dist/index-CNvZCDZa.js +166 -0
  125. package/dist/index-CO0GiXGE.js +168 -0
  126. package/dist/index-COGhiFjk.mjs +284 -0
  127. package/dist/index-COIlelpZ.mjs +262 -0
  128. package/dist/index-CPph-RFN.mjs +168 -0
  129. package/dist/index-CPu_XkjY.mjs +304 -0
  130. package/dist/index-CQ5t4ZXm.js +117 -0
  131. package/dist/index-CQeQ1nto.js +681 -0
  132. package/dist/index-CSc_T8Lu.js +218 -0
  133. package/dist/index-CUFKuE64.js +550 -0
  134. package/dist/index-CW8h3l6M.js +262 -0
  135. package/dist/index-CWrng7Hd.mjs +550 -0
  136. package/dist/index-CWuObqnS.mjs +587 -0
  137. package/dist/index-CX7-wc6X.cjs +1837 -0
  138. package/dist/index-CXviN8qZ.cjs +224 -0
  139. package/dist/index-CY9mowWW.mjs +705 -0
  140. package/dist/index-C_pTgB_1.js +194 -0
  141. package/dist/index-C_qaNb-X.mjs +225 -0
  142. package/dist/index-Ca0FeU7u.js +505 -0
  143. package/dist/index-Cb3ImEjd.cjs +165 -0
  144. package/dist/index-Cbhvi8yk.cjs +229 -0
  145. package/dist/index-Cc3vrs6_.mjs +228 -0
  146. package/dist/index-CcIXvx40.mjs +171 -0
  147. package/dist/index-CdaeeF3f.cjs +306 -0
  148. package/dist/index-CddVoIp2.js +213 -0
  149. package/dist/index-CeiRxGcN.mjs +218 -0
  150. package/dist/index-ChefKWWr.mjs +381 -0
  151. package/dist/index-Cj2ocjXI.cjs +227 -0
  152. package/dist/index-CkWEXzTN.js +129 -0
  153. package/dist/index-Ckhb9QAu.cjs +264 -0
  154. package/dist/index-CklJfQlf.cjs +220 -0
  155. package/dist/index-Cmh7PJUd.mjs +372 -0
  156. package/dist/index-Cn0ZJkAv.mjs +280 -0
  157. package/dist/index-CqTzarV1.mjs +198 -0
  158. package/dist/index-CrUbbFxE.js +284 -0
  159. package/dist/index-CsKaFB2K.mjs +228 -0
  160. package/dist/index-Cu8Ii5r7.cjs +335 -0
  161. package/dist/index-Cuw9ylL-.mjs +371 -0
  162. package/dist/index-CwOULUAt.mjs +382 -0
  163. package/dist/index-CyVnRqjE.cjs +196 -0
  164. package/dist/index-D-1dDKiZ.mjs +227 -0
  165. package/dist/index-D00bnaJy.cjs +220 -0
  166. package/dist/index-D07xiOJ6.cjs +446 -0
  167. package/dist/index-D1Ip6ro6.js +458 -0
  168. package/dist/index-D1Ymvd2b.cjs +286 -0
  169. package/dist/index-D5jOBT3f.cjs +240 -0
  170. package/dist/index-D5tEp8IU.js +337 -0
  171. package/dist/index-D7WuGKYY.cjs +227 -0
  172. package/dist/index-D8Dp6TnQ.cjs +1837 -0
  173. package/dist/index-D9OKpqgG.js +381 -0
  174. package/dist/index-DBMI2EcB.cjs +170 -0
  175. package/dist/index-DBRUKV0U.mjs +225 -0
  176. package/dist/index-DEvExC5x.cjs +119 -0
  177. package/dist/index-DEzxU_gQ.cjs +507 -0
  178. package/dist/index-DFypMD6R.cjs +261 -0
  179. package/dist/index-DHRqE92a.cjs +290 -0
  180. package/dist/index-DISym5OL.js +198 -0
  181. package/dist/index-DJ3ndv3i.mjs +705 -0
  182. package/dist/index-DJXP-Gmp.js +218 -0
  183. package/dist/index-DJlXDQOY.cjs +200 -0
  184. package/dist/index-DLW4GEJl.cjs +229 -0
  185. package/dist/index-DLu9E2Vq.js +238 -0
  186. package/dist/index-DM4ddIL6.js +382 -0
  187. package/dist/index-DMgHLbwU.cjs +339 -0
  188. package/dist/index-DN-ScBql.mjs +458 -0
  189. package/dist/index-DOkkIHER.js +163 -0
  190. package/dist/index-DRY8sDun.cjs +165 -0
  191. package/dist/index-DS3cjugP.mjs +171 -0
  192. package/dist/index-DS86eFsI.mjs +1835 -0
  193. package/dist/index-DUlT8CJ2.js +458 -0
  194. package/dist/index-DV1F4nxP.js +372 -0
  195. package/dist/index-DXsAcJ-o.mjs +359 -0
  196. package/dist/index-DZws2w4w.cjs +229 -0
  197. package/dist/index-D_HiVe2_.cjs +200 -0
  198. package/dist/index-Da6L5V_Z.mjs +681 -0
  199. package/dist/index-Dbb-jnWf.js +206 -0
  200. package/dist/index-DdXy_-T9.js +444 -0
  201. package/dist/index-DddNFRG3.js +337 -0
  202. package/dist/index-DejhKwvw.cjs +173 -0
  203. package/dist/index-DfBdD-5Z.cjs +383 -0
  204. package/dist/index-Df_KCbC4.mjs +213 -0
  205. package/dist/index-DiDq1sL6.cjs +240 -0
  206. package/dist/index-DiuJQ9Mq.js +198 -0
  207. package/dist/index-Djqj3DWJ.js +171 -0
  208. package/dist/index-Dk0q-ENv.mjs +166 -0
  209. package/dist/index-DlFElztE.mjs +163 -0
  210. package/dist/index-DlkxQ-B5.mjs +359 -0
  211. package/dist/index-Dm5kpK9t.js +227 -0
  212. package/dist/index-Dp8mobro.js +444 -0
  213. package/dist/index-DpBWZa1x.cjs +683 -0
  214. package/dist/index-DrkXuLUZ.js +227 -0
  215. package/dist/index-Dsq1FK90.cjs +275 -0
  216. package/dist/index-DtmhGgM8.cjs +282 -0
  217. package/dist/index-Du5MxO_2.mjs +505 -0
  218. package/dist/index-DveYQLCZ.cjs +460 -0
  219. package/dist/index-DxHMqS-W.js +117 -0
  220. package/dist/index-DyTApTHI.cjs +282 -0
  221. package/dist/index-DyTSkAm4.cjs +208 -0
  222. package/dist/index-DygJOEne.mjs +550 -0
  223. package/dist/index-DzAewrkw.js +238 -0
  224. package/dist/index-ESWdD7ek.cjs +215 -0
  225. package/dist/index-EuKHpnHv.mjs +117 -0
  226. package/dist/index-F1A7LMlw.mjs +228 -0
  227. package/dist/index-FP6hvgSw.cjs +552 -0
  228. package/dist/index-GDSrKnPp.mjs +198 -0
  229. package/dist/index-GMCZo-KH.js +222 -0
  230. package/dist/index-IQJLr7nR.js +288 -0
  231. package/dist/index-IawHHRZX.mjs +206 -0
  232. package/dist/index-Jk7MG7tE.cjs +286 -0
  233. package/dist/index-JtGxTXPr.mjs +337 -0
  234. package/dist/index-KAC20a9r.js +359 -0
  235. package/dist/index-LVWQqV-v.js +163 -0
  236. package/dist/index-Ls2fI7y4.js +163 -0
  237. package/dist/index-NB1VDvjW.cjs +374 -0
  238. package/dist/index-NIEZaRYg.cjs +261 -0
  239. package/dist/index-PQXUx1ZR.mjs +1835 -0
  240. package/dist/index-PyaLRKuk.mjs +168 -0
  241. package/dist/index-QQGo-BV1.mjs +444 -0
  242. package/dist/index-QXYDkAsQ.cjs +119 -0
  243. package/dist/index-SmEIf5jz.mjs +259 -0
  244. package/dist/index-UJhFwnD_.mjs +284 -0
  245. package/dist/index-UVyXzNlG.js +705 -0
  246. package/dist/index-UgyHGpUU.mjs +163 -0
  247. package/dist/index-UhQiJabs.cjs +707 -0
  248. package/dist/index-VvuhRvnC.mjs +218 -0
  249. package/dist/index-WPXuueaq.mjs +194 -0
  250. package/dist/index-X4u6bs58.js +259 -0
  251. package/dist/index-XZiO6uje.cjs +275 -0
  252. package/dist/index-YOlsBREZ.cjs +230 -0
  253. package/dist/index-Ytb942t9.js +587 -0
  254. package/dist/index-_2dg_MWu.cjs +460 -0
  255. package/dist/index-eFEW10em.js +213 -0
  256. package/dist/index-eq8bbEej.mjs +225 -0
  257. package/dist/index-f7FiDQMk.js +171 -0
  258. package/dist/index-fBzI1kbw.mjs +225 -0
  259. package/dist/index-fdDnq3vQ.js +163 -0
  260. package/dist/index-fqmAgjhG.js +206 -0
  261. package/dist/index-ikGyewP-.cjs +165 -0
  262. package/dist/index-jft-1bQ6.cjs +230 -0
  263. package/dist/index-l8e8ip4U.js +168 -0
  264. package/dist/index-lkBiml03.js +1835 -0
  265. package/dist/index-mm-YMeoi.js +505 -0
  266. package/dist/index-o7g3iua7.cjs +290 -0
  267. package/dist/index-ojnncNWd.js +587 -0
  268. package/dist/index-q9SCjCJM.mjs +280 -0
  269. package/dist/index-rn-_7-wp.cjs +196 -0
  270. package/dist/index-s27DHpTG.js +1835 -0
  271. package/dist/index-s2HuXM4d.mjs +206 -0
  272. package/dist/index-sbc7nDv3.js +213 -0
  273. package/dist/index-tx0X6vuE.mjs +222 -0
  274. package/dist/index-uCwv2hr-.mjs +166 -0
  275. package/dist/index-vHngHSlz.js +280 -0
  276. package/dist/index-xOtG5E4u.cjs +589 -0
  277. package/dist/index-zJk-Nm6b.mjs +458 -0
  278. package/dist/index-zqxgDrLR.mjs +382 -0
  279. package/dist/index.cjs +233 -0
  280. package/dist/index.d.cts +9 -0
  281. package/dist/index.d.cts.map +1 -0
  282. package/dist/index.d.ts +9 -0
  283. package/dist/index.d.ts.map +1 -0
  284. package/dist/index.js +230 -0
  285. package/dist/index.mjs +230 -0
  286. package/dist/testkit-BtZjdl4n.js +269 -0
  287. package/dist/testkit-BtZjdl4n.mjs +269 -0
  288. package/dist/testkit-C920qivh.js +281 -0
  289. package/dist/testkit-C920qivh.mjs +281 -0
  290. package/dist/testkit-CAf-AsDy.cjs +273 -0
  291. package/dist/testkit-D0rTQ6MD.cjs +286 -0
  292. package/makefile +47 -0
  293. package/package.json +89 -0
@@ -0,0 +1,372 @@
1
+ import { c as createSubgraph, a as createTest, s as serve } from './testkit-BtZjdl4n.mjs';
2
+ import { s as shouldPunishForPoorPlans } from './env-j1f_SZtG.mjs';
3
+ import '@apollo/composition';
4
+ import 'graphql';
5
+ import 'fets';
6
+ import '@apollo/subgraph';
7
+ import 'graphql-yoga';
8
+
9
+ const products = [
10
+ {
11
+ id: "p1",
12
+ categories: ["c1", "c2"]
13
+ },
14
+ {
15
+ id: "p2",
16
+ categories: ["c3", "c2"]
17
+ }
18
+ ];
19
+ const categories = [
20
+ {
21
+ id: "c1",
22
+ name: "Category 1",
23
+ subCategories: ["c2"]
24
+ },
25
+ {
26
+ id: "c2",
27
+ name: "Category 2",
28
+ subCategories: ["c3"]
29
+ },
30
+ {
31
+ id: "c3",
32
+ name: "Category 3",
33
+ subCategories: ["c1"]
34
+ }
35
+ ];
36
+
37
+ var allProducts = createSubgraph("all-products", {
38
+ typeDefs: (
39
+ /* GraphQL */
40
+ `
41
+ extend schema
42
+ @link(
43
+ url: "https://specs.apollo.dev/federation/v2.3"
44
+ import: ["@key", "@shareable"]
45
+ )
46
+
47
+ type Product @key(fields: "id") {
48
+ id: ID!
49
+ }
50
+ `
51
+ ),
52
+ resolvers: {
53
+ Product: {
54
+ __resolveReference(key) {
55
+ if (shouldPunishForPoorPlans()) {
56
+ throw new Error("You should be using the categories subgraph!");
57
+ }
58
+ const product = products.find((p) => p.id === key.id);
59
+ if (!product) {
60
+ return null;
61
+ }
62
+ return {
63
+ id: product.id
64
+ };
65
+ }
66
+ }
67
+ }
68
+ });
69
+
70
+ var category = createSubgraph("category", {
71
+ typeDefs: (
72
+ /* GraphQL */
73
+ `
74
+ extend schema
75
+ @link(
76
+ url: "https://specs.apollo.dev/federation/v2.3"
77
+ import: ["@key", "@shareable", "@external", "@provides"]
78
+ )
79
+
80
+ type Query {
81
+ products: [Product]
82
+ @shareable
83
+ @provides(fields: "categories { id name subCategories { id name } }")
84
+ }
85
+
86
+ type Product @key(fields: "id") {
87
+ id: ID!
88
+ categories: [Category] @external
89
+ }
90
+
91
+ type Category @key(fields: "id") {
92
+ id: ID!
93
+ """
94
+ This field is provided by Query.products
95
+ and we deliberately don't resolve it.
96
+ The test suite is about checking if @provides is used correctly.
97
+ """
98
+ name: String
99
+ subCategories: [Category] @external
100
+ }
101
+ `
102
+ ),
103
+ resolvers: {
104
+ Query: {
105
+ products() {
106
+ return products.map((p) => ({
107
+ id: p.id,
108
+ categories: p.categories.map((catId) => {
109
+ const cat = categories.find((c) => c.id === catId);
110
+ if (!cat) {
111
+ return null;
112
+ }
113
+ return {
114
+ id: cat.id,
115
+ name: cat.name,
116
+ subCategories: cat.subCategories.map((subCatId) => {
117
+ const subCat = categories.find((c) => c.id === subCatId);
118
+ if (!subCat) {
119
+ return null;
120
+ }
121
+ return {
122
+ id: subCat.id,
123
+ name: subCat.name
124
+ };
125
+ })
126
+ };
127
+ })
128
+ }));
129
+ }
130
+ },
131
+ Product: {
132
+ __resolveReference(key, context) {
133
+ if (shouldPunishForPoorPlans()) {
134
+ throw new Error("You should be using the categories subgraph!");
135
+ }
136
+ const product = products.find((p) => p.id === key.id);
137
+ if (!product) {
138
+ return null;
139
+ }
140
+ return {
141
+ id: product.id
142
+ };
143
+ }
144
+ },
145
+ Category: {
146
+ __resolveReference(key, context) {
147
+ if (shouldPunishForPoorPlans()) {
148
+ throw new Error("You should be using the categories subgraph!");
149
+ }
150
+ const cat = categories.find((c) => c.id === key.id);
151
+ if (!cat) {
152
+ return null;
153
+ }
154
+ return {
155
+ id: cat.id
156
+ // We explicitly don't resolve `name` here
157
+ // name: cat.name,
158
+ };
159
+ }
160
+ }
161
+ }
162
+ });
163
+
164
+ var subcategories = createSubgraph("subcategories", {
165
+ typeDefs: (
166
+ /* GraphQL */
167
+ `
168
+ extend schema
169
+ @link(
170
+ url: "https://specs.apollo.dev/federation/v2.3"
171
+ import: ["@key", "@shareable"]
172
+ )
173
+
174
+ type Product @key(fields: "id") {
175
+ id: ID!
176
+ categories: [Category] @shareable
177
+ }
178
+
179
+ type Category @key(fields: "id") {
180
+ id: ID!
181
+ subCategories: [Category] @shareable
182
+ }
183
+ `
184
+ ),
185
+ resolvers: {
186
+ Product: {
187
+ __resolveReference(key, context) {
188
+ if (shouldPunishForPoorPlans()) {
189
+ throw new Error("You should be using the categories subgraph!");
190
+ }
191
+ const product = products.find((p) => p.id === key.id);
192
+ if (!product) {
193
+ return null;
194
+ }
195
+ return {
196
+ id: product.id,
197
+ categories: product.categories
198
+ };
199
+ },
200
+ categories(product, _a, context) {
201
+ if (shouldPunishForPoorPlans()) {
202
+ throw new Error("You should be using the categories subgraph!");
203
+ }
204
+ return product.categories.map((catId) => {
205
+ const cat = categories.find((c) => c.id === catId);
206
+ if (!cat) {
207
+ return null;
208
+ }
209
+ return {
210
+ id: cat.id,
211
+ subCategories: cat.subCategories
212
+ };
213
+ });
214
+ }
215
+ },
216
+ Category: {
217
+ __resolveReference(key) {
218
+ const cat = categories.find((c) => c.id === key.id);
219
+ if (!cat) {
220
+ return null;
221
+ }
222
+ return {
223
+ id: cat.id,
224
+ subCategories: cat.subCategories
225
+ };
226
+ },
227
+ subCategories(category) {
228
+ return category.subCategories.map((catId) => {
229
+ const cat = categories.find((c) => c.id === catId);
230
+ if (!cat) {
231
+ return null;
232
+ }
233
+ return {
234
+ id: cat.id,
235
+ subCategories: cat.subCategories
236
+ };
237
+ });
238
+ }
239
+ }
240
+ }
241
+ });
242
+
243
+ var test = [
244
+ createTest(
245
+ /* GraphQL */
246
+ `
247
+ query {
248
+ products {
249
+ id
250
+ categories {
251
+ id
252
+ name
253
+ }
254
+ }
255
+ }
256
+ `,
257
+ {
258
+ data: {
259
+ products: [
260
+ {
261
+ id: "p1",
262
+ categories: [
263
+ {
264
+ id: "c1",
265
+ name: "Category 1"
266
+ },
267
+ {
268
+ id: "c2",
269
+ name: "Category 2"
270
+ }
271
+ ]
272
+ },
273
+ {
274
+ id: "p2",
275
+ categories: [
276
+ {
277
+ id: "c3",
278
+ name: "Category 3"
279
+ },
280
+ {
281
+ id: "c2",
282
+ name: "Category 2"
283
+ }
284
+ ]
285
+ }
286
+ ]
287
+ }
288
+ }
289
+ ),
290
+ createTest(
291
+ /* GraphQL */
292
+ `
293
+ query {
294
+ products {
295
+ id
296
+ categories {
297
+ id
298
+ name
299
+ subCategories {
300
+ id
301
+ name
302
+ }
303
+ }
304
+ }
305
+ }
306
+ `,
307
+ {
308
+ data: {
309
+ products: [
310
+ {
311
+ id: "p1",
312
+ categories: [
313
+ {
314
+ id: "c1",
315
+ name: "Category 1",
316
+ subCategories: [
317
+ {
318
+ id: "c2",
319
+ name: "Category 2"
320
+ }
321
+ ]
322
+ },
323
+ {
324
+ id: "c2",
325
+ name: "Category 2",
326
+ subCategories: [
327
+ {
328
+ id: "c3",
329
+ name: "Category 3"
330
+ }
331
+ ]
332
+ }
333
+ ]
334
+ },
335
+ {
336
+ id: "p2",
337
+ categories: [
338
+ {
339
+ id: "c3",
340
+ name: "Category 3",
341
+ subCategories: [
342
+ {
343
+ id: "c1",
344
+ name: "Category 1"
345
+ }
346
+ ]
347
+ },
348
+ {
349
+ id: "c2",
350
+ name: "Category 2",
351
+ subCategories: [
352
+ {
353
+ id: "c3",
354
+ name: "Category 3"
355
+ }
356
+ ]
357
+ }
358
+ ]
359
+ }
360
+ ]
361
+ }
362
+ }
363
+ )
364
+ ];
365
+
366
+ var index = serve(
367
+ "nested-provides",
368
+ [allProducts, category, subcategories],
369
+ test
370
+ );
371
+
372
+ export { index as default };
@@ -0,0 +1,280 @@
1
+ import { c as createSubgraph, a as createTest, s as serve } from './testkit-C920qivh.mjs';
2
+ import { GraphQLError } from 'graphql';
3
+ import '@apollo/composition';
4
+ import 'fets';
5
+ import '@apollo/subgraph';
6
+ import 'graphql-yoga';
7
+
8
+ const products = [
9
+ {
10
+ id: "p1",
11
+ price: 699.99,
12
+ hasDiscount: true
13
+ }
14
+ ];
15
+
16
+ var a = createSubgraph("a", {
17
+ typeDefs: (
18
+ /* GraphQL */
19
+ `
20
+ extend schema
21
+ @link(
22
+ url: "https://specs.apollo.dev/federation/v2.3"
23
+ import: ["@key", "@inaccessible"]
24
+ )
25
+
26
+ type Product @key(fields: "id") {
27
+ id: ID!
28
+ price: Float! @inaccessible
29
+ }
30
+ `
31
+ ),
32
+ resolvers: {
33
+ Product: {
34
+ __resolveReference(key) {
35
+ const product = products.find((product2) => product2.id === key.id);
36
+ if (!product) {
37
+ return null;
38
+ }
39
+ return {
40
+ id: product.id,
41
+ price: product.price
42
+ };
43
+ }
44
+ }
45
+ }
46
+ });
47
+
48
+ var b = createSubgraph("b", {
49
+ typeDefs: (
50
+ /* GraphQL */
51
+ `
52
+ extend schema
53
+ @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"])
54
+
55
+ type Query {
56
+ product: Product
57
+ }
58
+
59
+ type Product @key(fields: "id") {
60
+ id: ID!
61
+ hasDiscount: Boolean!
62
+ }
63
+ `
64
+ ),
65
+ resolvers: {
66
+ Query: {
67
+ product() {
68
+ return {
69
+ id: products[0].id,
70
+ hasDiscount: products[0].hasDiscount
71
+ };
72
+ }
73
+ },
74
+ Product: {
75
+ __resolveReference(key) {
76
+ const product = products.find((product2) => product2.id === key.id);
77
+ if (!product) {
78
+ return null;
79
+ }
80
+ return {
81
+ id: product.id,
82
+ hasDiscount: product.hasDiscount
83
+ };
84
+ }
85
+ }
86
+ }
87
+ });
88
+
89
+ var c = createSubgraph("c", {
90
+ typeDefs: (
91
+ /* GraphQL */
92
+ `
93
+ extend schema
94
+ @link(
95
+ url: "https://specs.apollo.dev/federation/v2.3"
96
+ import: ["@key", "@external", "@requires"]
97
+ )
98
+
99
+ type Product @key(fields: "id") {
100
+ id: ID!
101
+ price: Float! @external
102
+ isExpensive: Boolean! @requires(fields: "price")
103
+ hasDiscount: Boolean! @external
104
+ isExpensiveWithDiscount: Boolean! @requires(fields: "hasDiscount")
105
+ }
106
+ `
107
+ ),
108
+ resolvers: {
109
+ Product: {
110
+ __resolveReference(key) {
111
+ if (!products.find((product2) => product2.id === key.id)) {
112
+ return null;
113
+ }
114
+ const product = {
115
+ __typename: "Product",
116
+ id: key.id
117
+ };
118
+ if (typeof key.price === "number") {
119
+ product.price = key.price;
120
+ product.isExpensive = key.price > 500;
121
+ } else if ("price" in key && typeof key.price !== "undefined") {
122
+ return new GraphQLError("Product.price must be a number");
123
+ }
124
+ if (typeof key.hasDiscount === "boolean") {
125
+ product.hasDiscount = key.hasDiscount;
126
+ product.isExpensiveWithDiscount = !key.hasDiscount;
127
+ } else if ("hasDiscount" in key && typeof key.hasDiscount !== "undefined") {
128
+ return new GraphQLError("Product.hasDiscount must be a number");
129
+ }
130
+ return product;
131
+ }
132
+ }
133
+ }
134
+ });
135
+
136
+ var d = createSubgraph("d", {
137
+ typeDefs: (
138
+ /* GraphQL */
139
+ `
140
+ extend schema
141
+ @link(
142
+ url: "https://specs.apollo.dev/federation/v2.3"
143
+ import: ["@key", "@external", "@requires"]
144
+ )
145
+
146
+ type Product @key(fields: "id") {
147
+ id: ID!
148
+ isExpensive: Boolean! @external
149
+ canAfford: Boolean! @requires(fields: "isExpensive")
150
+ isExpensiveWithDiscount: Boolean! @external
151
+ canAffordWithDiscount: Boolean!
152
+ @requires(fields: "isExpensiveWithDiscount")
153
+ }
154
+ `
155
+ ),
156
+ resolvers: {
157
+ Product: {
158
+ __resolveReference(key) {
159
+ if (!products.find((product2) => product2.id === key.id)) {
160
+ return null;
161
+ }
162
+ const product = {
163
+ __typename: "Product",
164
+ id: key.id
165
+ };
166
+ if (typeof key.isExpensive === "boolean") {
167
+ product.isExpensive = key.isExpensive;
168
+ product.canAfford = !key.isExpensive;
169
+ } else if ("isExpensive" in key && typeof key.isExpensive !== "undefined") {
170
+ return new GraphQLError("Product.isExpensive must be a boolean");
171
+ }
172
+ if (typeof key.isExpensiveWithDiscount === "boolean") {
173
+ product.isExpensiveWithDiscount = key.isExpensiveWithDiscount;
174
+ product.canAffordWithDiscount = !key.isExpensiveWithDiscount;
175
+ } else if ("isExpensiveWithDiscount" in key && typeof key.isExpensiveWithDiscount !== "undefined") {
176
+ return new GraphQLError(
177
+ "Product.isExpensiveWithDiscount must be a boolean"
178
+ );
179
+ }
180
+ return product;
181
+ }
182
+ }
183
+ }
184
+ });
185
+
186
+ var test = [
187
+ createTest(
188
+ /* GraphQL */
189
+ `
190
+ query {
191
+ product {
192
+ canAfford
193
+ }
194
+ }
195
+ `,
196
+ {
197
+ data: {
198
+ product: {
199
+ canAfford: false
200
+ }
201
+ }
202
+ }
203
+ ),
204
+ createTest(
205
+ /* GraphQL */
206
+ `
207
+ query {
208
+ product {
209
+ isExpensive
210
+ }
211
+ }
212
+ `,
213
+ {
214
+ data: {
215
+ product: {
216
+ isExpensive: true
217
+ }
218
+ }
219
+ }
220
+ ),
221
+ createTest(
222
+ /* GraphQL */
223
+ `
224
+ query {
225
+ product {
226
+ isExpensive
227
+ canAfford
228
+ }
229
+ }
230
+ `,
231
+ {
232
+ data: {
233
+ product: {
234
+ isExpensive: true,
235
+ canAfford: false
236
+ }
237
+ }
238
+ }
239
+ ),
240
+ createTest(
241
+ /* GraphQL */
242
+ `
243
+ query {
244
+ product {
245
+ canAffordWithDiscount
246
+ }
247
+ }
248
+ `,
249
+ {
250
+ data: {
251
+ product: {
252
+ canAffordWithDiscount: true
253
+ }
254
+ }
255
+ }
256
+ ),
257
+ createTest(
258
+ /* GraphQL */
259
+ `
260
+ query {
261
+ product {
262
+ canAfford
263
+ canAffordWithDiscount
264
+ }
265
+ }
266
+ `,
267
+ {
268
+ data: {
269
+ product: {
270
+ canAfford: false,
271
+ canAffordWithDiscount: true
272
+ }
273
+ }
274
+ }
275
+ )
276
+ ];
277
+
278
+ var index = serve("requires-requires", [a, b, c, d], test);
279
+
280
+ export { index as default };