mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
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 } from "./loaders/shuttle/loadShuttleTestData";
|
|
import { InterchangeSystem, InterchangeSystemBuilderArguments } from "./entities/InterchangeSystem";
|
|
import { ChapmanApiBasedParkingRepositoryLoader } from "./loaders/parking/ChapmanApiBasedParkingRepositoryLoader";
|
|
import { supportedIntegrationTestSystems } from "./loaders/supportedIntegrationTestSystems";
|
|
import { loadParkingTestData } from "./loaders/parking/loadParkingTestData";
|
|
|
|
const typeDefs = readFileSync("./schema.graphqls", "utf8");
|
|
|
|
// In the future this can be stored as a separate file
|
|
const supportedSystems: InterchangeSystemBuilderArguments[] = [
|
|
{
|
|
id: "1",
|
|
passioSystemId: "263",
|
|
parkingSystemId: ChapmanApiBasedParkingRepositoryLoader.id,
|
|
name: "Chapman University",
|
|
}
|
|
]
|
|
|
|
async function main() {
|
|
const server = new ApolloServer<ServerContext>({
|
|
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);
|
|
if (system.parkingRepository) {
|
|
await loadParkingTestData(system.parkingRepository);
|
|
}
|
|
|
|
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();
|