Add tests, fix cases where loaders are not passed params

This commit is contained in:
Brian Beck 2016-12-08 14:33:18 -08:00
parent 5b41af6e6a
commit 3252b52dc1
27 changed files with 113 additions and 62 deletions

View file

@ -21,7 +21,7 @@ export default function createLoaders (client) {
const lookup = new DataLoader(keys => {
return Promise.all(keys.map(key => {
const [ entityType, id, params ] = key
const [ entityType, id, params = {} ] = key
return client.lookup(entityType, id, params).then(entity => {
if (entity) {
// Store the entity type so we can determine what type of object this
@ -39,7 +39,7 @@ export default function createLoaders (client) {
const browse = new DataLoader(keys => {
return Promise.all(keys.map(key => {
const [ entityType, params ] = key
const [ entityType, params = {} ] = key
return client.browse(entityType, params).then(list => {
list[toPlural(entityType)].forEach(entity => {
// Store the entity type so we can determine what type of object this
@ -57,7 +57,7 @@ export default function createLoaders (client) {
const search = new DataLoader(keys => {
return Promise.all(keys.map(key => {
const [ entityType, query, params ] = key
const [ entityType, query, params = {} ] = key
return client.search(entityType, query, params).then(list => {
list[toPlural(entityType)].forEach(entity => {
// Store the entity type so we can determine what type of object this

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:36 GMT",
"date": "Thu, 08 Dec 2016 22:32:00 GMT",
"content-type": "application/json; charset=UTF-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "547",
"x-ratelimit-reset": "1481235037",
"x-ratelimit-remaining": "303",
"x-ratelimit-reset": "1481236321",
"last-modified": "Wed, 09 Nov 2016 23:43:24 GMT",
"server": "Jetty(9.3.10.v20160621)",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/recording?query=Burn%20the%20Witch&fmt=json",
"time": 604,
"time": 596,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:38 GMT",
"date": "Thu, 08 Dec 2016 22:32:02 GMT",
"content-type": "application/json; charset=UTF-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "679",
"x-ratelimit-reset": "1481235039",
"last-modified": "Thu, 08 Dec 2016 21:32:00 GMT",
"x-ratelimit-remaining": "334",
"x-ratelimit-reset": "1481236323",
"last-modified": "Thu, 08 Dec 2016 22:03:30 GMT",
"server": "Jetty(9.3.10.v20160621)",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/label?limit=1&query=Apple%20Records&fmt=json",
"time": 1473,
"time": 1539,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:35 GMT",
"date": "Thu, 08 Dec 2016 22:31:58 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "250",
"x-ratelimit-reset": "1481235035",
"x-ratelimit-remaining": "180",
"x-ratelimit-reset": "1481236319",
"server": "Plack::Handler::Starlet",
"etag": "W/\"39c7b86496389329f958f3d9d8599d32\"",
"etag": "W/\"15092bd7b55df20c4f8fd072b82a0f1f\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist/c8da2e40-bd28-4d4e-813a-bd2f51958ba8?fmt=json",
"time": 3316,
"time": 426,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:44 GMT",
"date": "Thu, 08 Dec 2016 22:32:06 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "553",
"x-ratelimit-reset": "1481235045",
"x-ratelimit-remaining": "289",
"x-ratelimit-reset": "1481236327",
"server": "Plack::Handler::Starlet",
"etag": "W/\"1bb5095802d059afef4624c8e955cac9\"",
"etag": "W/\"6a12c1ded7c7c8d9315107669601ed70\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist/300c4c73-33ac-4255-9d57-4e32627f5e13?inc=artist-rels&fmt=json",
"time": 2141,
"time": 556,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:44 GMT",
"date": "Thu, 08 Dec 2016 22:32:06 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "552",
"x-ratelimit-reset": "1481235045",
"x-ratelimit-remaining": "287",
"x-ratelimit-reset": "1481236327",
"server": "Plack::Handler::Starlet",
"etag": "W/\"6ef3837bacadc37c2b7f98ef14494ffa\"",
"etag": "W/\"cfec247269cfa3680afeab36d412221c\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist/0d4ab0f9-bbda-4ab1-ae2c-f772ffcfbea9?inc=artist-rels&fmt=json",
"time": 2139,
"time": 517,
"request": {
"method": "GET",
"headers": {

View file

@ -0,0 +1 @@
{"primary-type":"Album","disambiguation":"","title":"Lures","secondary-types":[],"id":"e37d2740-4503-4e3f-ab6d-e622a25e964d","secondary-type-ids":[],"first-release-date":"2014-10-07","primary-type-id":"f529b476-6e62-324f-b0aa-1f3e33d313fc"}

View file

@ -0,0 +1,27 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:32:00 GMT",
"content-type": "application/json; charset=utf-8",
"content-length": "240",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "504",
"x-ratelimit-reset": "1481236321",
"server": "Plack::Handler::Starlet",
"etag": "\"89bacb0f43473ab326be8f6ba1f42afd\"",
"access-control-allow-origin": "*"
},
"url": "http://musicbrainz.org:80/ws/2/release-group/e37d2740-4503-4e3f-ab6d-e622a25e964d?fmt=json",
"time": 588,
"request": {
"method": "GET",
"headers": {
"User-Agent": "graphbrainz/3.1.0 ( https://github.com/exogen/graphbrainz )",
"host": "musicbrainz.org",
"accept-encoding": "gzip, deflate",
"accept": "application/json"
}
}
}

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:38 GMT",
"date": "Thu, 08 Dec 2016 22:32:05 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "381",
"x-ratelimit-reset": "1481235039",
"x-ratelimit-remaining": "697",
"x-ratelimit-reset": "1481236327",
"server": "Plack::Handler::Starlet",
"etag": "W/\"39e8c37928b3a6031027cd8ab314a49d\"",
"etag": "W/\"9020613941ca4d7631fab0e7d51d077f\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/release?label=cf7fc5cf-e011-4ef4-b511-cd0188537910&limit=1&fmt=json",
"time": 525,
"time": 390,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:47 GMT",
"date": "Thu, 08 Dec 2016 22:32:11 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "297",
"x-ratelimit-reset": "1481235047",
"x-ratelimit-remaining": "254",
"x-ratelimit-reset": "1481236331",
"server": "Plack::Handler::Starlet",
"etag": "W/\"40e494f99de2f93d29eb00587cf919e8\"",
"etag": "W/\"285b663debaf6f383194dcb82b6655e1\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist/ba550d0e-adac-4864-b88b-407cab5e76af?inc=artist-rels&fmt=json",
"time": 578,
"time": 677,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:36 GMT",
"date": "Thu, 08 Dec 2016 22:32:01 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "396",
"x-ratelimit-reset": "1481235037",
"x-ratelimit-remaining": "147",
"x-ratelimit-reset": "1481236321",
"server": "Plack::Handler::Starlet",
"etag": "W/\"94bf3bba877af6290e53de6524fcbdf3\"",
"etag": "W/\"2dd0bb83c0e5e4f352ffbf3a1272050d\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/release-group?artist=c8da2e40-bd28-4d4e-813a-bd2f51958ba8&inc=artist-credits&fmt=json",
"time": 490,
"time": 439,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:44 GMT",
"date": "Thu, 08 Dec 2016 22:32:10 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "551",
"x-ratelimit-reset": "1481235045",
"x-ratelimit-remaining": "255",
"x-ratelimit-reset": "1481236331",
"server": "Plack::Handler::Starlet",
"etag": "W/\"ff712330ac15db00e8bfb935e809bf95\"",
"etag": "W/\"dbec5286f8302667b6edff5be3352490\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist/49a51491-650e-44b3-8085-2f07ac2986dd?inc=artist-rels&fmt=json",
"time": 2134,
"time": 672,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:42 GMT",
"date": "Thu, 08 Dec 2016 22:32:06 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "574",
"x-ratelimit-reset": "1481235043",
"x-ratelimit-remaining": "570",
"x-ratelimit-reset": "1481236327",
"server": "Plack::Handler::Starlet",
"etag": "W/\"a60590c307227cfa6ee8fff91153f1bc\"",
"etag": "W/\"00e70096bc0434f732f47e3050094637\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist?release=2ac3cbf2-f0d0-3678-af5f-b62dcb051bc0&inc=artist-rels&fmt=json",
"time": 1544,
"time": 841,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:47 GMT",
"date": "Thu, 08 Dec 2016 22:32:11 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "299",
"x-ratelimit-reset": "1481235047",
"x-ratelimit-remaining": "253",
"x-ratelimit-reset": "1481236331",
"server": "Plack::Handler::Starlet",
"etag": "W/\"fa1c3dc12994eab7fe0dcb44b627373c\"",
"etag": "W/\"262816d2e746629059388bf96eb1241d\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist/4d5447d7-c61c-4120-ba1b-d7f471d385b9?inc=artist-rels&fmt=json",
"time": 538,
"time": 676,
"request": {
"method": "GET",
"headers": {

Binary file not shown.

View file

@ -1,22 +1,22 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 08 Dec 2016 22:10:44 GMT",
"date": "Thu, 08 Dec 2016 22:32:06 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"keep-alive": "timeout=15",
"vary": "Accept-Encoding",
"x-ratelimit-limit": "700",
"x-ratelimit-remaining": "550",
"x-ratelimit-reset": "1481235045",
"x-ratelimit-remaining": "288",
"x-ratelimit-reset": "1481236327",
"server": "Plack::Handler::Starlet",
"etag": "W/\"8816493f7872c79a0eabce9b71262302\"",
"etag": "W/\"7c937ac3dcff44777fa9d4c32d65b803\"",
"access-control-allow-origin": "*",
"content-encoding": "gzip"
},
"url": "http://musicbrainz.org:80/ws/2/artist/42a8f507-8412-4611-854f-926571049fa0?inc=artist-rels&fmt=json",
"time": 2138,
"time": 558,
"request": {
"method": "GET",
"headers": {

View file

@ -12,6 +12,29 @@ const client = new MusicBrainz()
const loaders = createLoaders(client)
const context = { client, loaders }
test('schema has a node field', t => {
const query = `
{
node(id: "UmVsZWFzZUdyb3VwOmUzN2QyNzQwLTQ1MDMtNGUzZi1hYjZkLWU2MjJhMjVlOTY0ZA==") {
__typename
... on ReleaseGroup {
mbid
}
}
}
`
return graphql(schema, query, null, context).then(result => {
t.deepEqual(result, {
data: {
node: {
__typename: 'ReleaseGroup',
mbid: 'e37d2740-4503-4e3f-ab6d-e622a25e964d'
}
}
})
})
})
test('schema has a lookup query', t => {
const query = `
{