Add states field to country

This commit is contained in:
Trevor Blades
2020-02-02 15:27:41 -08:00
parent 44211746b9
commit 4320bd639b
4 changed files with 30 additions and 5 deletions

5
package-lock.json generated
View File

@@ -6707,6 +6707,11 @@
"long": "^4.0.0" "long": "^4.0.0"
} }
}, },
"provinces": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/provinces/-/provinces-1.11.0.tgz",
"integrity": "sha1-Rni9Y+iBHwoZTrwcV+7hxV585sI="
},
"proxy-addr": { "proxy-addr": {
"version": "2.0.5", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",

View File

@@ -14,7 +14,8 @@
"apollo-server": "^2.7.0", "apollo-server": "^2.7.0",
"countries-list": "^2.4.3", "countries-list": "^2.4.3",
"esm": "^3.2.25", "esm": "^3.2.25",
"graphql": "^14.4.2" "graphql": "^14.4.2",
"provinces": "^1.11.0"
}, },
"devDependencies": { "devDependencies": {
"@trevorblades/eslint-config": "^7.0.1", "@trevorblades/eslint-config": "^7.0.1",

View File

@@ -1,3 +1,4 @@
import provinces from 'provinces';
import {continents, countries, languages} from 'countries-list'; import {continents, countries, languages} from 'countries-list';
export default { export default {
@@ -8,20 +9,31 @@ export default {
name: continents[continent] name: continents[continent]
}; };
}, },
languages(parent) { languages(country) {
return parent.languages.map(code => { return country.languages.map(code => {
const language = languages[code]; const language = languages[code];
return { return {
...language, ...language,
code code
}; };
}); });
},
states(country) {
return provinces.filter(province => province.country === country.code);
}
},
State: {
code(state) {
return state.short;
},
country(state) {
return countries[state.country];
} }
}, },
Continent: { Continent: {
countries(parent) { countries(continent) {
return Object.entries(countries) return Object.entries(countries)
.filter(entry => entry[1].continent === parent.code) .filter(entry => entry[1].continent === continent.code)
.map(([code, country]) => ({ .map(([code, country]) => ({
...country, ...country,
code code

View File

@@ -17,6 +17,13 @@ export default gql`
languages: [Language] languages: [Language]
emoji: String emoji: String
emojiU: String emojiU: String
states: [State]
}
type State {
code: String
name: String
country: Country
} }
type Language { type Language {