@@ -13,8 +13,7 @@ import graphql.schema.TypeResolver
1313 * @author Andrew Potter
1414 */
1515internal abstract class DictionaryTypeResolver (
16- private val dictionary : BiMap <JavaType , TypeDefinition <* >>,
17- private val types : Map <String , GraphQLObjectType >
16+ private val dictionary : BiMap <JavaType , TypeDefinition <* >>
1817) : TypeResolver {
1918 private fun <T > getTypeDefinition (clazz : Class <T >): TypeDefinition <* >? {
2019 return dictionary[clazz]
@@ -25,30 +24,26 @@ internal abstract class DictionaryTypeResolver(
2524 override fun getType (env : TypeResolutionEnvironment ): GraphQLObjectType ? {
2625 val clazz = env.getObject<Any >().javaClass
2726 val name = getTypeDefinition(clazz)?.name ? : clazz.simpleName
28- return types[ name] ? : throw TypeResolverError (getError(name))
27+ return env.schema.getObjectType( name) ? : throw TypeResolverError (getError(name))
2928 }
3029
3130 abstract fun getError (name : String ): String
3231}
3332
3433internal class InterfaceTypeResolver (
3534 dictionary : BiMap <JavaType , TypeDefinition <* >>,
36- private val thisInterface : GraphQLInterfaceType ,
37- types : List <GraphQLObjectType >
35+ private val thisInterface : GraphQLInterfaceType
3836) : DictionaryTypeResolver(
39- dictionary,
40- types.filter { type -> type.interfaces.any { it.name == thisInterface.name } }.associateBy { it.name }
37+ dictionary
4138) {
4239 override fun getError (name : String ) = " Expected object type with name '$name ' to implement interface '${thisInterface.name} ', but it doesn't!"
4340}
4441
4542internal class UnionTypeResolver (
4643 dictionary : BiMap <JavaType , TypeDefinition <* >>,
47- private val thisUnion : GraphQLUnionType ,
48- types : List <GraphQLObjectType >
44+ private val thisUnion : GraphQLUnionType
4945) : DictionaryTypeResolver(
50- dictionary,
51- types.filter { type -> thisUnion.types.any { it.name == type.name } }.associateBy { it.name }
46+ dictionary
5247) {
5348 override fun getError (name : String ) = " Expected object type with name '$name ' to exist for union '${thisUnion.name} ', but it doesn't!"
5449}
0 commit comments