@@ -47,6 +47,8 @@ import graphql.schema.idl.ScalarInfo
4747import graphql.schema.idl.SchemaGeneratorHelper
4848import java.util.*
4949import kotlin.reflect.KClass
50+ import kotlin.reflect.full.memberProperties
51+ import kotlin.reflect.jvm.isAccessible
5052
5153/* *
5254 * Parses a GraphQL Schema and maps object fields to provided class methods.
@@ -105,9 +107,16 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
105107 val inputObjects = inputObjectDefinitions.map { createInputObject(it) }
106108 val enums = enumDefinitions.map { createEnumObject(it) }
107109
110+ // Unfortunately, since graphql-java 12, the getTypeResolver method has been made package-protected,
111+ // so we need reflection to access the 'typeResolver' field on GraphQLInterfaceType and GraphQLUnionType
112+ val interfaceTypeResolverField = GraphQLInterfaceType ::class .memberProperties.find { it.name == " typeResolver" }
113+ interfaceTypeResolverField!! .isAccessible = true
114+ val unionTypeResolverField = GraphQLUnionType ::class .memberProperties.find { it.name == " typeResolver" }
115+ unionTypeResolverField!! .isAccessible = true
116+
108117 // Assign type resolver to interfaces now that we know all of the object types
109- interfaces.forEach { (it.typeResolver as TypeResolverProxy ).typeResolver = InterfaceTypeResolver (dictionary.inverse(), it, objects) }
110- unions.forEach { (it.typeResolver as TypeResolverProxy ).typeResolver = UnionTypeResolver (dictionary.inverse(), it, objects) }
118+ interfaces.forEach { (interfaceTypeResolverField.get(it) as TypeResolverProxy ).typeResolver = InterfaceTypeResolver (dictionary.inverse(), it, objects) }
119+ unions.forEach { (unionTypeResolverField.get(it) as TypeResolverProxy ).typeResolver = UnionTypeResolver (dictionary.inverse(), it, objects) }
111120
112121 // Find query type and mutation/subscription type (if mutation/subscription type exists)
113122 val queryName = rootInfo.getQueryName()
@@ -159,7 +168,7 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
159168 val wiredField = directiveGenerator.onField(field.build(), DirectiveBehavior .Params (runtimeWiring))
160169 GraphQLFieldDefinition .Builder (wiredField)
161170 .clearArguments()
162- .argument (wiredField.arguments)
171+ .arguments (wiredField.arguments)
163172 }
164173 }
165174
@@ -219,11 +228,17 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
219228 val enumName = enumDefinition.name
220229 val enumValue = type.unwrap().enumConstants.find { (it as Enum <* >).name == enumName }
221230 ? : throw SchemaError (" Expected value for name '$enumName ' in enum '${type.unwrap().simpleName} ' but found none!" )
222- val enumValueDirectives = buildDirectives(enumDefinition.directives, setOf (), Introspection .DirectiveLocation .ENUM_VALUE ).toMutableList()
231+ val enumValueDirectives = buildDirectives(enumDefinition.directives, setOf (), Introspection .DirectiveLocation .ENUM_VALUE )
223232 getDeprecated(enumDefinition.directives).let {
224- val enumValueDefinition = GraphQLEnumValueDefinition (enumName,
225- if (enumDefinition.description != null ) enumDefinition.description.content else getDocumentation(enumDefinition),
226- enumValue, it, enumValueDirectives)
233+ val enumValueDefinition = GraphQLEnumValueDefinition .newEnumValueDefinition()
234+ .name(enumName)
235+ .description(if (enumDefinition.description != null ) enumDefinition.description.content else getDocumentation(enumDefinition))
236+ .value(enumValue)
237+ .deprecationReason(it)
238+ .withDirectives(* enumValueDirectives)
239+ .definition(enumDefinition)
240+ .build()
241+
227242 builder.value(directiveGenerator.onEnumValue(enumValueDefinition, DirectiveBehavior .Params (runtimeWiring)))
228243 }
229244 }
0 commit comments