Files
project-inter-server/src/resolvers/QueryResolvers.ts
Brendan Chen 415b461308 Add sorting to all data types
- Add name-based sorting for entities with names
- Add order-based sorting for ordered stops
- Add "seconds remaining" based sorting for ETAs
- Add tests to check sorting
2025-09-30 15:24:22 -07:00

63 lines
1.9 KiB
TypeScript

import { ServerContext } from "../ServerContext";
import { Resolvers } from "../generated/graphql";
const GRAPHQL_SCHEMA_MIN_VERSION = 1;
const GRAPHQL_SCHEMA_CURRENT_VERSION = 1;
export const QueryResolvers: Resolvers<ServerContext> = {
Query: {
systems: async (_parent, args, contextValue, _info) => {
return contextValue.systems
.slice()
.sort((a, b) => a.name.localeCompare(b.name))
.map((system) => {
return {
name: system.name,
id: system.id,
};
})
},
system: async (_parent, args, contextValue, _info) => {
if (!args.id) return null;
const system = contextValue.findSystemById(args.id);
if (system === null) return null;
return {
name: system.name,
id: system.id,
};
},
// TODO: Update the GraphQL schema to require a system ID
isNotificationScheduled: async (_parent, args, contextValue, _info) => {
const notificationData = args.input;
for (let system of contextValue.systems) {
const isScheduled = await system.notificationRepository.isNotificationScheduled(notificationData);
if (isScheduled) {
return true;
}
}
return false;
},
secondsThresholdForNotification: async (_parent, args, contextValue, _info) => {
const notificationData = args.input;
for (let system of contextValue.systems) {
const isScheduled = await system.notificationRepository.isNotificationScheduled(notificationData);
if (isScheduled) {
return await system.notificationRepository.getSecondsThresholdForNotificationIfExists(args.input);
}
}
return null;
},
schemaMinVersion: async (_parent, _args, _contextValue, _info) => {
return GRAPHQL_SCHEMA_MIN_VERSION;
},
schemaCurrentVersion: async (_parent, _args, _contextValue, _info) => {
return GRAPHQL_SCHEMA_CURRENT_VERSION;
},
},
}