import { Coordinates, Resolvers } from "../generated/graphql"; import { ServerContext } from "../ServerContext"; export const RouteResolvers: Resolvers = { Route: { shuttles: async (parent, args, contextValue, info) => { const shuttles = await contextValue.shuttleRepository.getShuttlesByRouteId(parent.id); return shuttles.map(({ coordinates, name, id, orientationInDegrees }) => ({ coordinates: coordinates as Coordinates, name, route: parent, routeId: parent.id, id, orientationInDegrees })); }, orderedStop: async (parent, args, contextValue, info) => { if (!args.forStopId) return null; const orderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(parent.id, args.forStopId); if (!orderedStop) return null; const stop = await contextValue.shuttleRepository.getStopById(orderedStop.stopId); if (!stop) return null; return { stopId: args.forStopId, routeId: parent.id, route: parent, } }, }, }