mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
Add search score field to edges
This commit is contained in:
parent
618ac1b3e1
commit
531ed4e9b8
16 changed files with 45 additions and 34 deletions
|
|
@ -122,10 +122,16 @@ export function searchResolver () {
|
||||||
count: arrayLength
|
count: arrayLength
|
||||||
} = list
|
} = list
|
||||||
const meta = { sliceStart, arrayLength }
|
const meta = { sliceStart, arrayLength }
|
||||||
return {
|
const connection = {
|
||||||
totalCount: arrayLength,
|
totalCount: arrayLength,
|
||||||
...connectionFromArraySlice(arraySlice, { first, after }, meta)
|
...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
|
* 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
|
* for a particular field that's being requested, make another request to grab
|
||||||
* it (after making sure it isn't already available).
|
* 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) => {
|
return (source, args, { loaders }, info) => {
|
||||||
const key = toDashed(info.fieldName)
|
const key = toDashed(info.fieldName)
|
||||||
if (key in source || (source._inc && source._inc.indexOf(key) !== -1)) {
|
if (key in source || (source._inc && source._inc.indexOf(key) !== -1)) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import {
|
||||||
releases,
|
releases,
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Area = new GraphQLObjectType({
|
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
|
export default Area
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import {
|
||||||
works,
|
works,
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Artist = new GraphQLObjectType({
|
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
|
export default Artist
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
lifeSpan,
|
lifeSpan,
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Event = new GraphQLObjectType({
|
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
|
export default Event
|
||||||
|
|
|
||||||
|
|
@ -231,9 +231,16 @@ export const totalCount = {
|
||||||
ignoring pagination.`
|
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({
|
return connectionDefinitions({
|
||||||
nodeType,
|
nodeType,
|
||||||
connectionFields: () => ({ totalCount })
|
connectionFields: () => ({ totalCount }),
|
||||||
|
edgeFields: () => ({ score })
|
||||||
}).connectionType
|
}).connectionType
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
aliases,
|
aliases,
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Instrument = new GraphQLObjectType({
|
const Instrument = new GraphQLObjectType({
|
||||||
|
|
@ -40,5 +40,5 @@ classification.`
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export const InstrumentConnection = connectionWithCount(Instrument)
|
export const InstrumentConnection = connectionWithExtras(Instrument)
|
||||||
export default Instrument
|
export default Instrument
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import {
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
fieldWithID,
|
fieldWithID,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Label = new GraphQLObjectType({
|
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
|
export default Label
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import {
|
||||||
fieldWithID,
|
fieldWithID,
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
export const Coordinates = new GraphQLObjectType({
|
export const Coordinates = new GraphQLObjectType({
|
||||||
|
|
@ -68,5 +68,5 @@ function.`
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export const PlaceConnection = connectionWithCount(Place)
|
export const PlaceConnection = connectionWithExtras(Place)
|
||||||
export default Place
|
export default Place
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
releases,
|
releases,
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Recording = new GraphQLObjectType({
|
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
|
export default Recording
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import Entity from './entity'
|
||||||
import {
|
import {
|
||||||
getHyphenated,
|
getHyphenated,
|
||||||
fieldWithID,
|
fieldWithID,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Relationship = new GraphQLObjectType({
|
const Relationship = new GraphQLObjectType({
|
||||||
|
|
@ -78,5 +78,5 @@ relationship type.`
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export const RelationshipConnection = connectionWithCount(Relationship)
|
export const RelationshipConnection = connectionWithExtras(Relationship)
|
||||||
export default Relationship
|
export default Relationship
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import {
|
||||||
tags,
|
tags,
|
||||||
fieldWithID,
|
fieldWithID,
|
||||||
getHyphenated,
|
getHyphenated,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const ReleaseGroup = new GraphQLObjectType({
|
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
|
export default ReleaseGroup
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import {
|
||||||
tags,
|
tags,
|
||||||
fieldWithID,
|
fieldWithID,
|
||||||
getHyphenated,
|
getHyphenated,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Release = new GraphQLObjectType({
|
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
|
export default Release
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import {
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
fieldWithID,
|
fieldWithID,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Series = new GraphQLObjectType({
|
const Series = new GraphQLObjectType({
|
||||||
|
|
@ -32,5 +32,5 @@ contains.`
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export const SeriesConnection = connectionWithCount(Series)
|
export const SeriesConnection = connectionWithExtras(Series)
|
||||||
export default Series
|
export default Series
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import {
|
||||||
GraphQLString,
|
GraphQLString,
|
||||||
GraphQLInt
|
GraphQLInt
|
||||||
} from 'graphql/type'
|
} from 'graphql/type'
|
||||||
import { connectionWithCount } from './helpers'
|
import { connectionWithExtras } from './helpers'
|
||||||
|
|
||||||
const Tag = new GraphQLObjectType({
|
const Tag = new GraphQLObjectType({
|
||||||
name: 'Tag',
|
name: 'Tag',
|
||||||
|
|
@ -23,5 +23,5 @@ release, or recording.`,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export const TagConnection = connectionWithCount(Tag)
|
export const TagConnection = connectionWithExtras(Tag)
|
||||||
export default Tag
|
export default Tag
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { GraphQLObjectType, GraphQLNonNull } from 'graphql/type'
|
||||||
import Node from './node'
|
import Node from './node'
|
||||||
import Entity from './entity'
|
import Entity from './entity'
|
||||||
import { URLString } from './scalars'
|
import { URLString } from './scalars'
|
||||||
import { id, mbid, relationships, connectionWithCount } from './helpers'
|
import { id, mbid, relationships, connectionWithExtras } from './helpers'
|
||||||
|
|
||||||
const URL = new GraphQLObjectType({
|
const URL = new GraphQLObjectType({
|
||||||
name: 'URL',
|
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
|
export default URL
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
relationships,
|
relationships,
|
||||||
tags,
|
tags,
|
||||||
fieldWithID,
|
fieldWithID,
|
||||||
connectionWithCount
|
connectionWithExtras
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const Work = new GraphQLObjectType({
|
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
|
export default Work
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue