import { Coordinates, Resolvers } from "../generated/graphql"; import { ServerContext } from "../ServerContext"; export const SystemResolvers: Resolvers = { System: { routes: async (parent, args, contextValue, info) => { return await contextValue.repository.getRoutesBySystemId(parent.id); }, stops: async (parent, args, contextValue, info) => { const stops = await contextValue.repository.getStopsBySystemId(parent.id); return stops.map(({ id, name, coordinates }) => ({ id, name, // Both ICoordinates and Coordinates have the same definition coordinates: coordinates as Coordinates, })); }, stop: async (parent, args, contextValue, info) => { if (!args.id) return null; const stop = await contextValue.repository.getStopById(args.id); if (stop === null) return null; return { id: stop.id, name: stop.name, coordinates: stop.coordinates as Coordinates, }; }, route: async (parent, args, contextValue, info) => { if (!args.id) return null; const route = await contextValue.repository.getRouteById(args.id); if (route === null) return null; return { color: route.color, id: route.id, name: route.name, polylineCoordinates: route.polylineCoordinates as Coordinates[], }; }, shuttle: async (parent, args, contextValue, info) => { if (!args.id) return null; const shuttle = await contextValue.repository.getShuttleById(args.id); if (shuttle === null) return null; return shuttle; }, shuttles: async (parent, args, contextValue, info) => { const shuttles = await contextValue.repository.getShuttlesBySystemId(parent.id); return shuttles.map(shuttle => ({ coordinates: shuttle.coordinates, name: shuttle.name, id: shuttle.id, routeId: shuttle.routeId, })); } }, }