mirror of
https://github.com/FranP-code/countries.git
synced 2025-10-13 00:02:15 +00:00
Use enums for country/continent/language codes
This commit is contained in:
24
index.js
24
index.js
@@ -3,14 +3,26 @@ const {ApolloServer, gql} = require('apollo-server');
|
|||||||
const {continents, countries, languages} = require('countries-list');
|
const {continents, countries, languages} = require('countries-list');
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
|
enum ContinentCode {
|
||||||
|
${Object.keys(continents)}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CountryCode {
|
||||||
|
${Object.keys(countries)}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LanguageCode {
|
||||||
|
${Object.keys(languages)}
|
||||||
|
}
|
||||||
|
|
||||||
type Continent {
|
type Continent {
|
||||||
code: String
|
code: ContinentCode
|
||||||
name: String
|
name: String
|
||||||
countries: [Country]
|
countries: [Country]
|
||||||
}
|
}
|
||||||
|
|
||||||
type Country {
|
type Country {
|
||||||
code: String
|
code: CountryCode
|
||||||
name: String
|
name: String
|
||||||
native: String
|
native: String
|
||||||
phone: String
|
phone: String
|
||||||
@@ -29,7 +41,7 @@ const typeDefs = gql`
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Language {
|
type Language {
|
||||||
code: String
|
code: LanguageCode
|
||||||
name: String
|
name: String
|
||||||
native: String
|
native: String
|
||||||
rtl: Int
|
rtl: Int
|
||||||
@@ -37,11 +49,11 @@ const typeDefs = gql`
|
|||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
continents: [Continent]
|
continents: [Continent]
|
||||||
continent(code: String!): Continent
|
continent(code: ContinentCode!): Continent
|
||||||
countries: [Country]
|
countries: [Country]
|
||||||
country(code: String!): Country
|
country(code: CountryCode!): Country
|
||||||
languages: [Language]
|
languages: [Language]
|
||||||
language(code: String!): Language
|
language(code: LanguageCode!): Language
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user