@graphql-hive/federation-gateway-audit
Version:
Audit tool for Apollo Federation Gateway
235 lines (231 loc) • 8.21 kB
JavaScript
;
var fets = require('fets');
var node_http = require('node:http');
async function getTestCases(router) {
const testCases = await Promise.all(
[
Promise.resolve().then(function () { return require('./index-xOtG5E4u.cjs'); }),
Promise.resolve().then(function () { return require('./index-DEvExC5x.cjs'); }),
Promise.resolve().then(function () { return require('./index-DMgHLbwU.cjs'); }),
Promise.resolve().then(function () { return require('./index-DejhKwvw.cjs'); }),
Promise.resolve().then(function () { return require('./index-DpBWZa1x.cjs'); }),
Promise.resolve().then(function () { return require('./index-BDMi6sOm.cjs'); }),
Promise.resolve().then(function () { return require('./index-UhQiJabs.cjs'); }),
Promise.resolve().then(function () { return require('./index-1nZTfbJn.cjs'); }),
Promise.resolve().then(function () { return require('./index-DRY8sDun.cjs'); }),
Promise.resolve().then(function () { return require('./index-Dsq1FK90.cjs'); }),
Promise.resolve().then(function () { return require('./index-Cbhvi8yk.cjs'); }),
Promise.resolve().then(function () { return require('./index-DFypMD6R.cjs'); }),
Promise.resolve().then(function () { return require('./index-jft-1bQ6.cjs'); }),
Promise.resolve().then(function () { return require('./index-ikGyewP-.cjs'); }),
Promise.resolve().then(function () { return require('./index-BF0H5kP0.cjs'); }),
Promise.resolve().then(function () { return require('./index-DEzxU_gQ.cjs'); }),
Promise.resolve().then(function () { return require('./index-8FxjbyOU.cjs'); }),
Promise.resolve().then(function () { return require('./index-BReFIfq_.cjs'); }),
Promise.resolve().then(function () { return require('./index-C15P-_1j.cjs'); }),
Promise.resolve().then(function () { return require('./index-ByUr80PD.cjs'); }),
Promise.resolve().then(function () { return require('./index-ESWdD7ek.cjs'); }),
Promise.resolve().then(function () { return require('./index-CNOcqGKC.cjs'); }),
Promise.resolve().then(function () { return require('./index-CKEgb_R7.cjs'); }),
Promise.resolve().then(function () { return require('./index-BYEdADrG.cjs'); }),
Promise.resolve().then(function () { return require('./index-o7g3iua7.cjs'); }),
Promise.resolve().then(function () { return require('./index-DveYQLCZ.cjs'); }),
Promise.resolve().then(function () { return require('./index-Bu7pZnPO.cjs'); }),
Promise.resolve().then(function () { return require('./index-BzPCjhuQ.cjs'); }),
Promise.resolve().then(function () { return require('./index-NB1VDvjW.cjs'); }),
Promise.resolve().then(function () { return require('./index-Cu8Ii5r7.cjs'); }),
Promise.resolve().then(function () { return require('./index-BoGmP6Cy.cjs'); }),
Promise.resolve().then(function () { return require('./index-DtmhGgM8.cjs'); }),
Promise.resolve().then(function () { return require('./index-D5jOBT3f.cjs'); }),
Promise.resolve().then(function () { return require('./index-CyVnRqjE.cjs'); }),
Promise.resolve().then(function () { return require('./index-D1Ymvd2b.cjs'); }),
Promise.resolve().then(function () { return require('./index-D07xiOJ6.cjs'); }),
Promise.resolve().then(function () { return require('./index-DfBdD-5Z.cjs'); }),
Promise.resolve().then(function () { return require('./index-CX7-wc6X.cjs'); }),
Promise.resolve().then(function () { return require('./index-BblYlZ3A.cjs'); }),
Promise.resolve().then(function () { return require('./index-BQQgQaGz.cjs'); }),
Promise.resolve().then(function () { return require('./index-DyTSkAm4.cjs'); }),
Promise.resolve().then(function () { return require('./index-B958BFYC.cjs'); }),
Promise.resolve().then(function () { return require('./index-D00bnaJy.cjs'); }),
Promise.resolve().then(function () { return require('./index-D_HiVe2_.cjs'); }),
Promise.resolve().then(function () { return require('./index-06y0enFf.cjs'); }),
Promise.resolve().then(function () { return require('./index-DdyNs8M6.cjs'); })
].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 = node_http.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 = fets.createRouter({
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 fets.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) => fets.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) => fets.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) => fets.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) => fets.Response.json(
testCases.map(
({ id }) => `${req.parsedUrl.origin}/${id}/subgraphs`
)
)
);
}
});
const testCases$ = getTestCases(router);
return router;
}
exports.createRouter = createRouter;
exports.serve = serve;