graphbrainz/src/types/node.js
Brian Beck 780596480a Add Disc type, lookup, and discs field on Media (#16)
* Add Disc type, lookup, and discs field on Media
* Remove query optimization so search subqueries work
2016-12-13 21:18:33 -08:00

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 }