From 0600c2026b13142cb45a9d55a6acb0eeb9b4f163 Mon Sep 17 00:00:00 2001 From: Brian Beck Date: Sun, 11 Dec 2016 16:12:54 -0800 Subject: [PATCH] Use Duration scalar for recording lengths (#11) --- src/types/recording.js | 5 ++-- .../fixtures/81a6d797dbe67ce75ba99ed2f5315ee0 | 1 + .../81a6d797dbe67ce75ba99ed2f5315ee0.headers | 27 +++++++++++++++++++ test/schema.js | 13 +++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0 create mode 100644 test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0.headers diff --git a/src/types/recording.js b/src/types/recording.js index a6fa506..1c6174c 100644 --- a/src/types/recording.js +++ b/src/types/recording.js @@ -1,12 +1,11 @@ import { GraphQLObjectType, GraphQLList, - GraphQLInt, GraphQLBoolean } from 'graphql/type' import Node from './node' import Entity from './entity' -import { ISRC } from './scalars' +import { Duration, ISRC } from './scalars' import { id, mbid, @@ -51,7 +50,7 @@ or mixing.`, (ISRCs) for this recording.` }, length: { - type: GraphQLInt, + type: Duration, description: `An approximation to the length of the recording, calculated from the lengths of the tracks using it.` }, diff --git a/test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0 b/test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0 new file mode 100644 index 0000000..328d7e0 --- /dev/null +++ b/test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0 @@ -0,0 +1 @@ +{"disambiguation":"","id":"9f9cf187-d6f9-437f-9d98-d59cdbd52757","video":false,"length":383493,"title":"Paranoid Android"} \ No newline at end of file diff --git a/test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0.headers b/test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0.headers new file mode 100644 index 0000000..0f91d59 --- /dev/null +++ b/test/fixtures/81a6d797dbe67ce75ba99ed2f5315ee0.headers @@ -0,0 +1,27 @@ +{ + "statusCode": 200, + "headers": { + "date": "Sun, 11 Dec 2016 22:49:10 GMT", + "content-type": "application/json; charset=utf-8", + "content-length": "122", + "connection": "keep-alive", + "keep-alive": "timeout=15", + "x-ratelimit-limit": "700", + "x-ratelimit-remaining": "535", + "x-ratelimit-reset": "1481496552", + "server": "Plack::Handler::Starlet", + "etag": "\"6a43a7029600ae595783f39d6d3d1f63\"", + "access-control-allow-origin": "*" + }, + "url": "http://musicbrainz.org:80/ws/2/recording/9f9cf187-d6f9-437f-9d98-d59cdbd52757?fmt=json", + "time": 424, + "request": { + "method": "GET", + "headers": { + "User-Agent": "graphbrainz/4.2.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 521d569..8fd3f0c 100644 --- a/test/schema.js +++ b/test/schema.js @@ -579,3 +579,16 @@ test('Works can be browsed by iswc', testData, ` { title: 'Song of the French Partisan', iswcs: ['T-900.755.682-3'] } ]) }) + +test('Recordings have a length in milliseconds', testData, ` + { + lookup { + recording(mbid: "9f9cf187-d6f9-437f-9d98-d59cdbd52757") { + length + } + } + } +`, (t, data) => { + const { recording } = data.lookup + t.is(recording.length, 383493) +})