mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
Add missing Area type/typeID, pass start() options to middleware (#46)
This commit is contained in:
parent
e77143fbd7
commit
75e24c18bc
28 changed files with 310 additions and 18 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" valign="top"><strong>type</strong></td>
|
||||
<td valign="top"><a href="#string">String</a></td>
|
||||
<td>
|
||||
|
||||
The type of area (country, city, etc. – see the [possible
|
||||
values](https://musicbrainz.org/doc/Area)).
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" valign="top"><strong>typeID</strong></td>
|
||||
<td valign="top"><a href="#mbid">MBID</a></td>
|
||||
<td>
|
||||
|
||||
The MBID associated with the value of the `type`
|
||||
field.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
24
schema.json
24
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.",
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -47,5 +47,6 @@ export default function createLoader (options) {
|
|||
cacheKeyFn: ([ entityType, id ]) => `${entityType}/${id}`,
|
||||
cacheMap: cache
|
||||
})
|
||||
|
||||
return loader
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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}.`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
BIN
test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb
vendored
Normal file
BIN
test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb
vendored
Normal file
Binary file not shown.
29
test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb.headers
vendored
Normal file
29
test/fixtures/0e70a8c76fbbaf74403b1979f99fbdeb.headers
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/fixtures/756130058c8775fa7cb29d1dd73b0466
vendored
Normal file
1
test/fixtures/756130058c8775fa7cb29d1dd73b0466
vendored
Normal file
|
|
@ -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"}
|
||||
27
test/fixtures/756130058c8775fa7cb29d1dd73b0466.headers
vendored
Normal file
27
test/fixtures/756130058c8775fa7cb29d1dd73b0466.headers
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1
vendored
Normal file
1
test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1
vendored
Normal file
|
|
@ -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":""}
|
||||
27
test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1.headers
vendored
Normal file
27
test/fixtures/761c6577dcc6cfe15f0c2143f6c6dfd1.headers
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/fixtures/7c1e7fa42910da45f700bc832c12f126
vendored
Normal file
1
test/fixtures/7c1e7fa42910da45f700bc832c12f126
vendored
Normal file
|
|
@ -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"}
|
||||
27
test/fixtures/7c1e7fa42910da45f700bc832c12f126.headers
vendored
Normal file
27
test/fixtures/7c1e7fa42910da45f700bc832c12f126.headers
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
test/fixtures/89450a383b06d3be5d7cf6f7c7234721
vendored
Normal file
BIN
test/fixtures/89450a383b06d3be5d7cf6f7c7234721
vendored
Normal file
Binary file not shown.
29
test/fixtures/89450a383b06d3be5d7cf6f7c7234721.headers
vendored
Normal file
29
test/fixtures/89450a383b06d3be5d7cf6f7c7234721.headers
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9
vendored
Normal file
1
test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9
vendored
Normal file
|
|
@ -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}}
|
||||
27
test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9.headers
vendored
Normal file
27
test/fixtures/d191cb9a3134c90cfaa98b8b73f9e8c9.headers
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
43
test/snapshots/schema.js.md
Normal file
43
test/snapshots/schema.js.md
Normal file
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
BIN
test/snapshots/schema.js.snap
Normal file
BIN
test/snapshots/schema.js.snap
Normal file
Binary file not shown.
Loading…
Reference in a new issue