2016-08-31 06:33:29 +00:00
|
|
|
import { GraphQLInterfaceType } from 'graphql'
|
2016-12-02 08:21:10 +00:00
|
|
|
import { mbid, connectionWithExtras } from './helpers'
|
2016-08-08 07:54:06 +00:00
|
|
|
|
2017-11-18 08:35:28 +00:00
|
|
|
const debug = require('debug')('graphbrainz:types/entity')
|
|
|
|
|
|
2016-12-02 08:21:10 +00:00
|
|
|
const Entity = new GraphQLInterfaceType({
|
2016-08-08 07:54:06 +00:00
|
|
|
name: 'Entity',
|
2016-08-20 05:59:32 +00:00
|
|
|
description: 'An entity in the MusicBrainz schema.',
|
2017-11-18 06:34:46 +00:00
|
|
|
resolveType(value, context, info) {
|
|
|
|
|
if (value._type) {
|
|
|
|
|
let originalType
|
|
|
|
|
try {
|
|
|
|
|
originalType = require(`./${value._type}`).default
|
|
|
|
|
} catch (err) {
|
2017-11-18 08:35:28 +00:00
|
|
|
debug(`Failed to load type: ${value._type}`)
|
2017-11-18 06:34:46 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// Don't use `originalType`! The schema may have been extended in which
|
|
|
|
|
// case the types have all been replaced. Instead, find the current type
|
|
|
|
|
// of the same name.
|
2017-11-18 08:35:28 +00:00
|
|
|
const typeMap = info.schema.getTypeMap()
|
2017-11-18 06:34:46 +00:00
|
|
|
return typeMap[originalType.name]
|
2016-08-20 05:59:32 +00:00
|
|
|
}
|
|
|
|
|
},
|
2016-11-28 13:49:04 +00:00
|
|
|
fields: () => ({ mbid })
|
2016-08-08 07:54:06 +00:00
|
|
|
})
|
2016-12-02 08:21:10 +00:00
|
|
|
|
|
|
|
|
export const EntityConnection = connectionWithExtras(Entity)
|
|
|
|
|
export default Entity
|