From d906ec1086e86523687c6bf0c53c79ff7f200f19 Mon Sep 17 00:00:00 2001 From: Brian Beck Date: Mon, 12 Dec 2016 01:01:40 -0800 Subject: [PATCH] Add support for release media (#14) --- docs/schema.md | 28 ++++++ docs/types.md | 63 +++++++++++++ schema.json | 87 ++++++++++++++++++ src/resolvers.js | 1 + src/types/media.js | 31 +++++++ src/types/release.js | 5 + .../fixtures/f70e148191e1ebbc95eb12ddc2d85be2 | Bin 0 -> 519 bytes .../f70e148191e1ebbc95eb12ddc2d85be2.headers | 29 ++++++ test/schema.js | 34 +++++++ 9 files changed, 278 insertions(+) create mode 100644 src/types/media.js create mode 100644 test/fixtures/f70e148191e1ebbc95eb12ddc2d85be2 create mode 100644 test/fixtures/f70e148191e1ebbc95eb12ddc2d85be2.headers diff --git a/docs/schema.md b/docs/schema.md index fd2a15d..1f4711c 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -987,6 +987,31 @@ type LookupQuery { # 36-character UUIDs. scalar MBID +# A medium is the actual physical medium the audio content is +# stored upon. This means that each CD in a multi-disc release will be entered as +# separate mediums within the release, and that both sides of a vinyl record or +# cassette will exist on one medium. Mediums have a format (e.g. CD, DVD, vinyl, +# cassette) and can optionally also have a title. +type Medium { + # The title of this particular medium. + title: String + + # The [format](https://musicbrainz.org/doc/Release/Format) of + # the medium (e.g. CD, DVD, vinyl, cassette). + format: String + + # The MBID associated with the value of the `format` + # field. + formatID: MBID + + # The order of this medium in the release (for example, in a + # multi-disc release). + position: Int + + # The number of audio tracks on this medium. + trackCount: Int +} + # An object with an ID interface Node { # The id of the object. @@ -1551,6 +1576,9 @@ type Release implements Node, Entity { # [ratings](https://musicbrainz.org/doc/Rating_System). quality: String + # The media on which the release was distributed. + media: [Medium] + # 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 935fa3d..eef0911 100644 --- a/docs/types.md +++ b/docs/types.md @@ -29,6 +29,7 @@ You may also be interested in reading the [schema in GraphQL syntax](schema.md).
  • [LabelEdge](#labeledge)
  • [LifeSpan](#lifespan)
  • [LookupQuery](#lookupquery)
  • +
  • [Medium](#medium)
  • [PageInfo](#pageinfo)
  • [Place](#place)
  • [PlaceConnection](#placeconnection)
  • @@ -2503,6 +2504,61 @@ A lookup of an individual MusicBrainz entity by its MBID. +### Medium + +A medium is the actual physical medium the audio content is +stored upon. This means that each CD in a multi-disc release will be entered as +separate mediums within the release, and that both sides of a vinyl record or +cassette will exist on one medium. Mediums have a format (e.g. CD, DVD, vinyl, +cassette) and can optionally also have a title. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Field / ArgumentTypeDescription
    title String + The title of this particular medium. +
    format String + The format of +the medium (e.g. CD, DVD, vinyl, cassette). +
    formatID MBID + The MBID associated with the value of the format +field. +
    position Int + The order of this medium in the release (for example, in a +multi-disc release). +
    trackCount Int + The number of audio tracks on this medium. +
    + ### PageInfo Information about pagination in a connection. @@ -3877,6 +3933,13 @@ It is not a mark of how good or bad the music itself is – for that, use ratings. + + media + [Medium] + + The media on which the release was distributed. + + artists ArtistConnection diff --git a/schema.json b/schema.json index ddb165d..e75dcd0 100644 --- a/schema.json +++ b/schema.json @@ -2911,6 +2911,22 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "media", + "description": "The media on which the release was distributed.", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "Medium", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "artists", "description": "A list of artists linked to this entity.", @@ -3197,6 +3213,77 @@ "enumValues": null, "possibleTypes": null }, + { + "kind": "OBJECT", + "name": "Medium", + "description": "A medium is the actual physical medium the audio content is\nstored upon. This means that each CD in a multi-disc release will be entered as\nseparate mediums within the release, and that both sides of a vinyl record or\ncassette will exist on one medium. Mediums have a format (e.g. CD, DVD, vinyl,\ncassette) and can optionally also have a title.", + "fields": [ + { + "name": "title", + "description": "The title of this particular medium.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "format", + "description": "The [format](https://musicbrainz.org/doc/Release/Format) of\nthe medium (e.g. CD, DVD, vinyl, cassette).", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "formatID", + "description": "The MBID associated with the value of the `format`\nfield.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "MBID", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "position", + "description": "The order of this medium in the release (for example, in a\nmulti-disc release).", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "trackCount", + "description": "The number of audio tracks on this medium.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, { "kind": "OBJECT", "name": "LabelConnection", diff --git a/src/resolvers.js b/src/resolvers.js index f75cfba..7366990 100644 --- a/src/resolvers.js +++ b/src/resolvers.js @@ -42,6 +42,7 @@ export function includeSubqueries (params, info, fragments = info.fragments) { artistCredit: 'artist-credits', artistCredits: 'artist-credits', isrcs: 'isrcs', + media: 'media', tags: 'tags' } let fields = getFields(info, fragments) diff --git a/src/types/media.js b/src/types/media.js new file mode 100644 index 0000000..abc43d0 --- /dev/null +++ b/src/types/media.js @@ -0,0 +1,31 @@ +import { GraphQLObjectType, GraphQLString, GraphQLInt } from 'graphql/type' +import { resolveHyphenated, fieldWithID } from './helpers' + +export default new GraphQLObjectType({ + name: 'Medium', + description: `A medium is the actual physical medium the audio content is +stored upon. This means that each CD in a multi-disc release will be entered as +separate mediums within the release, and that both sides of a vinyl record or +cassette will exist on one medium. Mediums have a format (e.g. CD, DVD, vinyl, +cassette) and can optionally also have a title.`, + fields: () => ({ + title: { + type: GraphQLString, + description: 'The title of this particular medium.' + }, + ...fieldWithID('format', { + description: `The [format](https://musicbrainz.org/doc/Release/Format) of +the medium (e.g. CD, DVD, vinyl, cassette).` + }), + position: { + type: GraphQLInt, + description: `The order of this medium in the release (for example, in a +multi-disc release).` + }, + trackCount: { + type: GraphQLInt, + description: 'The number of audio tracks on this medium.', + resolve: resolveHyphenated + } + }) +}) diff --git a/src/types/release.js b/src/types/release.js index dd60f91..80f8abc 100644 --- a/src/types/release.js +++ b/src/types/release.js @@ -2,6 +2,7 @@ import { GraphQLObjectType, GraphQLString, GraphQLList } from 'graphql/type' import Node from './node' import Entity from './entity' import { ASIN, DateType } from './scalars' +import Media from './media' import { ReleaseStatus } from './enums' import ReleaseEvent from './release-event' import { @@ -82,6 +83,10 @@ information.` It is not a mark of how good or bad the music itself is – for that, use [ratings](https://musicbrainz.org/doc/Rating_System).` }, + media: { + type: new GraphQLList(Media), + description: 'The media on which the release was distributed.' + }, artists, labels, recordings, diff --git a/test/fixtures/f70e148191e1ebbc95eb12ddc2d85be2 b/test/fixtures/f70e148191e1ebbc95eb12ddc2d85be2 new file mode 100644 index 0000000000000000000000000000000000000000..b27d7980e84dd9d4f0013a475898e96bbd7ce7b4 GIT binary patch literal 519 zcmV+i0{HzOiwFP!000001D#UAj?*v@{gsu^9Vw0-$L%{U5^M3erMnLahsf1R`1wQ$FlGMzHlBFmECQw- zO%%ks$8n*R;PdZu+KF{eM=tv`Px+InwdaZ6F_N3#J(nIt!-K&-}t_)VoxFBZ&Ug??U6kd z@9(+)vbYE8Gnd!HE3#{49hw?JHw>zR?f@m$U|MgjH(HUB1tIZf;I=5qn>x%(yc!`d ztGD>R#9> 0) t.true(artist.collections.edges.length > 0) }) + +test('Releases support a list of media', testData, ` + { + lookup { + release(mbid: "a4864e94-6d75-4ade-bc93-0dabf3521453") { + media { + title + format + formatID + position + trackCount + } + } + } + } +`, (t, data) => { + const { release } = data.lookup + t.deepEqual(release.media, [ + { + title: 'Left', + format: 'CD', + formatID: '9712d52a-4509-3d4b-a1a2-67c88c643e31', + position: 1, + trackCount: 12 + }, + { + title: 'Right', + format: 'CD', + formatID: '9712d52a-4509-3d4b-a1a2-67c88c643e31', + position: 2, + trackCount: 11 + } + ]) +})