mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
* More resolveType fixes, this time for Relay's nodeDefinitions * Add a loadExtension helper * Use createContext in test helpers
29 lines
927 B
JavaScript
29 lines
927 B
JavaScript
import { GraphQLInterfaceType } from 'graphql'
|
|
import { mbid, connectionWithExtras } from './helpers'
|
|
|
|
const debug = require('debug')('graphbrainz:types/entity')
|
|
|
|
const Entity = new GraphQLInterfaceType({
|
|
name: 'Entity',
|
|
description: 'An entity in the MusicBrainz schema.',
|
|
resolveType(value, context, info) {
|
|
if (value._type) {
|
|
let originalType
|
|
try {
|
|
originalType = require(`./${value._type}`).default
|
|
} catch (err) {
|
|
debug(`Failed to load type: ${value._type}`)
|
|
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.
|
|
const typeMap = info.schema.getTypeMap()
|
|
return typeMap[originalType.name]
|
|
}
|
|
},
|
|
fields: () => ({ mbid })
|
|
})
|
|
|
|
export const EntityConnection = connectionWithExtras(Entity)
|
|
export default Entity
|