From 2de2e600794eb0ad361bb25b327d4ef01d836206 Mon Sep 17 00:00:00 2001 From: Brian Beck Date: Fri, 17 Nov 2017 22:34:46 -0800 Subject: [PATCH] Fix resolveType after the schema has been extended (#50) --- src/types/entity.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/types/entity.js b/src/types/entity.js index e871bc6..7e1dabd 100644 --- a/src/types/entity.js +++ b/src/types/entity.js @@ -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 })