diff --git a/src/resolvers.js b/src/resolvers.js index e7fb6a7..a395ee4 100644 --- a/src/resolvers.js +++ b/src/resolvers.js @@ -122,10 +122,16 @@ export function searchResolver () { count: arrayLength } = list const meta = { sliceStart, arrayLength } - return { + const connection = { totalCount: arrayLength, ...connectionFromArraySlice(arraySlice, { first, after }, meta) } + // Move the `score` field up to the edge object and make sure it's a + // number (MusicBrainz returns a string). + connection.edges.forEach(edge => { + edge.score = parseInt(edge.node.score, 10) + }) + return connection }) } } @@ -164,14 +170,12 @@ export function linkedResolver () { } } -const noop = value => value - /** * If we weren't smart enough or weren't able to include the `inc` parameter * for a particular field that's being requested, make another request to grab * it (after making sure it isn't already available). */ -export function subqueryResolver (includeValue, handler = noop) { +export function subqueryResolver (includeValue, handler = value => value) { return (source, args, { loaders }, info) => { const key = toDashed(info.fieldName) if (key in source || (source._inc && source._inc.indexOf(key) !== -1)) { diff --git a/src/types/area.js b/src/types/area.js index b6d3e34..d38c314 100644 --- a/src/types/area.js +++ b/src/types/area.js @@ -15,7 +15,7 @@ import { releases, relationships, tags, - connectionWithCount + connectionWithExtras } from './helpers' const Area = new GraphQLObjectType({ @@ -46,5 +46,5 @@ the codes assigned by ISO to countries and subdivisions.`, }) }) -export const AreaConnection = connectionWithCount(Area) +export const AreaConnection = connectionWithExtras(Area) export default Area diff --git a/src/types/artist.js b/src/types/artist.js index ea0afcc..881e0f3 100644 --- a/src/types/artist.js +++ b/src/types/artist.js @@ -18,7 +18,7 @@ import { works, relationships, tags, - connectionWithCount + connectionWithExtras } from './helpers' const Artist = new GraphQLObjectType({ @@ -75,5 +75,5 @@ neither. Groups do not have genders.` }) }) -export const ArtistConnection = connectionWithCount(Artist) +export const ArtistConnection = connectionWithExtras(Artist) export default Artist diff --git a/src/types/event.js b/src/types/event.js index a8392c9..5e799f2 100644 --- a/src/types/event.js +++ b/src/types/event.js @@ -12,7 +12,7 @@ import { lifeSpan, relationships, tags, - connectionWithCount + connectionWithExtras } from './helpers' const Event = new GraphQLObjectType({ @@ -50,5 +50,5 @@ for syntax and examples.` }) }) -export const EventConnection = connectionWithCount(Event) +export const EventConnection = connectionWithExtras(Event) export default Event diff --git a/src/types/helpers.js b/src/types/helpers.js index d43ae99..5d0b9e1 100644 --- a/src/types/helpers.js +++ b/src/types/helpers.js @@ -231,9 +231,16 @@ export const totalCount = { ignoring pagination.` } -export function connectionWithCount (nodeType) { +export const score = { + type: GraphQLInt, + description: `The relevancy score (0–100) assigned by the search engine, if +these results were found through a search.` +} + +export function connectionWithExtras (nodeType) { return connectionDefinitions({ nodeType, - connectionFields: () => ({ totalCount }) + connectionFields: () => ({ totalCount }), + edgeFields: () => ({ score }) }).connectionType } diff --git a/src/types/instrument.js b/src/types/instrument.js index 711153c..20786ef 100644 --- a/src/types/instrument.js +++ b/src/types/instrument.js @@ -10,7 +10,7 @@ import { aliases, relationships, tags, - connectionWithCount + connectionWithExtras } from './helpers' const Instrument = new GraphQLObjectType({ @@ -40,5 +40,5 @@ classification.` }) }) -export const InstrumentConnection = connectionWithCount(Instrument) +export const InstrumentConnection = connectionWithExtras(Instrument) export default Instrument diff --git a/src/types/label.js b/src/types/label.js index b0a5a99..2b4c1c4 100644 --- a/src/types/label.js +++ b/src/types/label.js @@ -20,7 +20,7 @@ import { relationships, tags, fieldWithID, - connectionWithCount + connectionWithExtras } from './helpers' const Label = new GraphQLObjectType({ @@ -65,5 +65,5 @@ imprint, production, distributor, rights society, etc.` }) }) -export const LabelConnection = connectionWithCount(Label) +export const LabelConnection = connectionWithExtras(Label) export default Label diff --git a/src/types/place.js b/src/types/place.js index 1659f07..20447ac 100644 --- a/src/types/place.js +++ b/src/types/place.js @@ -14,7 +14,7 @@ import { fieldWithID, relationships, tags, - connectionWithCount + connectionWithExtras } from './helpers' export const Coordinates = new GraphQLObjectType({ @@ -68,5 +68,5 @@ function.` }) }) -export const PlaceConnection = connectionWithCount(Place) +export const PlaceConnection = connectionWithExtras(Place) export default Place diff --git a/src/types/recording.js b/src/types/recording.js index dc123ed..cf795a4 100644 --- a/src/types/recording.js +++ b/src/types/recording.js @@ -12,7 +12,7 @@ import { releases, relationships, tags, - connectionWithCount + connectionWithExtras } from './helpers' const Recording = new GraphQLObjectType({ @@ -53,5 +53,5 @@ from the lengths of the tracks using it.` }) }) -export const RecordingConnection = connectionWithCount(Recording) +export const RecordingConnection = connectionWithExtras(Recording) export default Recording diff --git a/src/types/relationship.js b/src/types/relationship.js index 8bb62b1..6cc25c8 100644 --- a/src/types/relationship.js +++ b/src/types/relationship.js @@ -10,7 +10,7 @@ import Entity from './entity' import { getHyphenated, fieldWithID, - connectionWithCount + connectionWithExtras } from './helpers' const Relationship = new GraphQLObjectType({ @@ -78,5 +78,5 @@ relationship type.` }) }) -export const RelationshipConnection = connectionWithCount(Relationship) +export const RelationshipConnection = connectionWithExtras(Relationship) export default Relationship diff --git a/src/types/release-group.js b/src/types/release-group.js index 0461eab..21459b5 100644 --- a/src/types/release-group.js +++ b/src/types/release-group.js @@ -16,7 +16,7 @@ import { tags, fieldWithID, getHyphenated, - connectionWithCount + connectionWithExtras } from './helpers' const ReleaseGroup = new GraphQLObjectType({ @@ -61,5 +61,5 @@ that apply to this release group.` }) }) -export const ReleaseGroupConnection = connectionWithCount(ReleaseGroup) +export const ReleaseGroupConnection = connectionWithExtras(ReleaseGroup) export default ReleaseGroup diff --git a/src/types/release.js b/src/types/release.js index 2b642a5..91e28f0 100644 --- a/src/types/release.js +++ b/src/types/release.js @@ -19,7 +19,7 @@ import { tags, fieldWithID, getHyphenated, - connectionWithCount + connectionWithExtras } from './helpers' const Release = new GraphQLObjectType({ @@ -83,5 +83,5 @@ It is not a mark of how good or bad the music itself is – for that, use }) }) -export const ReleaseConnection = connectionWithCount(Release) +export const ReleaseConnection = connectionWithExtras(Release) export default Release diff --git a/src/types/series.js b/src/types/series.js index 129a60f..d7062e0 100644 --- a/src/types/series.js +++ b/src/types/series.js @@ -9,7 +9,7 @@ import { relationships, tags, fieldWithID, - connectionWithCount + connectionWithExtras } from './helpers' const Series = new GraphQLObjectType({ @@ -32,5 +32,5 @@ contains.` }) }) -export const SeriesConnection = connectionWithCount(Series) +export const SeriesConnection = connectionWithExtras(Series) export default Series diff --git a/src/types/tag.js b/src/types/tag.js index b9f1117..975d08f 100644 --- a/src/types/tag.js +++ b/src/types/tag.js @@ -4,7 +4,7 @@ import { GraphQLString, GraphQLInt } from 'graphql/type' -import { connectionWithCount } from './helpers' +import { connectionWithExtras } from './helpers' const Tag = new GraphQLObjectType({ name: 'Tag', @@ -23,5 +23,5 @@ release, or recording.`, }) }) -export const TagConnection = connectionWithCount(Tag) +export const TagConnection = connectionWithExtras(Tag) export default Tag diff --git a/src/types/url.js b/src/types/url.js index ce17152..dc00530 100644 --- a/src/types/url.js +++ b/src/types/url.js @@ -2,7 +2,7 @@ import { GraphQLObjectType, GraphQLNonNull } from 'graphql/type' import Node from './node' import Entity from './entity' import { URLString } from './scalars' -import { id, mbid, relationships, connectionWithCount } from './helpers' +import { id, mbid, relationships, connectionWithExtras } from './helpers' const URL = new GraphQLObjectType({ name: 'URL', @@ -21,5 +21,5 @@ acquired, an entry in another database, etc.`, }) }) -export const URLConnection = connectionWithCount(URL) +export const URLConnection = connectionWithExtras(URL) export default URL diff --git a/src/types/work.js b/src/types/work.js index 9cf5ba6..7c5c211 100644 --- a/src/types/work.js +++ b/src/types/work.js @@ -11,7 +11,7 @@ import { relationships, tags, fieldWithID, - connectionWithCount + connectionWithExtras } from './helpers' const Work = new GraphQLObjectType({ @@ -44,5 +44,5 @@ to the work by copyright collecting agencies.` }) }) -export const WorkConnection = connectionWithCount(Work) +export const WorkConnection = connectionWithExtras(Work) export default Work