Files
countries/index.js
2018-10-11 13:30:52 -04:00

38 lines
696 B
JavaScript

import {ApolloServer, gql} from 'apollo-server';
import {countries} from 'countries-list';
const typeDefs = gql`
type Country {
code: String
name: String
native: String
phone: String
continent: String
currency: String
languages: [String]
emoji: String
emojiU: String
}
type Query {
countries: [Country]
}
`;
const countriesArray = Object.keys(countries).map(code => ({
...countries[code],
code
}));
const resolvers = {
Query: {
countries: () => countriesArray
}
};
const server = new ApolloServer({typeDefs, resolvers});
server.listen({port: process.env.PORT}).then(({url}) => {
console.log(`🚀 Server ready at ${url}`);
});