graphbrainz/src/queries/browse.js

147 lines
3.6 KiB
JavaScript
Raw Permalink Normal View History

2016-09-01 08:39:27 +00:00
import { GraphQLObjectType } from 'graphql'
import { forwardConnectionArgs } from 'graphql-relay'
import { browseResolver } from '../resolvers'
2016-08-20 05:59:32 +00:00
import {
MBID,
URLString,
AreaConnection,
2016-09-01 04:31:48 +00:00
ArtistConnection,
EventConnection,
LabelConnection,
PlaceConnection,
RecordingConnection,
ReleaseConnection,
ReleaseGroupConnection,
URLConnection,
WorkConnection
2016-08-20 05:59:32 +00:00
} from '../types'
2016-11-26 01:38:32 +00:00
import { toWords } from '../types/helpers'
const area = {
type: MBID,
description: 'The MBID of an area to which the entity is linked.'
}
const artist = {
type: MBID,
description: 'The MBID of an artist to which the entity is linked.'
}
const collection = {
type: MBID,
description: 'The MBID of a collection in which the entity is found.'
}
2016-11-26 01:38:32 +00:00
const recording = {
type: MBID,
description: 'The MBID of a recording to which the entity is linked.'
}
const release = {
type: MBID,
description: 'The MBID of a release to which the entity is linked.'
}
const releaseGroup = {
type: MBID,
description: 'The MBID of a release group to which the entity is linked.'
}
2016-09-01 08:39:27 +00:00
function browseQuery (connectionType, args) {
2016-11-26 01:38:32 +00:00
const typeName = toWords(connectionType.name.slice(0, -10))
2016-09-01 08:39:27 +00:00
return {
type: connectionType,
2016-11-26 01:38:32 +00:00
description: `Browse ${typeName} entities linked to the given arguments.`,
2016-09-01 08:39:27 +00:00
args: {
...forwardConnectionArgs,
...args
},
resolve: browseResolver()
}
}
2016-08-20 05:59:32 +00:00
export const BrowseQuery = new GraphQLObjectType({
2016-08-20 05:59:32 +00:00
name: 'BrowseQuery',
2016-11-26 01:38:32 +00:00
description: `A query for all MusicBrainz entities directly linked to another
entity.`,
2016-08-20 05:59:32 +00:00
fields: {
areas: browseQuery(AreaConnection, {
collection
}),
2016-09-01 08:39:27 +00:00
artists: browseQuery(ArtistConnection, {
2016-11-26 01:38:32 +00:00
area,
collection,
2016-11-26 01:38:32 +00:00
recording,
release,
releaseGroup,
work: {
type: MBID,
description: 'The MBID of a work to which the artist is linked.'
}
2016-09-01 08:39:27 +00:00
}),
events: browseQuery(EventConnection, {
2016-11-26 01:38:32 +00:00
area,
artist,
collection,
2016-11-26 01:38:32 +00:00
place: {
type: MBID,
description: 'The MBID of a place to which the event is linked.'
}
2016-09-01 08:39:27 +00:00
}),
labels: browseQuery(LabelConnection, {
2016-11-26 01:38:32 +00:00
area,
collection,
2016-11-26 01:38:32 +00:00
release
2016-09-01 08:39:27 +00:00
}),
places: browseQuery(PlaceConnection, {
area,
collection
2016-09-01 08:39:27 +00:00
}),
recordings: browseQuery(RecordingConnection, {
2016-11-26 01:38:32 +00:00
artist,
collection,
2016-11-26 01:38:32 +00:00
release
2016-09-01 08:39:27 +00:00
}),
releases: browseQuery(ReleaseConnection, {
2016-11-26 01:38:32 +00:00
area,
artist,
collection,
2016-11-26 01:38:32 +00:00
label: {
type: MBID,
description: 'The MBID of a label to which the release is linked.'
},
track: {
type: MBID,
description: 'The MBID of a track that is included in the release.'
},
trackArtist: {
type: MBID,
description: `The MBID of an artist that appears on a track in the
release, but is not included in the credits for the release itself.`
},
recording,
releaseGroup
2016-09-01 08:39:27 +00:00
}),
releaseGroups: browseQuery(ReleaseGroupConnection, {
2016-11-26 01:38:32 +00:00
artist,
collection,
2016-11-26 01:38:32 +00:00
release
2016-09-01 08:39:27 +00:00
}),
works: browseQuery(WorkConnection, {
artist,
collection
2016-09-01 08:39:27 +00:00
}),
urls: browseQuery(URLConnection, {
2016-11-26 01:38:32 +00:00
resource: {
type: URLString,
description: 'The web address for which to browse URL entities.'
}
2016-09-01 08:39:27 +00:00
})
2016-08-20 05:59:32 +00:00
}
})
export const browseField = {
type: BrowseQuery,
description: 'Browse all MusicBrainz entities directly linked to another entity.',
// We only have work to do once we know what entity types are being requested,
// so this can just resolve to an empty object.
resolve: () => ({})
}
export default BrowseQuery