2016-09-01 08:39:27 +00:00
|
|
|
import { GraphQLObjectType, GraphQLNonNull, GraphQLString } from 'graphql'
|
|
|
|
|
import { forwardConnectionArgs } from 'graphql-relay'
|
|
|
|
|
import { searchResolver } from '../resolvers'
|
2016-08-20 05:59:32 +00:00
|
|
|
import {
|
2016-09-01 04:31:48 +00:00
|
|
|
AreaConnection,
|
|
|
|
|
ArtistConnection,
|
2016-11-28 13:49:04 +00:00
|
|
|
EventConnection,
|
|
|
|
|
InstrumentConnection,
|
2016-09-01 04:31:48 +00:00
|
|
|
LabelConnection,
|
|
|
|
|
PlaceConnection,
|
|
|
|
|
RecordingConnection,
|
|
|
|
|
ReleaseConnection,
|
|
|
|
|
ReleaseGroupConnection,
|
2016-11-28 13:49:04 +00:00
|
|
|
SeriesConnection,
|
2016-09-01 04:31:48 +00:00
|
|
|
WorkConnection
|
2016-08-20 05:59:32 +00:00
|
|
|
} from '../types'
|
2016-11-26 01:38:32 +00:00
|
|
|
import { toWords } from '../types/helpers'
|
2016-09-01 08:39:27 +00:00
|
|
|
|
|
|
|
|
function searchQuery (connectionType) {
|
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: `Search for ${typeName} entities matching the given query.`,
|
2016-09-01 08:39:27 +00:00
|
|
|
args: {
|
2016-11-28 13:49:04 +00:00
|
|
|
query: {
|
|
|
|
|
type: new GraphQLNonNull(GraphQLString),
|
|
|
|
|
description: `The query terms, in Lucene search syntax. See [examples
|
|
|
|
|
and search fields](https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2/Search).`
|
|
|
|
|
},
|
2016-09-01 08:39:27 +00:00
|
|
|
...forwardConnectionArgs
|
|
|
|
|
},
|
|
|
|
|
resolve: searchResolver()
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-20 05:59:32 +00:00
|
|
|
|
2016-11-27 03:19:18 +00:00
|
|
|
export const SearchQuery = new GraphQLObjectType({
|
2016-08-20 05:59:32 +00:00
|
|
|
name: 'SearchQuery',
|
2016-11-26 01:38:32 +00:00
|
|
|
description: 'A search for MusicBrainz entities using Lucene query syntax.',
|
2016-08-20 05:59:32 +00:00
|
|
|
fields: {
|
2016-09-01 04:31:48 +00:00
|
|
|
areas: searchQuery(AreaConnection),
|
|
|
|
|
artists: searchQuery(ArtistConnection),
|
2016-11-28 13:49:04 +00:00
|
|
|
events: searchQuery(EventConnection),
|
|
|
|
|
instruments: searchQuery(InstrumentConnection),
|
2016-09-01 04:31:48 +00:00
|
|
|
labels: searchQuery(LabelConnection),
|
|
|
|
|
places: searchQuery(PlaceConnection),
|
|
|
|
|
recordings: searchQuery(RecordingConnection),
|
|
|
|
|
releases: searchQuery(ReleaseConnection),
|
|
|
|
|
releaseGroups: searchQuery(ReleaseGroupConnection),
|
2016-11-28 13:49:04 +00:00
|
|
|
series: searchQuery(SeriesConnection),
|
2016-09-01 04:31:48 +00:00
|
|
|
works: searchQuery(WorkConnection)
|
2016-08-20 05:59:32 +00:00
|
|
|
}
|
|
|
|
|
})
|
2016-11-27 03:19:18 +00:00
|
|
|
|
|
|
|
|
export const searchField = {
|
|
|
|
|
type: SearchQuery,
|
|
|
|
|
description: 'Search for MusicBrainz entities using Lucene query syntax.',
|
|
|
|
|
// 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 SearchQuery
|