graphbrainz/src/types/entity.js

27 lines
814 B
JavaScript
Raw Normal View History

2016-08-31 06:33:29 +00:00
import { GraphQLInterfaceType } from 'graphql'
import { mbid, connectionWithExtras } from './helpers'
2016-08-08 07:54:06 +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.',
resolveType(value, context, info) {
if (value._type) {
const typeMap = info.schema.getTypeMap()
let originalType
try {
originalType = require(`./${value._type}`).default
} catch (err) {
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.
return typeMap[originalType.name]
2016-08-20 05:59:32 +00:00
}
},
fields: () => ({ mbid })
2016-08-08 07:54:06 +00:00
})
export const EntityConnection = connectionWithExtras(Entity)
export default Entity