2021-04-16 04:34:29 +00:00
|
|
|
import GraphQL from 'graphql';
|
|
|
|
|
import GraphQLRelay from 'graphql-relay';
|
|
|
|
|
import { resolveSearch } from '../resolvers.js';
|
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,
|
2021-04-16 04:34:29 +00:00
|
|
|
WorkConnection,
|
|
|
|
|
} from '../types/index.js';
|
|
|
|
|
import { toWords } from '../util.js';
|
|
|
|
|
|
|
|
|
|
const { GraphQLObjectType, GraphQLNonNull, GraphQLString } = GraphQL;
|
|
|
|
|
const { forwardConnectionArgs } = GraphQLRelay;
|
2016-09-01 08:39:27 +00:00
|
|
|
|
2017-11-07 05:54:56 +00:00
|
|
|
function createSearchField(connectionType) {
|
2021-04-16 04:34:29 +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
|
2021-04-16 04:34:29 +00:00
|
|
|
and search fields](https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2/Search).`,
|
2016-11-28 13:49:04 +00:00
|
|
|
},
|
2021-04-16 04:34:29 +00:00
|
|
|
...forwardConnectionArgs,
|
2016-09-01 08:39:27 +00:00
|
|
|
},
|
2021-04-16 04:34:29 +00:00
|
|
|
resolve: resolveSearch,
|
|
|
|
|
};
|
2016-09-01 08:39:27 +00:00
|
|
|
}
|
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-12-02 08:21:10 +00:00
|
|
|
areas: createSearchField(AreaConnection),
|
|
|
|
|
artists: createSearchField(ArtistConnection),
|
|
|
|
|
events: createSearchField(EventConnection),
|
|
|
|
|
instruments: createSearchField(InstrumentConnection),
|
|
|
|
|
labels: createSearchField(LabelConnection),
|
|
|
|
|
places: createSearchField(PlaceConnection),
|
|
|
|
|
recordings: createSearchField(RecordingConnection),
|
|
|
|
|
releases: createSearchField(ReleaseConnection),
|
|
|
|
|
releaseGroups: createSearchField(ReleaseGroupConnection),
|
|
|
|
|
series: createSearchField(SeriesConnection),
|
2021-04-16 04:34:29 +00:00
|
|
|
works: createSearchField(WorkConnection),
|
|
|
|
|
},
|
|
|
|
|
});
|
2016-11-27 03:19:18 +00:00
|
|
|
|
2016-12-02 08:21:10 +00:00
|
|
|
export const search = {
|
2016-11-27 03:19:18 +00:00
|
|
|
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.
|
2021-04-16 04:34:29 +00:00
|
|
|
resolve: () => ({}),
|
|
|
|
|
};
|
2016-11-27 03:19:18 +00:00
|
|
|
|
2021-04-16 04:34:29 +00:00
|
|
|
export default SearchQuery;
|