diff --git a/docs/schema.md b/docs/schema.md
index 895e9a8..f59fe7d 100644
--- a/docs/schema.md
+++ b/docs/schema.md
@@ -58,6 +58,14 @@ type Area implements Node, Entity {
# the codes assigned by ISO to countries and subdivisions.
isoCodes: [String]
+ # The type of area (country, city, etc. – see the [possible
+ # values](https://musicbrainz.org/doc/Area)).
+ type: String
+
+ # The MBID associated with the value of the `type`
+ # field.
+ typeID: MBID
+
# A list of artists linked to this entity.
artists(after: String, first: Int): ArtistConnection
diff --git a/docs/types.md b/docs/types.md
index 1f2c835..9768c31 100644
--- a/docs/types.md
+++ b/docs/types.md
@@ -317,6 +317,26 @@ alternate names or misspellings.
[ISO 3166 codes](https://en.wikipedia.org/wiki/ISO_3166) are
the codes assigned by ISO to countries and subdivisions.
+
+
+
+| type |
+String |
+
+
+The type of area (country, city, etc. – see the [possible
+values](https://musicbrainz.org/doc/Area)).
+
+ |
+
+
+| typeID |
+MBID |
+
+
+The MBID associated with the value of the `type`
+field.
+
|
diff --git a/package.json b/package.json
index 459e0fd..c6efb3d 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,6 @@
"dashify": "^0.2.2",
"dataloader": "^1.3.0",
"debug": "^3.0.0",
- "deep-diff": "^0.3.8",
"dotenv": "^4.0.0",
"es6-error": "^4.0.2",
"express": "^4.16.2",
diff --git a/schema.json b/schema.json
index 348c6fb..3377450 100644
--- a/schema.json
+++ b/schema.json
@@ -591,6 +591,30 @@
"isDeprecated": false,
"deprecationReason": null
},
+ {
+ "name": "type",
+ "description": "The type of area (country, city, etc. – see the [possible\nvalues](https://musicbrainz.org/doc/Area)).",
+ "args": [],
+ "type": {
+ "kind": "SCALAR",
+ "name": "String",
+ "ofType": null
+ },
+ "isDeprecated": false,
+ "deprecationReason": null
+ },
+ {
+ "name": "typeID",
+ "description": "The MBID associated with the value of the `type`\nfield.",
+ "args": [],
+ "type": {
+ "kind": "SCALAR",
+ "name": "MBID",
+ "ofType": null
+ },
+ "isDeprecated": false,
+ "deprecationReason": null
+ },
{
"name": "artists",
"description": "A list of artists linked to this entity.",
diff --git a/src/api/client.js b/src/api/client.js
index 01d7a9d..87c4ea3 100644
--- a/src/api/client.js
+++ b/src/api/client.js
@@ -97,15 +97,17 @@ export default class Client {
}
}
- debug(`Sending request. url=${this.baseURL}${path} attempt=${info.currentAttempt}`)
+ const url = `${options.baseUrl}${options.url}`
+
+ debug(`Sending request. url=${url} attempt=${info.currentAttempt}`)
request(options, (err, response, body) => {
if (err) {
- debug(`Error: “${err}” url=${this.baseURL}${path}`)
+ debug(`Error: “${err}” url=${url}`)
reject(err)
} else if (response.statusCode >= 400) {
const message = this.parseErrorMessage(response, body)
- debug(`Error: “${message}” url=${this.baseURL}${path}`)
+ debug(`Error: “${message}” url=${url}`)
const ClientError = this.errorClass
reject(new ClientError(message, response.statusCode))
} else if (options.method === 'HEAD') {
diff --git a/src/extensions/cover-art-archive/index.js b/src/extensions/cover-art-archive/index.js
index 228ac4f..4523c36 100644
--- a/src/extensions/cover-art-archive/index.js
+++ b/src/extensions/cover-art-archive/index.js
@@ -6,8 +6,8 @@ import { ONE_DAY } from '../../util'
export default {
name: 'Cover Art Archive',
- description:
- 'Retrieve cover art images for releases from the [Cover Art Archive](https://coverartarchive.org/).',
+ description: `Retrieve cover art images for releases from the [Cover Art
+Archive](https://coverartarchive.org/).`,
extendContext (context, { coverArtClient, coverArtArchive = {} } = {}) {
const client = coverArtClient || new CoverArtArchiveClient(coverArtArchive)
const cacheSize = parseInt(
diff --git a/src/extensions/fanart-tv/index.js b/src/extensions/fanart-tv/index.js
index bfcbf8f..bfeecb4 100644
--- a/src/extensions/fanart-tv/index.js
+++ b/src/extensions/fanart-tv/index.js
@@ -6,9 +6,8 @@ import { ONE_DAY } from '../../util'
export default {
name: 'fanart.tv',
- description:
- 'Retrieve high quality artwork for artists, releases, and labels from ' +
- '[fanart.tv](https://fanart.tv/).',
+ description: `Retrieve high quality artwork for artists, releases, and labels
+from [fanart.tv](https://fanart.tv/).`,
extendContext (context, { fanArt = {} } = {}) {
const client = new FanArtClient(fanArt)
const cacheSize = parseInt(
diff --git a/src/extensions/fanart-tv/loader.js b/src/extensions/fanart-tv/loader.js
index 4da6855..ce04486 100644
--- a/src/extensions/fanart-tv/loader.js
+++ b/src/extensions/fanart-tv/loader.js
@@ -47,5 +47,6 @@ export default function createLoader (options) {
cacheKeyFn: ([ entityType, id ]) => `${entityType}/${id}`,
cacheMap: cache
})
+
return loader
}
diff --git a/src/extensions/mediawiki/index.js b/src/extensions/mediawiki/index.js
index d7f72f9..bc58d40 100644
--- a/src/extensions/mediawiki/index.js
+++ b/src/extensions/mediawiki/index.js
@@ -6,9 +6,8 @@ import { ONE_DAY } from '../../util'
export default {
name: 'MediaWiki',
- description:
- 'Retrieve information from MediaWiki image pages, like the actual image ' +
- 'file URL and EXIF metadata.',
+ description: `Retrieve information from MediaWiki image pages, like the actual
+image file URL and EXIF metadata.`,
extendContext (context, { mediaWiki = {} } = {}) {
const client = new MediaWikiClient(mediaWiki)
const cacheSize = parseInt(
diff --git a/src/extensions/the-audio-db/index.js b/src/extensions/the-audio-db/index.js
index ba1c26a..a6fb611 100644
--- a/src/extensions/the-audio-db/index.js
+++ b/src/extensions/the-audio-db/index.js
@@ -6,9 +6,8 @@ import { ONE_DAY } from '../../util'
export default {
name: 'TheAudioDB',
- description:
- 'Retrieve images and information about artists, releases, and recordings ' +
- 'from [TheAudioDB.com](http://www.theaudiodb.com/).',
+ description: `Retrieve images and information about artists, releases, and
+recordings from [TheAudioDB.com](http://www.theaudiodb.com/).`,
extendContext (context, { theAudioDB = {} } = {}) {
const client = new TheAudioDBClient(theAudioDB)
const cacheSize = parseInt(
diff --git a/src/index.js b/src/index.js
index cac7831..bf0ce6b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -52,7 +52,7 @@ const middleware = ({
export default middleware
-export function start () {
+export function start (options) {
require('dotenv').config({ silent: true })
const app = express()
const port = process.env.PORT || 3000
@@ -72,7 +72,7 @@ export function start () {
break
}
app.use(compression())
- app.use(route, cors(corsOptions), middleware())
+ app.use(route, cors(corsOptions), middleware(options))
app.listen(port)
console.log(`Listening on port ${port}.`)
}
diff --git a/src/types/area.js b/src/types/area.js
index 2b010d0..1ecf2d0 100644
--- a/src/types/area.js
+++ b/src/types/area.js
@@ -16,6 +16,7 @@ import {
relationships,
collections,
tags,
+ fieldWithID,
connectionWithExtras
} from './helpers'
@@ -37,6 +38,10 @@ or settlements (countries, cities, or the like).`,
the codes assigned by ISO to countries and subdivisions.`,
resolve: data => data['iso-3166-1-codes']
},
+ ...fieldWithID('type', {
+ description: `The type of area (country, city, etc. – see the [possible
+values](https://musicbrainz.org/doc/Area)).`
+ }),
artists,
events,
labels,
diff --git a/src/types/helpers.js b/src/types/helpers.js
index f8a8131..e666cdb 100644
--- a/src/types/helpers.js
+++ b/src/types/helpers.js
@@ -90,7 +90,14 @@ export function fieldWithID (name, config = {}) {
type: isPlural ? new GraphQLList(MBID) : MBID,
description: `The MBID${s} associated with the value${s} of the \`${name}\`
field.`,
- resolve: resolveHyphenated
+ resolve: (entity, args, { loaders }) => {
+ const fieldName = toDashed(idName)
+ if (fieldName in entity) {
+ return entity[fieldName]
+ }
+ return loaders.lookup.load([entity._type, entity.id])
+ .then(data => data[fieldName])
+ }
}
return {
[name]: config,
diff --git a/test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb b/test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb
new file mode 100644
index 0000000..6a7b527
Binary files /dev/null and b/test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb differ
diff --git a/test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb.headers b/test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb.headers
new file mode 100644
index 0000000..89c663c
--- /dev/null
+++ b/test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb.headers
@@ -0,0 +1,29 @@
+{
+ "statusCode": 200,
+ "headers": {
+ "date": "Sat, 04 Nov 2017 22:18:56 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": "1049",
+ "x-ratelimit-reset": "1509833937",
+ "server": "Plack::Handler::Starlet",
+ "etag": "W/\"f3dbfd2359a7a02668094286e405c7d7\"",
+ "access-control-allow-origin": "*",
+ "content-encoding": "gzip"
+ },
+ "url": "http://musicbrainz.org:80/ws/2/area/d907b0ac-2956-386f-a246-62d55779aae1?fmt=json",
+ "time": 355,
+ "request": {
+ "method": "GET",
+ "headers": {
+ "User-Agent": "graphbrainz/7.0.0 ( https://github.com/exogen/graphbrainz )",
+ "host": "musicbrainz.org",
+ "accept-encoding": "gzip, deflate",
+ "accept": "application/json"
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/fixtures/756130058c8775fa7cb29d1dd73b0466 b/test/fixtures/756130058c8775fa7cb29d1dd73b0466
new file mode 100644
index 0000000..8d967d6
--- /dev/null
+++ b/test/fixtures/756130058c8775fa7cb29d1dd73b0466
@@ -0,0 +1 @@
+{"type":"City","disambiguation":"","type-id":"6fd8f29a-3d0a-32fc-980d-ea697b69da78","sort-name":"New Germany","life-span":{"end":null,"ended":false,"begin":null},"name":"New Germany","id":"36721201-bb7c-4dce-be68-0553b1131205"}
\ No newline at end of file
diff --git a/test/fixtures/756130058c8775fa7cb29d1dd73b0466.headers b/test/fixtures/756130058c8775fa7cb29d1dd73b0466.headers
new file mode 100644
index 0000000..c683061
--- /dev/null
+++ b/test/fixtures/756130058c8775fa7cb29d1dd73b0466.headers
@@ -0,0 +1,27 @@
+{
+ "statusCode": 200,
+ "headers": {
+ "date": "Sat, 04 Nov 2017 22:19:01 GMT",
+ "content-type": "application/json; charset=utf-8",
+ "content-length": "227",
+ "connection": "keep-alive",
+ "keep-alive": "timeout=15",
+ "x-ratelimit-limit": "1200",
+ "x-ratelimit-remaining": "789",
+ "x-ratelimit-reset": "1509833941",
+ "server": "Plack::Handler::Starlet",
+ "etag": "\"f003dc5379faf397737ab63975fcacab\"",
+ "access-control-allow-origin": "*"
+ },
+ "url": "http://musicbrainz.org:80/ws/2/area/36721201-bb7c-4dce-be68-0553b1131205?fmt=json",
+ "time": 356,
+ "request": {
+ "method": "GET",
+ "headers": {
+ "User-Agent": "graphbrainz/7.0.0 ( https://github.com/exogen/graphbrainz )",
+ "host": "musicbrainz.org",
+ "accept-encoding": "gzip, deflate",
+ "accept": "application/json"
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1 b/test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1
new file mode 100644
index 0000000..b717ae5
--- /dev/null
+++ b/test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1
@@ -0,0 +1 @@
+{"type-id":"6fd8f29a-3d0a-32fc-980d-ea697b69da78","life-span":{"ended":false,"begin":null,"end":null},"type":"City","id":"84a30f29-682f-4642-a981-4ba0f50a42fa","sort-name":"Brakel","name":"Brakel","disambiguation":""}
\ No newline at end of file
diff --git a/test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1.headers b/test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1.headers
new file mode 100644
index 0000000..f239cff
--- /dev/null
+++ b/test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1.headers
@@ -0,0 +1,27 @@
+{
+ "statusCode": 200,
+ "headers": {
+ "date": "Sat, 04 Nov 2017 22:19:01 GMT",
+ "content-type": "application/json; charset=utf-8",
+ "content-length": "217",
+ "connection": "keep-alive",
+ "keep-alive": "timeout=15",
+ "x-ratelimit-limit": "1200",
+ "x-ratelimit-remaining": "787",
+ "x-ratelimit-reset": "1509833941",
+ "server": "Plack::Handler::Starlet",
+ "etag": "\"313b6eef3c187e7f009395a2511cb6bc\"",
+ "access-control-allow-origin": "*"
+ },
+ "url": "http://musicbrainz.org:80/ws/2/area/84a30f29-682f-4642-a981-4ba0f50a42fa?fmt=json",
+ "time": 365,
+ "request": {
+ "method": "GET",
+ "headers": {
+ "User-Agent": "graphbrainz/7.0.0 ( https://github.com/exogen/graphbrainz )",
+ "host": "musicbrainz.org",
+ "accept-encoding": "gzip, deflate",
+ "accept": "application/json"
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/fixtures/7c1e7fa42910da45f700bc832c12f126 b/test/fixtures/7c1e7fa42910da45f700bc832c12f126
new file mode 100644
index 0000000..973635b
--- /dev/null
+++ b/test/fixtures/7c1e7fa42910da45f700bc832c12f126
@@ -0,0 +1 @@
+{"id":"516dda4c-c58d-43a7-9bde-ef6b12a8b741","type-id":"6fd8f29a-3d0a-32fc-980d-ea697b69da78","life-span":{"ended":false,"end":null,"begin":null},"name":"New Germany","sort-name":"New Germany","disambiguation":"","type":"City"}
\ No newline at end of file
diff --git a/test/fixtures/7c1e7fa42910da45f700bc832c12f126.headers b/test/fixtures/7c1e7fa42910da45f700bc832c12f126.headers
new file mode 100644
index 0000000..e8cd095
--- /dev/null
+++ b/test/fixtures/7c1e7fa42910da45f700bc832c12f126.headers
@@ -0,0 +1,27 @@
+{
+ "statusCode": 200,
+ "headers": {
+ "date": "Sat, 04 Nov 2017 22:19:01 GMT",
+ "content-type": "application/json; charset=utf-8",
+ "content-length": "227",
+ "connection": "keep-alive",
+ "keep-alive": "timeout=15",
+ "x-ratelimit-limit": "1200",
+ "x-ratelimit-remaining": "788",
+ "x-ratelimit-reset": "1509833941",
+ "server": "Plack::Handler::Starlet",
+ "etag": "\"fd49c850b3796ed9dc7cfdb680d6142d\"",
+ "access-control-allow-origin": "*"
+ },
+ "url": "http://musicbrainz.org:80/ws/2/area/516dda4c-c58d-43a7-9bde-ef6b12a8b741?fmt=json",
+ "time": 365,
+ "request": {
+ "method": "GET",
+ "headers": {
+ "User-Agent": "graphbrainz/7.0.0 ( https://github.com/exogen/graphbrainz )",
+ "host": "musicbrainz.org",
+ "accept-encoding": "gzip, deflate",
+ "accept": "application/json"
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/fixtures/89450a383b06d3be5d7cf6f7c7234721 b/test/fixtures/89450a383b06d3be5d7cf6f7c7234721
new file mode 100644
index 0000000..323bae2
Binary files /dev/null and b/test/fixtures/89450a383b06d3be5d7cf6f7c7234721 differ
diff --git a/test/fixtures/89450a383b06d3be5d7cf6f7c7234721.headers b/test/fixtures/89450a383b06d3be5d7cf6f7c7234721.headers
new file mode 100644
index 0000000..9f23fbc
--- /dev/null
+++ b/test/fixtures/89450a383b06d3be5d7cf6f7c7234721.headers
@@ -0,0 +1,29 @@
+{
+ "statusCode": 200,
+ "headers": {
+ "date": "Sat, 04 Nov 2017 22:18:55 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": "635",
+ "x-ratelimit-reset": "1509833935",
+ "last-modified": "Sat, 04 Nov 2017 21:24:29 GMT",
+ "server": "Jetty(9.3.10.v20160621)",
+ "access-control-allow-origin": "*",
+ "content-encoding": "gzip"
+ },
+ "url": "http://musicbrainz.org:80/ws/2/area?limit=5&query=Germany&fmt=json",
+ "time": 552,
+ "request": {
+ "method": "GET",
+ "headers": {
+ "User-Agent": "graphbrainz/7.0.0 ( https://github.com/exogen/graphbrainz )",
+ "host": "musicbrainz.org",
+ "accept-encoding": "gzip, deflate",
+ "accept": "application/json"
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9 b/test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9
new file mode 100644
index 0000000..74bc844
--- /dev/null
+++ b/test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9
@@ -0,0 +1 @@
+{"iso-3166-1-codes":["DE"],"id":"85752fda-13c4-31a3-bee5-0e5cb1f51dad","name":"Germany","sort-name":"Germany","disambiguation":"","type":"Country","type-id":"06dd0ae4-8c74-30bb-b43d-95dcedf961de","life-span":{"begin":null,"ended":false,"end":null}}
\ No newline at end of file
diff --git a/test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9.headers b/test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9.headers
new file mode 100644
index 0000000..360774a
--- /dev/null
+++ b/test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9.headers
@@ -0,0 +1,27 @@
+{
+ "statusCode": 200,
+ "headers": {
+ "date": "Sat, 04 Nov 2017 22:18:56 GMT",
+ "content-type": "application/json; charset=utf-8",
+ "content-length": "248",
+ "connection": "keep-alive",
+ "keep-alive": "timeout=15",
+ "x-ratelimit-limit": "1200",
+ "x-ratelimit-remaining": "1048",
+ "x-ratelimit-reset": "1509833937",
+ "server": "Plack::Handler::Starlet",
+ "etag": "\"82c22921587af20efc7bb9480993b28f\"",
+ "access-control-allow-origin": "*"
+ },
+ "url": "http://musicbrainz.org:80/ws/2/area/85752fda-13c4-31a3-bee5-0e5cb1f51dad?fmt=json",
+ "time": 370,
+ "request": {
+ "method": "GET",
+ "headers": {
+ "User-Agent": "graphbrainz/7.0.0 ( https://github.com/exogen/graphbrainz )",
+ "host": "musicbrainz.org",
+ "accept-encoding": "gzip, deflate",
+ "accept": "application/json"
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/schema.js b/test/schema.js
index d735ed9..fa56082 100644
--- a/test/schema.js
+++ b/test/schema.js
@@ -502,6 +502,22 @@ test('area maps iso-3166-1-codes to isoCodes', testData, `
t.deepEqual(data.lookup.area.isoCodes, ['US'])
})
+test('areas have a type and typeID', testData, `
+ {
+ search {
+ areas(query: "Germany", first: 5) {
+ nodes {
+ name
+ type
+ typeID
+ }
+ }
+ }
+ }
+`, (t, data) => {
+ t.snapshot(data)
+})
+
test('alias locales use the locale scalar', testData, `
{
lookup {
diff --git a/test/snapshots/schema.js.md b/test/snapshots/schema.js.md
new file mode 100644
index 0000000..076020f
--- /dev/null
+++ b/test/snapshots/schema.js.md
@@ -0,0 +1,43 @@
+# Snapshot report for `test/schema.js`
+
+The actual snapshot is saved in `schema.js.snap`.
+
+Generated by [AVA](https://ava.li).
+
+## areas have a type and typeID
+
+> Snapshot 1
+
+ {
+ search: {
+ areas: {
+ nodes: [
+ {
+ name: 'Germany',
+ type: 'Country',
+ typeID: '06dd0ae4-8c74-30bb-b43d-95dcedf961de',
+ },
+ {
+ name: 'East Germany',
+ type: 'Country',
+ typeID: '06dd0ae4-8c74-30bb-b43d-95dcedf961de',
+ },
+ {
+ name: 'New Germany',
+ type: 'City',
+ typeID: '6fd8f29a-3d0a-32fc-980d-ea697b69da78',
+ },
+ {
+ name: 'New Germany',
+ type: 'City',
+ typeID: '6fd8f29a-3d0a-32fc-980d-ea697b69da78',
+ },
+ {
+ name: 'Brakel',
+ type: 'City',
+ typeID: '6fd8f29a-3d0a-32fc-980d-ea697b69da78',
+ },
+ ],
+ },
+ },
+ }
diff --git a/test/snapshots/schema.js.snap b/test/snapshots/schema.js.snap
new file mode 100644
index 0000000..3d34741
Binary files /dev/null and b/test/snapshots/schema.js.snap differ