UNPKG

@accounter/server

Version:
33 lines 1.22 kB
import { GraphQLError } from 'graphql'; import { CountriesProvider } from '../providers/countries.provider.js'; export const countriesResolvers = { Query: { allCountries: async (_, __, { injector }) => { try { return (await injector.get(CountriesProvider).getAllCountries()).map(country => country.code); } catch (e) { console.error('Error fetching countries', e); throw new GraphQLError('Error fetching countries'); } }, }, Country: { id: countryCode => countryCode, name: async (countryCode, __, { injector }) => injector .get(CountriesProvider) .getCountryByCodeLoader.load(countryCode) .catch(error => { console.error('Error fetching countries', error); throw new GraphQLError('Error fetching countries'); }) .then(country => { if (!country) { throw new GraphQLError(`Country not found for code: ${countryCode}`); } return country.name; }), code: countryCode => countryCode, }, }; //# sourceMappingURL=countries.resolver.js.map