diff --git a/docs/schema.md b/docs/schema.md index f59fe7d..183ce9f 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -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)). diff --git a/docs/types.md b/docs/types.md index 9768c31..022934d 100644 --- a/docs/types.md +++ b/docs/types.md @@ -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. + + + +standard +String + + +Specify the particular ISO standard codes to retrieve. +Available ISO standards are 3166-1, 3166-2, and 3166-3. + diff --git a/package.json b/package.json index f23956c..b0b841b 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/schema.json b/schema.json index 3377450..03c0ef4 100644 --- a/schema.json +++ b/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, diff --git a/src/types/area.js b/src/types/area.js index 1ecf2d0..9761ada 100644 --- a/src/types/area.js +++ b/src/types/area.js @@ -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 diff --git a/test/_schema.js b/test/_schema.js index 4defba0..e1dee2b 100644 --- a/test/_schema.js +++ b/test/_schema.js @@ -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, diff --git a/test/fixtures/a3643b415a8765c397d0b4e725ac6952 b/test/fixtures/a3643b415a8765c397d0b4e725ac6952 new file mode 100644 index 0000000..e536d83 Binary files /dev/null and b/test/fixtures/a3643b415a8765c397d0b4e725ac6952 differ diff --git a/test/fixtures/a3643b415a8765c397d0b4e725ac6952.headers b/test/fixtures/a3643b415a8765c397d0b4e725ac6952.headers new file mode 100644 index 0000000..41f9bae --- /dev/null +++ b/test/fixtures/a3643b415a8765c397d0b4e725ac6952.headers @@ -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" + } + } +} \ No newline at end of file