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 = { 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; }, }, }