diff --git a/schema.graphqls b/schema.graphqls index fed40f6..d2105a3 100644 --- a/schema.graphqls +++ b/schema.graphqls @@ -17,7 +17,7 @@ type System { type Route { name: String! id: ID! - orderedStops: [OrderedStop!] + orderedStop(forStopId: ID): OrderedStop shuttles: [Shuttle!] polylineCoordinates: [Coordinates!]! color: String! diff --git a/src/resolvers.ts b/src/resolvers.ts index 54d05c6..950bb6e 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -110,7 +110,24 @@ export const resolvers: Resolvers = { route: parent, 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 { + stop: { + id: stop.id, + name: stop.name, + coordinates: stop.coordinates as Coordinates, + }, + route: parent, + } + }, }, Shuttle: { eta: async (parent, args, contextValue, info) => {