Skip to content

DictionaryResolverType should use return GraphQLObjectType from Schema rather than cached map #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unused types property in DictionaryTypeResolver.
  • Loading branch information
timward60 committed Oct 8, 2021
commit bc1a536e70a0dc6b385841205cc35a8597f13f67
15 changes: 5 additions & 10 deletions src/main/kotlin/graphql/kickstart/tools/DictionaryTypeResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import graphql.schema.TypeResolver
* @author Andrew Potter
*/
internal abstract class DictionaryTypeResolver(
private val dictionary: BiMap<JavaType, TypeDefinition<*>>,
private val types: Map<String, GraphQLObjectType>
private val dictionary: BiMap<JavaType, TypeDefinition<*>>
) : TypeResolver {
private fun <T> getTypeDefinition(clazz: Class<T>): TypeDefinition<*>? {
return dictionary[clazz]
Expand All @@ -33,22 +32,18 @@ internal abstract class DictionaryTypeResolver(

internal class InterfaceTypeResolver(
dictionary: BiMap<JavaType, TypeDefinition<*>>,
private val thisInterface: GraphQLInterfaceType,
types: List<GraphQLObjectType>
private val thisInterface: GraphQLInterfaceType
) : DictionaryTypeResolver(
dictionary,
types.filter { type -> type.interfaces.any { it.name == thisInterface.name } }.associateBy { it.name }
dictionary
) {
override fun getError(name: String) = "Expected object type with name '$name' to implement interface '${thisInterface.name}', but it doesn't!"
}

internal class UnionTypeResolver(
dictionary: BiMap<JavaType, TypeDefinition<*>>,
private val thisUnion: GraphQLUnionType,
types: List<GraphQLObjectType>
private val thisUnion: GraphQLUnionType
) : DictionaryTypeResolver(
dictionary,
types.filter { type -> thisUnion.types.any { it.name == type.name } }.associateBy { it.name }
dictionary
) {
override fun getError(name: String) = "Expected object type with name '$name' to exist for union '${thisUnion.name}', but it doesn't!"
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class SchemaParser internal constructor(
val enums = enumDefinitions.map { createEnumObject(it) }

// Assign type resolver to interfaces now that we know all of the object types
interfaces.forEach { codeRegistryBuilder.typeResolver(it, InterfaceTypeResolver(dictionary.inverse(), it, objects)) }
unions.forEach { codeRegistryBuilder.typeResolver(it, UnionTypeResolver(dictionary.inverse(), it, objects)) }
interfaces.forEach { codeRegistryBuilder.typeResolver(it, InterfaceTypeResolver(dictionary.inverse(), it)) }
unions.forEach { codeRegistryBuilder.typeResolver(it, UnionTypeResolver(dictionary.inverse(), it)) }

// Find query type and mutation/subscription type (if mutation/subscription type exists)
val queryName = rootInfo.getQueryName()
Expand Down