import { readFileSync } from "fs"; import { ApolloServer } from "@apollo/server"; import { startStandaloneServer } from "@apollo/server/standalone"; import { MergedResolvers } from "./MergedResolvers"; import { ServerContext } from "./ServerContext"; import { loadShuttleTestData, supportedIntegrationTestSystems } from "./loaders/shuttle/loadShuttleTestData"; import { InterchangeSystem, InterchangeSystemBuilderArguments } from "./entities/InterchangeSystem"; const typeDefs = readFileSync("./schema.graphqls", "utf8"); // In the future this can be stored as a separate file const supportedSystems: InterchangeSystemBuilderArguments[] = [ { id: "1", passioSystemId: "263", name: "Chapman University", } ] async function main() { const server = new ApolloServer({ typeDefs, resolvers: MergedResolvers, introspection: process.env.NODE_ENV !== "production", }); let systems: InterchangeSystem[]; if (process.argv.length > 2 && process.argv[2] == "integration-testing") { console.log("Using integration testing setup") systems = await Promise.all(supportedIntegrationTestSystems.map( async (systemArguments) => { const system = InterchangeSystem.buildForTesting(systemArguments); // TODO: Have loading of different data for different systems in the future await loadShuttleTestData(system.shuttleRepository); return system; } )); } else { systems = await Promise.all(supportedSystems.map( async (systemArguments) => { return await InterchangeSystem.build(systemArguments); }, )); } const { url } = await startStandaloneServer(server, { listen: { port: process.env.PORT ? parseInt(process.env.PORT) : 4000, }, context: async () => { return { systems, findSystemById: (id: string) => { const system = systems.find((system) => system.id === id); if (!system) { return null; } return system; }, } }, }); console.log(`Server ready at: ${url}`); } main();