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,52 @@
import { Eta, Resolvers } from "../generated/graphql";
import { ServerContext } from "../ServerContext";
export const ShuttleResolvers: Resolvers<ServerContext> = {
Shuttle: {
eta: async (parent, args, contextValue, info) => {
if (!args.forStopId) return null;
const etaForStopId = await contextValue.repository.getEtaForShuttleAndStopId(parent.id, args.forStopId);
if (etaForStopId === null) return null;
return {
stopId: args.forStopId,
secondsRemaining: etaForStopId.secondsRemaining,
shuttleId: parent.id,
shuttle: parent,
};
},
etas: async (parent, args, contextValue, info) => {
const etasForShuttle = await contextValue.repository.getEtasForShuttleId(parent.id);
if (!etasForShuttle) return null;
const computedEtas = await Promise.all(etasForShuttle.map(async ({
secondsRemaining,
stopId,
}): Promise<Eta | null> => {
return {
secondsRemaining,
stopId,
shuttle: parent,
shuttleId: parent.id,
}
}));
if (computedEtas.every((eta) => eta !== null)) {
return computedEtas;
}
return [];
},
route: async (parent, args, contextValue, info) => {
const route = await contextValue.repository.getRouteById(parent.routeId);
if (route === null) return null;
return {
color: route.color,
id: route.id,
name: route.name,
polylineCoordinates: route.polylineCoordinates,
}
}
},
}