mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
* Add Disc type, lookup, and discs field on Media * Remove query optimization so search subqueries work
28 lines
705 B
JavaScript
28 lines
705 B
JavaScript
import { nodeDefinitions, fromGlobalId } from 'graphql-relay'
|
|
import { toDashed } from './helpers'
|
|
|
|
const debug = require('debug')('graphbrainz:types/node')
|
|
|
|
const TYPE_MODULES = {
|
|
discid: 'disc'
|
|
}
|
|
|
|
const { nodeInterface, nodeField } = nodeDefinitions(
|
|
(globalID, { loaders }) => {
|
|
const { type, id } = fromGlobalId(globalID)
|
|
const entityType = toDashed(type)
|
|
return loaders.lookup.load([entityType, id])
|
|
},
|
|
(obj) => {
|
|
const type = TYPE_MODULES[obj._type] || obj._type
|
|
try {
|
|
return require(`./${type}`).default
|
|
} catch (err) {
|
|
debug(`Failed to load type: ${type}`)
|
|
return null
|
|
}
|
|
}
|
|
)
|
|
|
|
export default nodeInterface
|
|
export { nodeInterface, nodeField }
|