Fix resolveType after the schema has been extended (#50)

This commit is contained in:
Brian Beck 2017-11-17 22:34:46 -08:00 committed by GitHub
parent ccce751ccb
commit 2de2e60079
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,9 +4,19 @@ import { mbid, connectionWithExtras } from './helpers'
const Entity = new GraphQLInterfaceType({ const Entity = new GraphQLInterfaceType({
name: 'Entity', name: 'Entity',
description: 'An entity in the MusicBrainz schema.', description: 'An entity in the MusicBrainz schema.',
resolveType(value) { resolveType(value, context, info) {
if (value._type && require.resolve(`./${value._type}`)) { if (value._type) {
return require(`./${value._type}`).default 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 }) fields: () => ({ mbid })