Files
project-inter-server/src/resolvers.ts

69 lines
1.9 KiB
TypeScript

import { Eta, OrderedStop, Resolvers, Route, Shuttle, Stop, System } from "./generated/graphql";
import { ServerContext } from "./serverContext";
export const resolvers: Resolvers<ServerContext> = {
Query: {
systems: (parent, args, contextValue, info) => {
return contextValue.sharedMemory.systems;
},
system: (parent, args, contextValue, info) => {
const systems = contextValue.sharedMemory.systems;
const system = systems.find((system) => system.id === args.id);
if (!system) {
return null;
}
return system;
}
},
System: {
stop: (parent, args, contextValue, info) => {
// TODO implement interface with ID and one function to perform search
const stops = parent.stops;
const stop = stops.find((stop) => stop.id === args.id);
if (!stop) {
return null;
}
return stop;
},
route: (parent, args, contextValue, info) => {
const routes = parent.routes
const route = routes.find((route) => route.id === args.id);
if (!route) {
return null;
}
return route;
},
shuttle: (parent, args, contextValue, info) => {
const shuttles = parent.shuttles;
const shuttle = shuttles.find((shuttle) => shuttle.id === args.id);
if (!shuttle) {
return null;
}
return shuttle;
}
},
Route: {
nextOrderedStop: (parent, args, contextValue, info) => {
const orderedStop = parent.orderedStops.find((orderedStop) => orderedStop.stop.id === args.forStopId);
if (!orderedStop || !orderedStop.nextStop) {
return null;
}
return orderedStop.nextStop;
},
},
Shuttle: {
eta: (parent, args, contextValue, info) => {
const etaForNextStop = parent.etas.find((eta) => eta.stop.id === args.forStopId);
if (!etaForNextStop) {
return null;
}
return etaForNextStop;
},
},
};