mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
Fix resolveType after the schema has been extended (#50)
This commit is contained in:
parent
ccce751ccb
commit
2de2e60079
1 changed files with 13 additions and 3 deletions
|
|
@ -4,9 +4,19 @@ import { mbid, connectionWithExtras } from './helpers'
|
|||
const Entity = new GraphQLInterfaceType({
|
||||
name: 'Entity',
|
||||
description: 'An entity in the MusicBrainz schema.',
|
||||
resolveType(value) {
|
||||
if (value._type && require.resolve(`./${value._type}`)) {
|
||||
return require(`./${value._type}`).default
|
||||
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]
|
||||
}
|
||||
},
|
||||
fields: () => ({ mbid })
|
||||
|
|
|
|||
Loading…
Reference in a new issue