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,63 @@
import { Coordinates, Resolvers } from "../generated/graphql";
import { ServerContext } from "../ServerContext";
export const SystemResolvers: Resolvers<ServerContext> = {
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,
}));
}
},
}