mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
Add support for retrieving ISO 3166-2 and ISO 3166-3 codes. (#53)
This commit is contained in:
parent
55176e6753
commit
f425082758
8 changed files with 105 additions and 4 deletions
|
|
@ -56,7 +56,11 @@ type Area implements Node, Entity {
|
|||
|
||||
# [ISO 3166 codes](https://en.wikipedia.org/wiki/ISO_3166) are
|
||||
# the codes assigned by ISO to countries and subdivisions.
|
||||
isoCodes: [String]
|
||||
isoCodes(
|
||||
# Specify the particular ISO standard codes to retrieve.
|
||||
# Available ISO standards are 3166-1, 3166-2, and 3166-3.
|
||||
standard: String = "3166-1"
|
||||
): [String]
|
||||
|
||||
# The type of area (country, city, etc. – see the [possible
|
||||
# values](https://musicbrainz.org/doc/Area)).
|
||||
|
|
|
|||
|
|
@ -317,6 +317,16 @@ alternate names or misspellings.
|
|||
[ISO 3166 codes](https://en.wikipedia.org/wiki/ISO_3166) are
|
||||
the codes assigned by ISO to countries and subdivisions.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="right" valign="top">standard</td>
|
||||
<td valign="top"><a href="#string">String</a></td>
|
||||
<td>
|
||||
|
||||
Specify the particular ISO standard codes to retrieve.
|
||||
Available ISO standards are 3166-1, 3166-2, and 3166-3.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
"test:coverage": "cross-env NODE_ENV=test nyc npm run test:only",
|
||||
"test:only": "cross-env VCR_MODE=playback ava",
|
||||
"test:record": "cross-env VCR_MODE=record ava",
|
||||
"test:record-new": "cross-env VCR_MODE=cache ava --serial",
|
||||
"test:record-new": "cross-env VCR_MODE=cache ava --concurrency 1",
|
||||
"test:watch": "npm run test:only -- --watch",
|
||||
"update-schema": "npm run -s print-schema:json > schema.json"
|
||||
},
|
||||
|
|
|
|||
13
schema.json
13
schema.json
|
|
@ -578,7 +578,18 @@
|
|||
{
|
||||
"name": "isoCodes",
|
||||
"description": "[ISO 3166 codes](https://en.wikipedia.org/wiki/ISO_3166) are\nthe codes assigned by ISO to countries and subdivisions.",
|
||||
"args": [],
|
||||
"args": [
|
||||
{
|
||||
"name": "standard",
|
||||
"description": "Specify the particular ISO standard codes to retrieve.\nAvailable ISO standards are 3166-1, 3166-2, and 3166-3.",
|
||||
"type": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
},
|
||||
"defaultValue": "\"3166-1\""
|
||||
}
|
||||
],
|
||||
"type": {
|
||||
"kind": "LIST",
|
||||
"name": null,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,18 @@ or settlements (countries, cities, or the like).`,
|
|||
type: new GraphQLList(GraphQLString),
|
||||
description: `[ISO 3166 codes](https://en.wikipedia.org/wiki/ISO_3166) are
|
||||
the codes assigned by ISO to countries and subdivisions.`,
|
||||
resolve: data => data['iso-3166-1-codes']
|
||||
args: {
|
||||
standard: {
|
||||
type: GraphQLString,
|
||||
description: `Specify the particular ISO standard codes to retrieve.
|
||||
Available ISO standards are 3166-1, 3166-2, and 3166-3.`,
|
||||
defaultValue: '3166-1'
|
||||
}
|
||||
},
|
||||
resolve: (data, args) => {
|
||||
const { standard = '3166-1' } = args
|
||||
return data[`iso-${standard}-codes`]
|
||||
}
|
||||
},
|
||||
...fieldWithID('type', {
|
||||
description: `The type of area (country, city, etc. – see the [possible
|
||||
|
|
|
|||
|
|
@ -580,6 +580,42 @@ test(
|
|||
}
|
||||
)
|
||||
|
||||
test(
|
||||
'area isoCodes accepts an argument to retrieve 3166-1, 3166-2, or 3166-3 codes',
|
||||
testData,
|
||||
`
|
||||
{
|
||||
lookup {
|
||||
eastGermany: area(mbid: "d907b0ac-2956-386f-a246-62d55779aae1") {
|
||||
name
|
||||
isoDefault: isoCodes
|
||||
iso3166_1: isoCodes(standard: "3166-1")
|
||||
iso3166_2: isoCodes(standard: "3166-2")
|
||||
iso3166_3: isoCodes(standard: "3166-3")
|
||||
}
|
||||
newYork: area(mbid: "75e398a3-5f3f-4224-9cd8-0fe44715bc95") {
|
||||
name
|
||||
isoDefault: isoCodes
|
||||
iso3166_1: isoCodes(standard: "3166-1")
|
||||
iso3166_2: isoCodes(standard: "3166-2")
|
||||
iso3166_3: isoCodes(standard: "3166-3")
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
(t, data) => {
|
||||
t.deepEqual(data.lookup.eastGermany.isoDefault, ['XG'])
|
||||
t.deepEqual(data.lookup.eastGermany.iso3166_1, ['XG'])
|
||||
t.is(data.lookup.eastGermany.iso3166_2, null)
|
||||
t.deepEqual(data.lookup.eastGermany.iso3166_3, ['DDDE'])
|
||||
|
||||
t.is(data.lookup.newYork.isoDefault, null)
|
||||
t.is(data.lookup.newYork.iso3166_1, null)
|
||||
t.deepEqual(data.lookup.newYork.iso3166_2, ['US-NY'])
|
||||
t.is(data.lookup.newYork.iso3166_3, null)
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
'areas have a type and typeID',
|
||||
testData,
|
||||
|
|
|
|||
BIN
test/fixtures/a3643b415a8765c397d0b4e725ac6952
vendored
Normal file
BIN
test/fixtures/a3643b415a8765c397d0b4e725ac6952
vendored
Normal file
Binary file not shown.
29
test/fixtures/a3643b415a8765c397d0b4e725ac6952.headers
vendored
Normal file
29
test/fixtures/a3643b415a8765c397d0b4e725ac6952.headers
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"statusCode": 200,
|
||||
"headers": {
|
||||
"date": "Thu, 23 Nov 2017 20:24:51 GMT",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"transfer-encoding": "chunked",
|
||||
"connection": "keep-alive",
|
||||
"keep-alive": "timeout=15",
|
||||
"vary": "Accept-Encoding",
|
||||
"x-ratelimit-limit": "1200",
|
||||
"x-ratelimit-remaining": "886",
|
||||
"x-ratelimit-reset": "1511468692",
|
||||
"server": "Plack::Handler::Starlet",
|
||||
"etag": "W/\"2bdd0bab5c20e84a04fec14ac72f29c2\"",
|
||||
"access-control-allow-origin": "*",
|
||||
"content-encoding": "gzip"
|
||||
},
|
||||
"url": "http://musicbrainz.org:80/ws/2/area/75e398a3-5f3f-4224-9cd8-0fe44715bc95?fmt=json",
|
||||
"time": 373,
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"User-Agent": "graphbrainz/7.3.0 ( https://github.com/exogen/graphbrainz )",
|
||||
"host": "musicbrainz.org",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"accept": "application/json"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue