move other resolvers into their own files

This commit is contained in:
2025-01-23 03:39:50 -08:00
parent 718677d6dd
commit 5813408a36
7 changed files with 241 additions and 198 deletions

View File

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