UNPKG

@graphql-hive/federation-gateway-audit

Version:
232 lines (229 loc) 5.87 kB
import { createRouter as createRouter$1, Response } from 'fets'; import { createServer } from 'node:http'; async function getTestCases(router) { const testCases = await Promise.all( [ import('./index-ojnncNWd.js'), import('./index-CQ5t4ZXm.js'), import('./index-DddNFRG3.js'), import('./index-Djqj3DWJ.js'), import('./index-CQeQ1nto.js'), import('./index-ByUUB7Zn.js'), import('./index-BStXx4OK.js'), import('./index-B38OpRtf.js'), import('./index-DOkkIHER.js'), import('./index-C9Eh7qBC.js'), import('./index-DrkXuLUZ.js'), import('./index-X4u6bs58.js'), import('./index-CLsasg69.js'), import('./index-LVWQqV-v.js'), import('./index-6itLA31k.js'), import('./index-mm-YMeoi.js'), import('./index-BcZC0OIN.js'), import('./index-B3aDw4Tt.js'), import('./index-Dm5kpK9t.js'), import('./index-BhPDIfmU.js'), import('./index-CMdC_Cah.js'), import('./index-B_eGT6oX.js'), import('./index-CddVoIp2.js'), import('./index-C05_HMLC.js'), import('./index-IQJLr7nR.js'), import('./index-DUlT8CJ2.js'), import('./index-CO0GiXGE.js'), import('./index-C4dnTlBf.js'), import('./index-DV1F4nxP.js'), import('./index-B-YHHt9g.js'), import('./index-BmOn6xYL.js'), import('./index-Bnb8TpOO.js'), import('./index-DLu9E2Vq.js'), import('./index-C_pTgB_1.js'), import('./index-CrUbbFxE.js'), import('./index-Dp8mobro.js'), import('./index-BGNmWPAk.js'), import('./index-lkBiml03.js'), import('./index-Bo74nI4n.js'), import('./index-BJB0tRA1.js'), import('./index-fqmAgjhG.js'), import('./index-1ZtG04bN.js'), import('./index-CSc_T8Lu.js'), import('./index-DISym5OL.js'), import('./index-CilR468b.js'), import('./index-CilqARtc.js') ].map((i) => i.then((e) => e.default)) ); testCases.sort((a, b) => a.id.localeCompare(b.id)); const registeredNames = /* @__PURE__ */ new Set(); for (const testCase of testCases) { if (registeredNames.has(testCase.id)) { throw new Error(`Duplicate test case id: ${testCase.id}`); } registeredNames.add(testCase.id); testCase.createRoutes(router); } return testCases; } function serve(port) { const router = createRouter(); const { resolve, reject, promise } = Promise.withResolvers(); let started = false; const server = createServer(router).listen(port, () => { started = true; resolve({ close }); }); server.once("error", (error) => { if (!started) { reject(error); } else { process.stderr.write("Server error: " + String(error)); } }); function close() { if (server.listening) { return new Promise((resolve2, reject2) => { server.closeAllConnections(); server.close((error) => { if (error) { reject2(error); } else { resolve2(); } }); }); } } server.once("close", () => { console.log("Server closed"); }); process.once("exit", () => { close(); }); process.once("SIGINT", () => { close(); }); process.once("SIGTERM", () => { close(); }); return promise; } function createRouter() { const router = createRouter$1({ landingPage: false, swaggerUI: { endpoint: "/", displayOperationId: false }, openAPI: { info: { title: "Federation Compatibility Test Suite", description: "A test suite for validating Apollo Federation v2 compatibility", contact: { name: "The Guild", url: "https://the-guild.dev", email: "contact@the-guild.dev" } } } }).route({ method: "GET", path: "/_health", handler() { return new Response("OK"); } }).route({ method: "GET", path: "/ids", operationId: "get_ids", description: "A list of test cases", tags: ["root"], schemas: { responses: { 200: { type: "array", items: { type: "string" } } } }, handler() { return testCases$.then( (testCases) => Response.json(testCases.map((t) => t.id)) ); } }).route({ method: "GET", path: "/supergraphs", description: "A list of supergraph endpoints", tags: ["root"], schemas: { responses: { 200: { type: "array", items: { type: "string" } } } }, handler(req) { return testCases$.then( (testCases) => Response.json( testCases.map( ({ id }) => `${req.parsedUrl.origin}/${id}/supergraph` ) ) ); } }).route({ method: "GET", path: "/tests", description: "A list of endpoints with tests", tags: ["root"], schemas: { responses: { 200: { type: "array", items: { type: "string" } } } }, handler(req) { return testCases$.then( (testCases) => Response.json( testCases.map(({ id }) => `${req.parsedUrl.origin}/${id}/tests`) ) ); } }).route({ method: "GET", path: "/subgraphs", description: "A list of endpoints with subgraphs", tags: ["root"], schemas: { responses: { 200: { type: "array", items: { type: "string" } } } }, handler(req) { return testCases$.then( (testCases) => Response.json( testCases.map( ({ id }) => `${req.parsedUrl.origin}/${id}/subgraphs` ) ) ); } }); const testCases$ = getTestCases(router); return router; } export { createRouter, serve };