@@ -47,6 +47,8 @@ import graphql.schema.idl.ScalarInfo
47
47
import graphql.schema.idl.SchemaGeneratorHelper
48
48
import java.util.*
49
49
import kotlin.reflect.KClass
50
+ import kotlin.reflect.full.memberProperties
51
+ import kotlin.reflect.jvm.isAccessible
50
52
51
53
/* *
52
54
* Parses a GraphQL Schema and maps object fields to provided class methods.
@@ -105,9 +107,16 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
105
107
val inputObjects = inputObjectDefinitions.map { createInputObject(it) }
106
108
val enums = enumDefinitions.map { createEnumObject(it) }
107
109
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
+
108
117
// 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) }
111
120
112
121
// Find query type and mutation/subscription type (if mutation/subscription type exists)
113
122
val queryName = rootInfo.getQueryName()
@@ -159,7 +168,7 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
159
168
val wiredField = directiveGenerator.onField(field.build(), DirectiveBehavior .Params (runtimeWiring))
160
169
GraphQLFieldDefinition .Builder (wiredField)
161
170
.clearArguments()
162
- .argument (wiredField.arguments)
171
+ .arguments (wiredField.arguments)
163
172
}
164
173
}
165
174
@@ -219,11 +228,17 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
219
228
val enumName = enumDefinition.name
220
229
val enumValue = type.unwrap().enumConstants.find { (it as Enum <* >).name == enumName }
221
230
? : 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 )
223
232
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
+
227
242
builder.value(directiveGenerator.onEnumValue(enumValueDefinition, DirectiveBehavior .Params (runtimeWiring)))
228
243
}
229
244
}
0 commit comments