mirror of
https://github.com/FranP-code/countries.git
synced 2025-10-13 00:02:15 +00:00
Initial commit
This commit is contained in:
37
index.js
Normal file
37
index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
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 => ({
|
||||
code,
|
||||
...countries[code]
|
||||
}));
|
||||
|
||||
const resolvers = {
|
||||
Query: {
|
||||
countries: () => countriesArray
|
||||
}
|
||||
};
|
||||
|
||||
const server = new ApolloServer({typeDefs, resolvers});
|
||||
|
||||
server.listen().then(({url}) => {
|
||||
console.log(`🚀 Server ready at ${url}`);
|
||||
});
|
||||
Reference in New Issue
Block a user