@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
package/dist/cli.js ADDED
@@ -0,0 +1,547 @@
1
+ #!/usr/bin/env node
2
+ import { writeFileSync, existsSync, mkdirSync, createWriteStream, readFileSync } from 'node:fs';
3
+ import retry from 'async-retry';
4
+ import yargs from 'yargs';
5
+ import waitOn from 'wait-on';
6
+ import getPort from 'get-port';
7
+ import detectPort from 'detect-port';
8
+ import { spawn } from 'node:child_process';
9
+ import { hideBin } from 'yargs/helpers';
10
+ import { run } from 'node:test';
11
+ import { tap, junit } from 'node:test/reporters';
12
+ import { styleText } from 'node:util';
13
+ import { killPortProcess } from 'kill-port-process';
14
+ import { dirname, extname, join } from 'node:path';
15
+ import { fileURLToPath } from 'node:url';
16
+ import { serve } from './index.js';
17
+ import 'fets';
18
+ import 'node:http';
19
+
20
+ process.removeAllListeners("warning");
21
+ const __dirname$1 = dirname(fileURLToPath(import.meta.url));
22
+ const ext = extname(fileURLToPath(import.meta.url));
23
+ const defaultPort = 4200;
24
+ function readPort(address) {
25
+ return parseInt(new URL(address).port, 10);
26
+ }
27
+ function resolvePath(argv, path) {
28
+ if (path.startsWith("/")) {
29
+ return path;
30
+ }
31
+ return join(argv.cwd, path);
32
+ }
33
+ yargs(hideBin(process.argv)).scriptName("graphql-federation-audit").epilogue(
34
+ "for more information, find our manual at https://github.com/the-guild-org/federation-compatibility"
35
+ ).version(readVersion() ?? "local").recommendCommands().option("cwd", {
36
+ describe: "Change the current working directory",
37
+ type: "string",
38
+ default: process.cwd()
39
+ }).command(
40
+ "serve",
41
+ "start the server",
42
+ (yargs2) => {
43
+ return yargs2.option("port", {
44
+ describe: "port to bind on",
45
+ default: defaultPort
46
+ });
47
+ },
48
+ async (argv) => {
49
+ await serve(argv.port);
50
+ console.log("Server started on port", argv.port);
51
+ }
52
+ ).command(
53
+ "supergraph",
54
+ "fetch a supergraph.graphql for a test group",
55
+ (yargs2) => {
56
+ return yargs2.option("test", {
57
+ describe: "test group id",
58
+ type: "string"
59
+ }).option("port", {
60
+ describe: "port to bind on",
61
+ default: defaultPort
62
+ }).demandOption("test");
63
+ },
64
+ async (argv) => {
65
+ const res = await fetch(
66
+ `http://localhost:${argv.port}/${argv.test}/supergraph`
67
+ );
68
+ if (!res.ok) {
69
+ process.stderr.write("Failed to fetch supergraph");
70
+ process.stderr.write(`HTTP ${res.status} ${res.statusText}`);
71
+ process.stderr.write('Body: "' + await res.text() + '"');
72
+ process.exit(1);
73
+ }
74
+ writeFileSync(resolvePath(argv, "supergraph.graphql"), await res.text());
75
+ process.exit(0);
76
+ }
77
+ ).command(
78
+ "subgraphs",
79
+ "fetch a subgraphs.json for a test group",
80
+ (yargs2) => {
81
+ return yargs2.option("test", {
82
+ describe: "test group id",
83
+ type: "string"
84
+ }).option("port", {
85
+ describe: "port to bind on",
86
+ default: defaultPort
87
+ }).demandOption("test");
88
+ },
89
+ async (argv) => {
90
+ const endpoint = `http://localhost:${argv.port}/${argv.test}/subgraphs`;
91
+ const res = await fetch(endpoint, {
92
+ headers: {
93
+ accept: "application/json"
94
+ }
95
+ });
96
+ if (!res.ok) {
97
+ process.stderr.write("Failed to fetch subgraphs: " + endpoint);
98
+ process.stderr.write(`HTTP ${res.status} ${res.statusText}`);
99
+ process.stderr.write('Body: "' + await res.text() + '"');
100
+ process.exit(1);
101
+ }
102
+ writeFileSync(resolvePath(argv, "subgraphs.json"), await res.text());
103
+ process.exit(0);
104
+ }
105
+ ).command(
106
+ "start",
107
+ "start a gateway for a requested test group",
108
+ (yargs2) => {
109
+ return yargs2.option("test", {
110
+ describe: "Test group id",
111
+ type: "string"
112
+ }).option("run-script", {
113
+ describe: "Path to a bash script to run before each test",
114
+ type: "string"
115
+ }).option("graphql", {
116
+ describe: "GraphQL endpoint serving the supergraph",
117
+ type: "string"
118
+ }).option("healthcheck", {
119
+ describe: "Health check endpoint",
120
+ type: "string"
121
+ }).option("port", {
122
+ describe: "Port to bind on",
123
+ default: defaultPort
124
+ }).demandOption("test").demandOption("graphql").demandOption("healthcheck").demandOption("run-script");
125
+ },
126
+ async (argv) => {
127
+ const abortSignal = new AbortController();
128
+ process.once("SIGINT", () => {
129
+ if (!abortSignal.signal.aborted) {
130
+ abortSignal.abort();
131
+ }
132
+ });
133
+ process.once("SIGTERM", () => {
134
+ if (!abortSignal.signal.aborted) {
135
+ abortSignal.abort();
136
+ }
137
+ });
138
+ const port = argv.port ?? await getPort();
139
+ await serve(port);
140
+ process.stdout.write("\n");
141
+ await killPortIfRunning(readPort(argv.graphql)).catch(() => {
142
+ });
143
+ const gatewayExit = Promise.withResolvers();
144
+ const gateway = spawn("sh", [argv.runScript, argv.test], {
145
+ signal: abortSignal.signal,
146
+ stdio: "inherit",
147
+ cwd: dirname(resolvePath(argv, argv.runScript))
148
+ });
149
+ gateway.on("error", (err) => {
150
+ if (err.message.includes("aborted")) {
151
+ return;
152
+ }
153
+ process.stderr.write(err.message);
154
+ });
155
+ gateway.once("exit", () => {
156
+ gatewayExit.resolve();
157
+ });
158
+ await gatewayExit.promise;
159
+ }
160
+ ).command(
161
+ "test-suite",
162
+ "run a test group",
163
+ (yargs2) => {
164
+ return yargs2.option("test", {
165
+ describe: "Test group id",
166
+ type: "string"
167
+ }).option("run-script", {
168
+ describe: "Path to a bash script to run before each test",
169
+ type: "string"
170
+ }).option("graphql", {
171
+ describe: "GraphQL endpoint serving the supergraph",
172
+ type: "string"
173
+ }).option("healthcheck", {
174
+ describe: "Health check endpoint",
175
+ type: "string"
176
+ }).option("port", {
177
+ describe: "Port to bind on",
178
+ default: defaultPort
179
+ }).option("no-server", {
180
+ describe: "Skip starting the server",
181
+ type: "boolean",
182
+ default: false
183
+ }).option("reporter", {
184
+ describe: "Choose a reporter",
185
+ choices: ["dot", "tap"],
186
+ default: "tap"
187
+ }).option("junit", {
188
+ describe: "Write test results to a JUnit XML file",
189
+ type: "boolean"
190
+ }).demandOption("test").demandOption("graphql").demandOption("healthcheck").demandOption("run-script");
191
+ },
192
+ async (argv) => {
193
+ const abortSignal = new AbortController();
194
+ process.once("SIGINT", () => {
195
+ if (!abortSignal.signal.aborted) {
196
+ abortSignal.abort();
197
+ }
198
+ });
199
+ process.once("SIGTERM", () => {
200
+ if (!abortSignal.signal.aborted) {
201
+ abortSignal.abort();
202
+ }
203
+ });
204
+ const port = argv.port ?? await getPort();
205
+ if (!argv["no-server"]) {
206
+ await serve(port);
207
+ }
208
+ process.stdout.write("\n");
209
+ if (!existsSync(resolvePath(argv, "./logs"))) {
210
+ mkdirSync(resolvePath(argv, "./logs"));
211
+ }
212
+ await killPortIfRunning(readPort(argv.graphql)).catch(() => {
213
+ });
214
+ const logStream = createWriteStream(
215
+ resolvePath(argv, `./logs/${argv.test}-gateway.log`),
216
+ {
217
+ flags: "w+"
218
+ }
219
+ );
220
+ const gatewayExit = Promise.withResolvers();
221
+ let gatewayExited = false;
222
+ const gateway = spawn("sh", [argv.runScript, argv.test], {
223
+ signal: abortSignal.signal,
224
+ stdio: "pipe",
225
+ cwd: dirname(resolvePath(argv, argv.runScript))
226
+ });
227
+ gateway.once("exit", () => {
228
+ gatewayExited = true;
229
+ gatewayExit.resolve();
230
+ });
231
+ gateway.stdout.pipe(logStream);
232
+ gateway.stderr.pipe(logStream);
233
+ const result = await runTest({
234
+ ...argv,
235
+ reporter: argv.reporter === "tap" ? "tap" : "dot",
236
+ junit: argv.junit,
237
+ port
238
+ });
239
+ if (!gatewayExited) {
240
+ gateway.kill();
241
+ }
242
+ await gatewayExit.promise;
243
+ process.stdout.write("\n");
244
+ if (result.includes("X")) {
245
+ process.exit(1);
246
+ } else {
247
+ process.exit(0);
248
+ }
249
+ }
250
+ ).command(
251
+ "test",
252
+ "run all test groups in a sequence",
253
+ (yargs2) => {
254
+ return yargs2.option("run-script", {
255
+ describe: "Path to a bash script to run before each test",
256
+ type: "string"
257
+ }).option("no-server", {
258
+ describe: "Skip starting the server",
259
+ type: "boolean",
260
+ default: false
261
+ }).option("graphql", {
262
+ describe: "GraphQL endpoint serving the supergraph",
263
+ type: "string"
264
+ }).option("healthcheck", {
265
+ describe: "Health check endpoint",
266
+ type: "string"
267
+ }).option("port", {
268
+ describe: "Port to bind on",
269
+ default: defaultPort
270
+ }).option("reporter", {
271
+ describe: "Choose a reporter",
272
+ choices: ["dot", "tap"],
273
+ default: "dot"
274
+ }).option("junit", {
275
+ describe: "Write test results to a JUnit XML file",
276
+ type: "boolean"
277
+ }).option("write", {
278
+ describe: "Write test results to a file",
279
+ type: "string",
280
+ default: "results.txt"
281
+ }).option("exit-on-fail", {
282
+ describe: "Exit with status 1 if any test fails",
283
+ type: "boolean",
284
+ default: false
285
+ }).demandOption("graphql").demandOption("healthcheck").demandOption("run-script");
286
+ },
287
+ async (argv) => {
288
+ const abortSignal = new AbortController();
289
+ process.once("SIGINT", () => {
290
+ if (!abortSignal.signal.aborted) {
291
+ abortSignal.abort();
292
+ }
293
+ });
294
+ process.once("SIGTERM", () => {
295
+ if (!abortSignal.signal.aborted) {
296
+ abortSignal.abort();
297
+ }
298
+ });
299
+ const port = argv.port ?? await getPort();
300
+ if (!argv["no-server"]) {
301
+ await serve(port);
302
+ }
303
+ const ids = await fetch(`http://localhost:${port}/ids`, {
304
+ signal: abortSignal.signal
305
+ }).then((res) => res.json());
306
+ const results = [];
307
+ process.stdout.write("Running " + ids.length + " test suites\n");
308
+ if (!existsSync(resolvePath(argv, "./logs"))) {
309
+ mkdirSync(resolvePath(argv, "./logs"));
310
+ }
311
+ process.stdout.write("\n");
312
+ for await (const id of ids) {
313
+ await killPortIfRunning(readPort(argv.graphql)).catch(() => {
314
+ });
315
+ const logStream = createWriteStream(
316
+ resolvePath(argv, `./logs/${id}-gateway.log`),
317
+ {
318
+ flags: "w+"
319
+ }
320
+ );
321
+ const gatewayExit = Promise.withResolvers();
322
+ let gatewayExited = false;
323
+ const gateway = spawn("sh", [argv.runScript, id], {
324
+ signal: abortSignal.signal,
325
+ stdio: "pipe",
326
+ cwd: dirname(resolvePath(argv, argv.runScript))
327
+ });
328
+ gateway.once("exit", () => {
329
+ gatewayExited = true;
330
+ gatewayExit.resolve();
331
+ });
332
+ gateway.stdout.pipe(logStream);
333
+ gateway.stderr.pipe(logStream);
334
+ const result = await runTest({
335
+ test: id,
336
+ graphql: argv.graphql,
337
+ healthcheck: argv.healthcheck,
338
+ port: argv.port,
339
+ reporter: argv.reporter === "tap" ? "tap" : "dot",
340
+ junit: argv.junit,
341
+ cwd: argv.cwd
342
+ });
343
+ results.push({ id, result });
344
+ if (!gatewayExited) {
345
+ gateway.kill();
346
+ }
347
+ await gatewayExit.promise;
348
+ }
349
+ let total = 0;
350
+ let passed = 0;
351
+ let failed = 0;
352
+ for (const { result } of results) {
353
+ for (const test of result) {
354
+ if (test === ".") {
355
+ total++;
356
+ passed++;
357
+ } else if (test === "X") {
358
+ total++;
359
+ failed++;
360
+ }
361
+ }
362
+ }
363
+ process.stdout.write("\n\n\n");
364
+ process.stdout.write(styleText("bold", "Results") + "\n");
365
+ process.stdout.write("-----------\n");
366
+ process.stdout.write(`Total: ${total}
367
+ `);
368
+ process.stdout.write(
369
+ `Passed: ${styleText("greenBright", passed + "")}
370
+ `
371
+ );
372
+ if (failed > 0) {
373
+ process.stdout.write(
374
+ `Failed: ${styleText("redBright", failed + "")}
375
+ `
376
+ );
377
+ }
378
+ process.stdout.write("\n");
379
+ if (failed > 0) {
380
+ process.stdout.write(
381
+ styleText("redBright", "Your gateway is not fully compatible\n")
382
+ );
383
+ } else {
384
+ process.stdout.write(
385
+ styleText("greenBright", "Your gateway is fully compatible\n")
386
+ );
387
+ }
388
+ writeFileSync(
389
+ resolvePath(argv, argv.write),
390
+ results.flatMap((r) => [r.id, r.result.join("")]).concat([
391
+ "",
392
+ "---",
393
+ `Total: ${total}`,
394
+ `Passed: ${passed}`,
395
+ `Failed: ${failed}`
396
+ ]).join("\n")
397
+ );
398
+ if (argv["exit-on-fail"] && failed > 0) {
399
+ process.exit(1);
400
+ }
401
+ process.exit(0);
402
+ }
403
+ ).demandCommand(1).parse();
404
+ async function runTest(args) {
405
+ process.stdout.write(`${args.test}
406
+ `);
407
+ process.env.TESTS_ENDPOINT = `http://localhost:${args.port}/${args.test}/tests`;
408
+ process.env.GRAPHQL_ENDPOINT = args.graphql;
409
+ process.env.TEST_SUITE = args.test;
410
+ const logStream = createWriteStream(
411
+ resolvePath({ cwd: args.cwd }, `./logs/${args.test}-tests.log`),
412
+ {
413
+ flags: "w+"
414
+ }
415
+ );
416
+ if (args.healthcheck) {
417
+ try {
418
+ await waitOnGraphQL({
419
+ healthcheck: args.healthcheck,
420
+ graphql: args.graphql
421
+ });
422
+ } catch (err) {
423
+ logStream.write("\nHealth check failed\n");
424
+ }
425
+ }
426
+ const { resolve, promise } = Promise.withResolvers();
427
+ const dotan = createDotReporter(resolve);
428
+ const testStream = run({
429
+ concurrency: 1,
430
+ files: [join(__dirname$1, `test${ext}`)]
431
+ });
432
+ testStream.compose(args.reporter === "tap" ? tap : dot).pipe(process.stdout);
433
+ testStream.compose(tap).pipe(logStream);
434
+ testStream.compose(dotan);
435
+ if (args.junit) {
436
+ const reportsDir = resolvePath({ cwd: args.cwd }, "reports");
437
+ if (!existsSync(reportsDir)) {
438
+ mkdirSync(reportsDir, { recursive: true });
439
+ }
440
+ const junitPath = join(reportsDir, `${args.test}.xml`);
441
+ const junitStream = createWriteStream(junitPath, {
442
+ flags: "w+"
443
+ });
444
+ testStream.compose(junit).pipe(junitStream);
445
+ }
446
+ return promise;
447
+ }
448
+ function createDotReporter(resolve) {
449
+ const report = [];
450
+ return async function* dot2(source) {
451
+ for await (const { type, data } of source) {
452
+ if (data != null && "details" in data && data.details?.type === "suite") {
453
+ continue;
454
+ }
455
+ if (type === "test:pass") {
456
+ report.push(".");
457
+ }
458
+ if (type === "test:fail") {
459
+ report.push("X");
460
+ }
461
+ }
462
+ resolve(report);
463
+ };
464
+ }
465
+ async function* dot(source) {
466
+ let count = 0;
467
+ let columns = getLineLength();
468
+ for await (const { type, data } of source) {
469
+ if (data != null && "details" in data && data.details?.type === "suite") {
470
+ continue;
471
+ }
472
+ if (type === "test:pass") {
473
+ yield styleText("green", ".");
474
+ }
475
+ if (type === "test:fail") {
476
+ yield styleText("red", "X");
477
+ }
478
+ if ((type === "test:fail" || type === "test:pass") && ++count === columns) {
479
+ yield "\n";
480
+ columns = getLineLength();
481
+ count = 0;
482
+ }
483
+ }
484
+ yield "\n";
485
+ }
486
+ function getLineLength() {
487
+ return Math.max(process.stdout.columns ?? 20, 20);
488
+ }
489
+ function readVersion() {
490
+ try {
491
+ return "v" + JSON.parse(readFileSync(join(__dirname$1, "../package.json"), "utf-8")).version;
492
+ } catch {
493
+ }
494
+ try {
495
+ return "v" + JSON.parse(readFileSync(join(__dirname$1, "./package.json"), "utf-8")).version;
496
+ } catch {
497
+ }
498
+ }
499
+ async function waitOnGraphQL(endpoints) {
500
+ const timeout = process.env["GATEWAY_TIMEOUT"] ? parseInt(process.env["GATEWAY_TIMEOUT"]) : 5e3;
501
+ await waitOn({
502
+ // Make sure the health check is a GET request
503
+ resources: [endpoints.healthcheck.replace("http://", "http-get://")],
504
+ timeout,
505
+ httpTimeout: 200,
506
+ log: false,
507
+ verbose: false
508
+ });
509
+ await retry(fetchTypename, {
510
+ maxRetryTime: 2e3,
511
+ retries: 20,
512
+ maxTimeout: 500,
513
+ minTimeout: 100
514
+ });
515
+ async function fetchTypename() {
516
+ const response = await fetch(endpoints.graphql, {
517
+ method: "POST",
518
+ headers: {
519
+ "Content-Type": "application/json",
520
+ accept: "application/json"
521
+ },
522
+ body: JSON.stringify({
523
+ operationName: "ping",
524
+ query: (
525
+ /* GraphQL */
526
+ `
527
+ query ping {
528
+ __typename
529
+ }
530
+ `
531
+ )
532
+ })
533
+ });
534
+ if (response.ok) {
535
+ const json = await response.json();
536
+ if (json.data.__typename === "Query") {
537
+ return;
538
+ }
539
+ }
540
+ throw new Error("Failed to fetch __typename");
541
+ }
542
+ }
543
+ async function killPortIfRunning(port) {
544
+ if (await detectPort(port)) {
545
+ await killPortProcess(port);
546
+ }
547
+ }
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ let env_loaded = false;
4
+ function shouldPunishForPoorPlans() {
5
+ if (!env_loaded) {
6
+ try {
7
+ process.loadEnvFile();
8
+ } catch (e) {
9
+ }
10
+ env_loaded = true;
11
+ }
12
+ return process.env.PUNISH_FOR_POOR_PLANS === "1";
13
+ }
14
+
15
+ exports.shouldPunishForPoorPlans = shouldPunishForPoorPlans;
@@ -0,0 +1,13 @@
1
+ let env_loaded = false;
2
+ function shouldPunishForPoorPlans() {
3
+ if (!env_loaded) {
4
+ try {
5
+ process.loadEnvFile();
6
+ } catch (e) {
7
+ }
8
+ env_loaded = true;
9
+ }
10
+ return process.env.PUNISH_FOR_POOR_PLANS === "1";
11
+ }
12
+
13
+ export { shouldPunishForPoorPlans as s };
@@ -0,0 +1,13 @@
1
+ let env_loaded = false;
2
+ function shouldPunishForPoorPlans() {
3
+ if (!env_loaded) {
4
+ try {
5
+ process.loadEnvFile();
6
+ } catch (e) {
7
+ }
8
+ env_loaded = true;
9
+ }
10
+ return process.env.PUNISH_FOR_POOR_PLANS === "1";
11
+ }
12
+
13
+ export { shouldPunishForPoorPlans as s };