@@ -7,15 +7,19 @@ import com.expedia.graphql.schema.SchemaGeneratorConfig
77import com.expedia.graphql.schema.exceptions.InvalidInputFieldTypeException
88import com.expedia.graphql.schema.extensions.directives
99import com.expedia.graphql.schema.extensions.getDeprecationReason
10+ import com.expedia.graphql.schema.extensions.getValidFunctions
11+ import com.expedia.graphql.schema.extensions.getValidProperties
1012import com.expedia.graphql.schema.extensions.graphQLDescription
1113import com.expedia.graphql.schema.extensions.isGraphQLContext
1214import com.expedia.graphql.schema.extensions.wrapInNonNull
15+ import com.expedia.graphql.schema.generator.types.defaultGraphQLScalars
16+ import com.expedia.graphql.schema.generator.types.enumType
17+ import com.expedia.graphql.schema.generator.types.getInputClassName
1318import com.expedia.graphql.schema.models.KGraphQLType
1419import graphql.TypeResolutionEnvironment
1520import graphql.schema.DataFetcher
1621import graphql.schema.GraphQLArgument
1722import graphql.schema.GraphQLDirective
18- import graphql.schema.GraphQLEnumType
1923import graphql.schema.GraphQLFieldDefinition
2024import graphql.schema.GraphQLInputObjectField
2125import graphql.schema.GraphQLInputObjectType
@@ -29,7 +33,6 @@ import graphql.schema.GraphQLSchema
2933import graphql.schema.GraphQLType
3034import graphql.schema.GraphQLTypeReference
3135import graphql.schema.GraphQLUnionType
32- import org.reflections.Reflections
3336import kotlin.reflect.KClass
3437import kotlin.reflect.KFunction
3538import kotlin.reflect.KParameter
@@ -52,9 +55,9 @@ internal class SchemaGenerator(
5255) {
5356
5457 private val cache = TypesCache (config.supportedPackages)
58+ private val subTypeMapper = SubTypeMapper (config.supportedPackages)
5559 private val additionTypes = mutableSetOf<GraphQLType >()
5660 private val directives = mutableSetOf<GraphQLDirective >()
57- private val reflections = Reflections (config.supportedPackages)
5861
5962 internal fun generate (): GraphQLSchema {
6063 val builder = generateWithReflection()
@@ -186,7 +189,7 @@ internal class SchemaGenerator(
186189
187190 private fun graphQLTypeOf (type : KType , inputType : Boolean = false): GraphQLType {
188191 val hookGraphQLType = config.hooks.willGenerateGraphQLType(type)
189- val graphQLType = hookGraphQLType ? : graphQLScalar (type) ? : objectFromReflection(type, inputType)
192+ val graphQLType = hookGraphQLType ? : defaultGraphQLScalars (type) ? : objectFromReflection(type, inputType)
190193 val typeWithNullityTakenIntoAccount = graphQLType.wrapInNonNull(type)
191194 config.hooks.didGenerateGraphQLType(type, typeWithNullityTakenIntoAccount)
192195 return typeWithNullityTakenIntoAccount
@@ -210,7 +213,7 @@ internal class SchemaGenerator(
210213 }
211214
212215 private fun getGraphQLType (kClass : KClass <* >, inputType : Boolean , type : KType ): GraphQLType = when {
213- kClass.isSubclassOf(Enum ::class ) -> enumType(kClass)
216+ kClass.isSubclassOf(Enum ::class ) -> @Suppress( " UNCHECKED_CAST " ) enumType(kClass as KClass < Enum < * >> )
214217 kClass.isSubclassOf(List ::class ) || kClass.java.isArray -> listType(type, inputType)
215218 kClass.canBeGraphQLUnion() -> unionType(kClass)
216219 kClass.canBeGraphQLInterface() -> interfaceType(kClass)
@@ -227,16 +230,6 @@ internal class SchemaGenerator(
227230 if (parameter.type.jvmErasure.java.isInterface) throw InvalidInputFieldTypeException ()
228231 }
229232
230- private fun enumType (kClass : KClass <* >): GraphQLEnumType {
231- val enumKClass = @Suppress(" UNCHECKED_CAST" ) (kClass as KClass <Enum <* >>)
232- val builder = GraphQLEnumType .newEnum()
233- enumKClass.java.enumConstants.forEach {
234- builder.value(it.name)
235- }
236- builder.name(enumKClass.simpleName)
237- return builder.build()
238- }
239-
240233 private fun listType (type : KType , inputType : Boolean ): GraphQLList =
241234 GraphQLList .list(graphQLTypeOf(type.arguments.first().type!! , inputType))
242235
@@ -274,7 +267,7 @@ internal class SchemaGenerator(
274267
275268 private fun inputObjectType (kClass : KClass <* >): GraphQLType {
276269 val builder = GraphQLInputObjectType .newInputObject()
277- val name = getGraphQLClassName (kClass, true )
270+ val name = getInputClassName (kClass)
278271
279272 builder.name(name)
280273 builder.description(kClass.graphQLDescription())
@@ -312,7 +305,7 @@ internal class SchemaGenerator(
312305 builder.typeResolver { env: TypeResolutionEnvironment -> env.schema.getObjectType(env.getObject<Any >().javaClass.simpleName) }
313306 val interfaceType = builder.build()
314307
315- val implementations = getSubTypesOf(kClass)
308+ val implementations = subTypeMapper. getSubTypesOf(kClass)
316309 implementations
317310 .filterNot { it.kotlin.isAbstract }
318311 .forEach {
@@ -334,7 +327,7 @@ internal class SchemaGenerator(
334327 builder.description(kClass.graphQLDescription())
335328 builder.typeResolver { env: TypeResolutionEnvironment -> env.schema.getObjectType(env.getObject<Any >().javaClass.simpleName) }
336329
337- val implementations = getSubTypesOf(kClass)
330+ val implementations = subTypeMapper. getSubTypesOf(kClass)
338331 implementations
339332 .filterNot { it.kotlin.isAbstract }
340333 .forEach {
@@ -351,7 +344,4 @@ internal class SchemaGenerator(
351344 builder.build()
352345 }
353346 }
354-
355- private fun getSubTypesOf (kclass : KClass <* >): MutableSet <out Class <out Any >> =
356- reflections.getSubTypesOf(Class .forName(kclass.javaObjectType.name))
357347}
0 commit comments