diff --git a/test/fixtures/05fcd912e8786fff4dca854a7fa44c81.headers b/test/fixtures/05fcd912e8786fff4dca854a7fa44c81.headers index aaed104..6874b25 100644 --- a/test/fixtures/05fcd912e8786fff4dca854a7fa44c81.headers +++ b/test/fixtures/05fcd912e8786fff4dca854a7fa44c81.headers @@ -1,22 +1,22 @@ { "statusCode": 200, "headers": { - "date": "Wed, 07 Dec 2016 23:09:35 GMT", + "date": "Thu, 08 Dec 2016 22:10:36 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": "361", - "x-ratelimit-reset": "1481152175", + "x-ratelimit-remaining": "547", + "x-ratelimit-reset": "1481235037", "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": 744, + "time": 604, "request": { "method": "GET", "headers": { diff --git a/test/fixtures/157ce6484de07a7e2ee93b54e8244e27 b/test/fixtures/157ce6484de07a7e2ee93b54e8244e27 new file mode 100644 index 0000000..2ae7eed Binary files /dev/null and b/test/fixtures/157ce6484de07a7e2ee93b54e8244e27 differ diff --git a/test/fixtures/157ce6484de07a7e2ee93b54e8244e27.headers b/test/fixtures/157ce6484de07a7e2ee93b54e8244e27.headers new file mode 100644 index 0000000..f9ac62a --- /dev/null +++ b/test/fixtures/157ce6484de07a7e2ee93b54e8244e27.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:38 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", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/456168a862ec0ca28127f067e3f166e7 b/test/fixtures/456168a862ec0ca28127f067e3f166e7 index 2abf52e..f4d156e 100644 Binary files a/test/fixtures/456168a862ec0ca28127f067e3f166e7 and b/test/fixtures/456168a862ec0ca28127f067e3f166e7 differ diff --git a/test/fixtures/456168a862ec0ca28127f067e3f166e7.headers b/test/fixtures/456168a862ec0ca28127f067e3f166e7.headers index 9fdb41b..c25c596 100644 --- a/test/fixtures/456168a862ec0ca28127f067e3f166e7.headers +++ b/test/fixtures/456168a862ec0ca28127f067e3f166e7.headers @@ -1,22 +1,22 @@ { "statusCode": 200, "headers": { - "date": "Wed, 07 Dec 2016 23:09:34 GMT", + "date": "Thu, 08 Dec 2016 22:10:35 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": "596", - "x-ratelimit-reset": "1481152175", + "x-ratelimit-remaining": "250", + "x-ratelimit-reset": "1481235035", "server": "Plack::Handler::Starlet", - "etag": "W/\"70e9c6b355083588be1b5abb2e76e291\"", + "etag": "W/\"39c7b86496389329f958f3d9d8599d32\"", "access-control-allow-origin": "*", "content-encoding": "gzip" }, "url": "http://musicbrainz.org:80/ws/2/artist/c8da2e40-bd28-4d4e-813a-bd2f51958ba8?fmt=json", - "time": 361, + "time": 3316, "request": { "method": "GET", "headers": { diff --git a/test/fixtures/6044ddc15443664659ef91c3c73c0776 b/test/fixtures/6044ddc15443664659ef91c3c73c0776 new file mode 100644 index 0000000..ed6e425 Binary files /dev/null and b/test/fixtures/6044ddc15443664659ef91c3c73c0776 differ diff --git a/test/fixtures/6044ddc15443664659ef91c3c73c0776.headers b/test/fixtures/6044ddc15443664659ef91c3c73c0776.headers new file mode 100644 index 0000000..f125c93 --- /dev/null +++ b/test/fixtures/6044ddc15443664659ef91c3c73c0776.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:44 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"1bb5095802d059afef4624c8e955cac9\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/69d9c8738fe3ea4883276fd8fc9979ce b/test/fixtures/69d9c8738fe3ea4883276fd8fc9979ce new file mode 100644 index 0000000..775e601 Binary files /dev/null and b/test/fixtures/69d9c8738fe3ea4883276fd8fc9979ce differ diff --git a/test/fixtures/69d9c8738fe3ea4883276fd8fc9979ce.headers b/test/fixtures/69d9c8738fe3ea4883276fd8fc9979ce.headers new file mode 100644 index 0000000..7b869a2 --- /dev/null +++ b/test/fixtures/69d9c8738fe3ea4883276fd8fc9979ce.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:44 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"6ef3837bacadc37c2b7f98ef14494ffa\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/9247bb00fc5e2e0dcf1fcd269df8b94e b/test/fixtures/9247bb00fc5e2e0dcf1fcd269df8b94e new file mode 100644 index 0000000..25c9e0a Binary files /dev/null and b/test/fixtures/9247bb00fc5e2e0dcf1fcd269df8b94e differ diff --git a/test/fixtures/9247bb00fc5e2e0dcf1fcd269df8b94e.headers b/test/fixtures/9247bb00fc5e2e0dcf1fcd269df8b94e.headers new file mode 100644 index 0000000..2d4a9b8 --- /dev/null +++ b/test/fixtures/9247bb00fc5e2e0dcf1fcd269df8b94e.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:38 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"39e8c37928b3a6031027cd8ab314a49d\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/97ec62634d0a8953ab3ba2ffce984a83 b/test/fixtures/97ec62634d0a8953ab3ba2ffce984a83 new file mode 100644 index 0000000..eadf9a2 Binary files /dev/null and b/test/fixtures/97ec62634d0a8953ab3ba2ffce984a83 differ diff --git a/test/fixtures/97ec62634d0a8953ab3ba2ffce984a83.headers b/test/fixtures/97ec62634d0a8953ab3ba2ffce984a83.headers new file mode 100644 index 0000000..6bf43a7 --- /dev/null +++ b/test/fixtures/97ec62634d0a8953ab3ba2ffce984a83.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:47 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"40e494f99de2f93d29eb00587cf919e8\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052 b/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052 index 7db0efa..14e944a 100644 Binary files a/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052 and b/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052 differ diff --git a/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052.headers b/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052.headers index aa93b5f..b94e736 100644 --- a/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052.headers +++ b/test/fixtures/a81703ff2de3c55fdf82ff4d0a1f5052.headers @@ -1,22 +1,22 @@ { "statusCode": 200, "headers": { - "date": "Wed, 07 Dec 2016 23:09:35 GMT", + "date": "Thu, 08 Dec 2016 22:10:36 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": "154", - "x-ratelimit-reset": "1481152175", + "x-ratelimit-remaining": "396", + "x-ratelimit-reset": "1481235037", "server": "Plack::Handler::Starlet", - "etag": "W/\"141f49e0130d012e9f5ffc328bc55045\"", + "etag": "W/\"94bf3bba877af6290e53de6524fcbdf3\"", "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": 379, + "time": 490, "request": { "method": "GET", "headers": { diff --git a/test/fixtures/b1df6f5637b0de25ce9f54874c8ecffc b/test/fixtures/b1df6f5637b0de25ce9f54874c8ecffc new file mode 100644 index 0000000..316ad52 Binary files /dev/null and b/test/fixtures/b1df6f5637b0de25ce9f54874c8ecffc differ diff --git a/test/fixtures/b1df6f5637b0de25ce9f54874c8ecffc.headers b/test/fixtures/b1df6f5637b0de25ce9f54874c8ecffc.headers new file mode 100644 index 0000000..ed9064b --- /dev/null +++ b/test/fixtures/b1df6f5637b0de25ce9f54874c8ecffc.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:44 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"ff712330ac15db00e8bfb935e809bf95\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/c907a9892b9dacd1c8f6a85cf9b95fb9 b/test/fixtures/c907a9892b9dacd1c8f6a85cf9b95fb9 new file mode 100644 index 0000000..6cc2f4f Binary files /dev/null and b/test/fixtures/c907a9892b9dacd1c8f6a85cf9b95fb9 differ diff --git a/test/fixtures/c907a9892b9dacd1c8f6a85cf9b95fb9.headers b/test/fixtures/c907a9892b9dacd1c8f6a85cf9b95fb9.headers new file mode 100644 index 0000000..7b2cb4a --- /dev/null +++ b/test/fixtures/c907a9892b9dacd1c8f6a85cf9b95fb9.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:42 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"a60590c307227cfa6ee8fff91153f1bc\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/d1a0073e6dcac919d8fdf8be12bfcbec b/test/fixtures/d1a0073e6dcac919d8fdf8be12bfcbec new file mode 100644 index 0000000..8c63d6f Binary files /dev/null and b/test/fixtures/d1a0073e6dcac919d8fdf8be12bfcbec differ diff --git a/test/fixtures/d1a0073e6dcac919d8fdf8be12bfcbec.headers b/test/fixtures/d1a0073e6dcac919d8fdf8be12bfcbec.headers new file mode 100644 index 0000000..5fefca3 --- /dev/null +++ b/test/fixtures/d1a0073e6dcac919d8fdf8be12bfcbec.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:47 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"fa1c3dc12994eab7fe0dcb44b627373c\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/fixtures/f2a7af3e3a39e31ee0d9d74b5820ebff b/test/fixtures/f2a7af3e3a39e31ee0d9d74b5820ebff new file mode 100644 index 0000000..f30b97c Binary files /dev/null and b/test/fixtures/f2a7af3e3a39e31ee0d9d74b5820ebff differ diff --git a/test/fixtures/f2a7af3e3a39e31ee0d9d74b5820ebff.headers b/test/fixtures/f2a7af3e3a39e31ee0d9d74b5820ebff.headers new file mode 100644 index 0000000..5cfc8ba --- /dev/null +++ b/test/fixtures/f2a7af3e3a39e31ee0d9d74b5820ebff.headers @@ -0,0 +1,29 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 08 Dec 2016 22:10:44 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", + "server": "Plack::Handler::Starlet", + "etag": "W/\"8816493f7872c79a0eabce9b71262302\"", + "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, + "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" + } + } +} \ No newline at end of file diff --git a/test/schema.js b/test/schema.js index 346d4cd..2e6af39 100644 --- a/test/schema.js +++ b/test/schema.js @@ -8,11 +8,9 @@ import createLoaders from '../src/loaders' sepia.fixtureDir(path.join(__dirname, 'fixtures')) -test.beforeEach(t => { - const client = new MusicBrainz() - const loaders = createLoaders(client) - t.context = { client, loaders } -}) +const client = new MusicBrainz() +const loaders = createLoaders(client) +const context = { client, loaders } test('schema has a lookup query', t => { const query = ` @@ -26,7 +24,7 @@ test('schema has a lookup query', t => { } } ` - return graphql(schema, query, null, t.context).then(result => { + return graphql(schema, query, null, context).then(result => { t.deepEqual(result, { data: { lookup: { @@ -58,7 +56,7 @@ test('schema has a search query', t => { } } ` - return graphql(schema, query, null, t.context).then(result => { + return graphql(schema, query, null, context).then(result => { const { recordings } = result.data.search t.true(recordings.totalCount > 0) t.true(recordings.edges.length === 25) @@ -89,10 +87,87 @@ test('schema has a browse query', t => { } } ` - return graphql(schema, query, null, t.context).then(result => { + return graphql(schema, query, null, context).then(result => { const { releaseGroups } = result.data.browse t.true(releaseGroups.totalCount > 0) t.true(releaseGroups.edges.length > 0) releaseGroups.edges.forEach(edge => t.truthy(edge.node.title)) }) }) + +test('supports deeply nested queries', t => { + const query = ` + query AppleRecordsMarriages { + search { + labels(query: "Apple Records", first: 1) { + edges { + node { + name + disambiguation + country + releases(first: 1) { + edges { + node { + title + date + artists { + edges { + node { + name + ...bandMembers + } + } + } + } + } + } + } + } + } + } + } + + fragment bandMembers on Artist { + relationships { + artists(direction: "backward", type: "member of band") { + edges { + node { + type + target { + ... on Artist { + name + ...marriages + } + } + } + } + } + } + } + + fragment marriages on Artist { + relationships { + artists(type: "married") { + edges { + node { + type + direction + begin + end + target { + ... on Artist { + name + } + } + } + } + } + } + } + ` + return graphql(schema, query, null, context).then(result => { + const { labels } = result.data.search + t.true(labels.edges.length > 0) + t.is(labels.edges[0].node.releases.edges.length, 1) + }) +})