@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,383 @@
1
+ 'use strict';
2
+
3
+ var testkit = require('./testkit-D0rTQ6MD.cjs');
4
+ require('@apollo/composition');
5
+ require('graphql');
6
+ require('fets');
7
+ require('@apollo/subgraph');
8
+ require('graphql-yoga');
9
+
10
+ let products = [];
11
+ let categories = [];
12
+ const numbers = {};
13
+ async function getProducts() {
14
+ return products;
15
+ }
16
+ function getCategories() {
17
+ return categories;
18
+ }
19
+ async function addProduct(name, price) {
20
+ const newProduct = {
21
+ id: "p-added-" + products.length,
22
+ name,
23
+ price
24
+ };
25
+ products.push(newProduct);
26
+ return newProduct;
27
+ }
28
+ async function addCategory(name, requestId) {
29
+ if (categories.some((c) => c.id === "c-added-" + requestId)) {
30
+ throw new Error("Category with this requestId was already added");
31
+ }
32
+ const newCategory = {
33
+ id: "c-added-" + requestId,
34
+ name
35
+ };
36
+ categories.push(newCategory);
37
+ return newCategory;
38
+ }
39
+ async function deleteProduct(id) {
40
+ const after = products.filter((p) => p.id !== id);
41
+ products = after;
42
+ }
43
+ function initProducts() {
44
+ const product = {
45
+ id: "p1",
46
+ name: "p1-name",
47
+ price: 9.99
48
+ };
49
+ if (products.some((p) => p.id === product.id)) {
50
+ return;
51
+ }
52
+ products.push(product);
53
+ }
54
+ function getNumber(requestId) {
55
+ const num = numbers[requestId];
56
+ return num ?? 0;
57
+ }
58
+ function addNumber(num, requestId) {
59
+ const existingNumber = getNumber(requestId);
60
+ const sum = existingNumber + num;
61
+ numbers[requestId] = sum;
62
+ return sum;
63
+ }
64
+ function multiplyNumber(by, requestId) {
65
+ const existingNumber = getNumber(requestId);
66
+ const result = existingNumber * by;
67
+ numbers[requestId] = result;
68
+ return result;
69
+ }
70
+ function deleteNumber(requestId) {
71
+ const num = getNumber(requestId);
72
+ if (typeof numbers[requestId] === "number") {
73
+ delete numbers[requestId];
74
+ }
75
+ return num;
76
+ }
77
+
78
+ var a = testkit.createSubgraph("a", {
79
+ typeDefs: (
80
+ /* GraphQL */
81
+ `
82
+ extend schema
83
+ @link(
84
+ url: "https://specs.apollo.dev/federation/v2.3"
85
+ import: ["@key", "@shareable"]
86
+ )
87
+
88
+ type Mutation {
89
+ addProduct(input: AddProductInput!): Product!
90
+ addCategory(name: String!, requestId: String!): Category! @shareable
91
+ multiply(by: Int!, requestId: String!): Int!
92
+ }
93
+
94
+ type Query {
95
+ product(id: ID!): Product!
96
+ products: [Product!]!
97
+ }
98
+
99
+ input AddProductInput {
100
+ name: String!
101
+ price: Float!
102
+ }
103
+
104
+ type Product @key(fields: "id") {
105
+ id: ID!
106
+ name: String!
107
+ price: Float!
108
+ }
109
+
110
+ type Category @key(fields: "id") {
111
+ id: ID!
112
+ }
113
+ `
114
+ ),
115
+ resolvers: {
116
+ Query: {
117
+ async product(_, { id }) {
118
+ initProducts();
119
+ const product = (await getProducts()).find((p) => p.id === id);
120
+ if (!product) {
121
+ return null;
122
+ }
123
+ return {
124
+ id: product.id,
125
+ name: product.name,
126
+ price: product.price
127
+ };
128
+ },
129
+ async products() {
130
+ initProducts();
131
+ return getProducts();
132
+ }
133
+ },
134
+ Mutation: {
135
+ async multiply(_, args) {
136
+ return multiplyNumber(args.by, args.requestId);
137
+ },
138
+ async addProduct(_, {
139
+ input
140
+ }) {
141
+ return addProduct(input.name, input.price);
142
+ },
143
+ async addCategory(_, {
144
+ name,
145
+ requestId
146
+ }) {
147
+ return addCategory(name, requestId);
148
+ }
149
+ },
150
+ Product: {
151
+ async __resolveReference(key) {
152
+ const products = await getProducts();
153
+ const product = products.find((p) => p.id === key.id);
154
+ if (!product) {
155
+ return null;
156
+ }
157
+ await deleteProduct(product.id);
158
+ return {
159
+ id: product.id,
160
+ name: product.name,
161
+ price: product.price
162
+ };
163
+ }
164
+ },
165
+ Category: {
166
+ __resolveReference(key) {
167
+ const categories = getCategories();
168
+ const category = categories.find((p) => p.id === key.id);
169
+ if (!category) {
170
+ return null;
171
+ }
172
+ return {
173
+ id: category.id
174
+ };
175
+ }
176
+ }
177
+ }
178
+ });
179
+
180
+ var b = testkit.createSubgraph("b", {
181
+ typeDefs: (
182
+ /* GraphQL */
183
+ `
184
+ extend schema
185
+ @link(
186
+ url: "https://specs.apollo.dev/federation/v2.3"
187
+ import: ["@key", "@external", "@requires", "@shareable"]
188
+ )
189
+
190
+ type Product @key(fields: "id") {
191
+ id: ID!
192
+ price: Float! @external
193
+ isExpensive: Boolean! @requires(fields: "price")
194
+ isAvailable: Boolean!
195
+ }
196
+
197
+ type Mutation {
198
+ delete(requestId: String!): Int!
199
+ addCategory(name: String!, requestId: String!): Category! @shareable
200
+ }
201
+
202
+ type Category @key(fields: "id") {
203
+ id: ID!
204
+ name: String!
205
+ }
206
+ `
207
+ ),
208
+ resolvers: {
209
+ Mutation: {
210
+ delete(_, args) {
211
+ return deleteNumber(args.requestId);
212
+ },
213
+ async addCategory(_, {
214
+ name,
215
+ requestId
216
+ }) {
217
+ return addCategory(name, requestId);
218
+ }
219
+ },
220
+ Product: {
221
+ async __resolveReference(key) {
222
+ const product = (await getProducts()).find(
223
+ (product2) => product2.id === key.id
224
+ );
225
+ if (!product) {
226
+ return null;
227
+ }
228
+ await deleteProduct(product.id);
229
+ if (typeof product.price === "number") {
230
+ return {
231
+ id: product.id,
232
+ isAvailable: true,
233
+ price: product.price
234
+ };
235
+ }
236
+ return {
237
+ id: product.id,
238
+ isAvailable: false
239
+ };
240
+ },
241
+ isExpensive(product) {
242
+ if (typeof product.price !== "number") {
243
+ throw new Error("Price is not available");
244
+ }
245
+ return product.price > 100;
246
+ }
247
+ },
248
+ Category: {
249
+ __resolveReference(key) {
250
+ const categories = getCategories();
251
+ const category = categories.find((p) => p.id === key.id);
252
+ if (!category) {
253
+ return null;
254
+ }
255
+ return {
256
+ id: category.id,
257
+ name: category.name
258
+ };
259
+ }
260
+ }
261
+ }
262
+ });
263
+
264
+ var c = testkit.createSubgraph("c", {
265
+ typeDefs: (
266
+ /* GraphQL */
267
+ `
268
+ extend schema
269
+ @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"])
270
+
271
+ type Mutation {
272
+ add(num: Int!, requestId: String!): Int!
273
+ }
274
+ `
275
+ ),
276
+ resolvers: {
277
+ Mutation: {
278
+ add(_, args) {
279
+ return addNumber(args.num, args.requestId);
280
+ }
281
+ }
282
+ }
283
+ });
284
+
285
+ var test = () => {
286
+ const randomId = Math.random().toString(16).substr(2);
287
+ return [
288
+ testkit.createTest(
289
+ /* GraphQL */
290
+ `
291
+ mutation {
292
+ addProduct(input: { name: "new", price: 599.99 }) {
293
+ name
294
+ price
295
+ isExpensive
296
+ isAvailable
297
+ }
298
+ }
299
+ `,
300
+ {
301
+ data: {
302
+ addProduct: {
303
+ name: "new",
304
+ price: 599.99,
305
+ isExpensive: true,
306
+ isAvailable: true
307
+ }
308
+ }
309
+ }
310
+ ),
311
+ testkit.createTest(
312
+ /* GraphQL */
313
+ `
314
+ query {
315
+ product(id: "p1") {
316
+ id
317
+ name
318
+ price
319
+ isExpensive
320
+ isAvailable
321
+ }
322
+ }
323
+ `,
324
+ {
325
+ data: {
326
+ product: {
327
+ id: "p1",
328
+ name: "p1-name",
329
+ price: 9.99,
330
+ isExpensive: false,
331
+ isAvailable: true
332
+ }
333
+ }
334
+ }
335
+ ),
336
+ // Test correct order of execution
337
+ // It obviously does not solve a problem with shared state and race conditions,
338
+ // but at least it reduces the risk a bit
339
+ testkit.createTest(
340
+ /* GraphQL */
341
+ `
342
+ mutation {
343
+ five: add(num: 5, requestId: "${randomId}")
344
+ ten: multiply(by: 2, requestId: "${randomId}")
345
+ twelve: add(num: 2, requestId: "${randomId}")
346
+ final: delete(requestId: "${randomId}")
347
+ }
348
+ `,
349
+ {
350
+ data: {
351
+ five: 5,
352
+ ten: 10,
353
+ twelve: 12,
354
+ final: 12
355
+ }
356
+ }
357
+ ),
358
+ // shared-root (mutation)
359
+ testkit.createTest(
360
+ /* GraphQL */
361
+ `
362
+ mutation {
363
+ addCategory(name: "new", requestId: "${randomId}") {
364
+ id
365
+ name
366
+ }
367
+ }
368
+ `,
369
+ {
370
+ data: {
371
+ addCategory: {
372
+ id: "c-added-" + randomId,
373
+ name: "new"
374
+ }
375
+ }
376
+ }
377
+ )
378
+ ];
379
+ };
380
+
381
+ var index = testkit.serve("mutations", [a, b, c], test);
382
+
383
+ exports.default = index;
@@ -0,0 +1,288 @@
1
+ import { c as createSubgraph, a as createTest, s as serve } from './testkit-BtZjdl4n.mjs';
2
+ import '@apollo/composition';
3
+ import 'graphql';
4
+ import 'fets';
5
+ import '@apollo/subgraph';
6
+ import 'graphql-yoga';
7
+
8
+ const products = [
9
+ {
10
+ id: "p1",
11
+ pid: "p1-pid",
12
+ categoryId: "c1"
13
+ },
14
+ {
15
+ id: "p2",
16
+ pid: "p2-pid",
17
+ categoryId: "c2"
18
+ },
19
+ {
20
+ id: "p3",
21
+ pid: "p3-pid",
22
+ categoryId: "c1"
23
+ }
24
+ ];
25
+ const categories = [
26
+ {
27
+ id: "c1",
28
+ name: "c1-name",
29
+ details: {
30
+ products: products.filter((p) => p.categoryId === "c1").length
31
+ }
32
+ },
33
+ {
34
+ id: "c2",
35
+ name: "c2-name",
36
+ details: {
37
+ products: products.filter((p) => p.categoryId === "c2").length
38
+ }
39
+ }
40
+ ];
41
+
42
+ var a = createSubgraph("a", {
43
+ typeDefs: (
44
+ /* GraphQL */
45
+ `
46
+ extend schema
47
+ @link(
48
+ url: "https://specs.apollo.dev/federation/v2.3"
49
+ import: ["@key", "@external", "@shareable"]
50
+ )
51
+
52
+ type Query {
53
+ products: [Product!]!
54
+ }
55
+
56
+ type Product @key(fields: "id") @key(fields: "id pid") {
57
+ id: ID!
58
+ pid: ID!
59
+ category: Category @shareable
60
+ }
61
+
62
+ type Category @key(fields: "id") {
63
+ id: ID!
64
+ name: String! @shareable
65
+ }
66
+ `
67
+ ),
68
+ resolvers: {
69
+ Query: {
70
+ products() {
71
+ return products.map((p) => ({
72
+ id: p.id,
73
+ pid: p.pid,
74
+ categoryId: p.categoryId
75
+ }));
76
+ }
77
+ },
78
+ Product: {
79
+ __resolveReference(key) {
80
+ const product = products.find(
81
+ (p) => p.id === key.id && ("pid" in key ? p.pid === key.pid : true)
82
+ );
83
+ if (!product) {
84
+ return null;
85
+ }
86
+ return {
87
+ id: product.id,
88
+ pid: product.pid,
89
+ categoryId: product.categoryId
90
+ };
91
+ },
92
+ category(product) {
93
+ const category = categories.find((c) => c.id === product.categoryId);
94
+ if (!category) {
95
+ return null;
96
+ }
97
+ return {
98
+ id: category.id,
99
+ name: category.name
100
+ };
101
+ }
102
+ },
103
+ Category: {
104
+ __resolveReference(key) {
105
+ const category = categories.find((c) => c.id === key.id);
106
+ if (!category) {
107
+ return null;
108
+ }
109
+ return {
110
+ id: category.id,
111
+ name: category.name
112
+ };
113
+ }
114
+ }
115
+ }
116
+ });
117
+
118
+ var b = createSubgraph("b", {
119
+ typeDefs: (
120
+ /* GraphQL */
121
+ `
122
+ extend schema
123
+ @link(
124
+ url: "https://specs.apollo.dev/federation/v2.3"
125
+ import: ["@key", "@shareable"]
126
+ )
127
+
128
+ type Product @key(fields: "id pid") {
129
+ id: ID!
130
+ pid: ID!
131
+ category: Category @shareable
132
+ }
133
+
134
+ type Category @key(fields: "id") {
135
+ id: ID!
136
+ name: String! @shareable
137
+ }
138
+ `
139
+ ),
140
+ resolvers: {
141
+ Product: {
142
+ __resolveReference(key) {
143
+ const product = products.find(
144
+ (p) => p.id === key.id && p.pid === key.pid
145
+ );
146
+ if (!product) {
147
+ return null;
148
+ }
149
+ return {
150
+ id: product.id,
151
+ pid: product.pid,
152
+ categoryId: product.categoryId
153
+ };
154
+ },
155
+ category(product) {
156
+ const category = categories.find((c) => c.id === product.categoryId);
157
+ if (!category) {
158
+ return null;
159
+ }
160
+ return {
161
+ id: category.id,
162
+ name: category.name
163
+ };
164
+ }
165
+ },
166
+ Category: {
167
+ __resolveReference(key) {
168
+ const category = categories.find((c) => c.id === key.id);
169
+ if (!category) {
170
+ return null;
171
+ }
172
+ return {
173
+ id: category.id,
174
+ name: category.name
175
+ };
176
+ }
177
+ }
178
+ }
179
+ });
180
+
181
+ var c = createSubgraph("c", {
182
+ typeDefs: (
183
+ /* GraphQL */
184
+ `
185
+ extend schema
186
+ @link(
187
+ url: "https://specs.apollo.dev/federation/v2.3"
188
+ import: ["@key", "@shareable"]
189
+ )
190
+
191
+ type Category {
192
+ details: CategoryDetails
193
+ }
194
+
195
+ type Product @key(fields: "id pid") {
196
+ id: ID!
197
+ pid: ID!
198
+ category: Category @shareable
199
+ }
200
+
201
+ type CategoryDetails {
202
+ products: Int
203
+ }
204
+ `
205
+ ),
206
+ resolvers: {
207
+ Product: {
208
+ __resolveReference(key) {
209
+ const product = products.find(
210
+ (p) => p.id === key.id && p.pid === key.pid
211
+ );
212
+ if (!product) {
213
+ return null;
214
+ }
215
+ return {
216
+ id: product.id,
217
+ pid: product.pid,
218
+ categoryId: product.categoryId
219
+ };
220
+ },
221
+ category(product) {
222
+ const category = categories.find((c) => c.id === product.categoryId);
223
+ if (!category) {
224
+ return null;
225
+ }
226
+ return {
227
+ details: category.details
228
+ };
229
+ }
230
+ }
231
+ }
232
+ });
233
+
234
+ var test = [
235
+ createTest(
236
+ /* GraphQL */
237
+ `
238
+ query {
239
+ products {
240
+ id
241
+ category {
242
+ id
243
+ details {
244
+ products
245
+ }
246
+ }
247
+ }
248
+ }
249
+ `,
250
+ {
251
+ data: {
252
+ products: [
253
+ {
254
+ id: "p1",
255
+ category: {
256
+ id: "c1",
257
+ details: {
258
+ products: 2
259
+ }
260
+ }
261
+ },
262
+ {
263
+ id: "p2",
264
+ category: {
265
+ id: "c2",
266
+ details: {
267
+ products: 1
268
+ }
269
+ }
270
+ },
271
+ {
272
+ id: "p3",
273
+ category: {
274
+ id: "c1",
275
+ details: {
276
+ products: 2
277
+ }
278
+ }
279
+ }
280
+ ]
281
+ }
282
+ }
283
+ )
284
+ ];
285
+
286
+ var index = serve("parent-entity-call", [a, b, c], test);
287
+
288
+ export { index as default };