@@ -4,6 +4,7 @@ import com.auritylab.graphql.kotlin.toolkit.codegen.helper.NamingHelper
44import com.auritylab.graphql.kotlin.toolkit.codegen.mapper.GeneratedMapper
55import com.auritylab.graphql.kotlin.toolkit.codegen.mapper.KotlinTypeMapper
66import com.auritylab.graphql.kotlin.toolkit.common.directive.DirectiveFacade
7+ import com.auritylab.graphql.kotlin.toolkit.common.helper.GraphQLTypeHelper
78import com.squareup.kotlinpoet.ANY
89import com.squareup.kotlinpoet.CodeBlock
910import com.squareup.kotlinpoet.FunSpec
@@ -17,7 +18,6 @@ import graphql.schema.GraphQLDirectiveContainer
1718import graphql.schema.GraphQLEnumType
1819import graphql.schema.GraphQLInputObjectType
1920import graphql.schema.GraphQLList
20- import graphql.schema.GraphQLModifiedType
2121import graphql.schema.GraphQLNonNull
2222import graphql.schema.GraphQLType
2323
@@ -42,17 +42,17 @@ internal class ArgumentCodeBlockGenerator(
4242 argumentName : String ,
4343 type : GraphQLType ,
4444 fieldDirectiveContainer : GraphQLDirectiveContainer ?
45- ): FunSpec {
46- val kotlinType = typeMapper.getKotlinType(type, fieldDirectiveContainer)
47-
48- return FunSpec .builder(" resolve${NamingHelper .uppercaseFirstLetter(argumentName)} " )
49- .addModifiers(KModifier .PRIVATE )
50- .addParameter(" map" , MAP .parameterizedBy(STRING , ANY ))
51- .returns(kotlinType)
52- .addCode(buildArgumentResolverCodeBlock(argumentName, type, fieldDirectiveContainer))
53- .build()
54- }
45+ ) = FunSpec .builder(" resolve${NamingHelper .uppercaseFirstLetter(argumentName)} " )
46+ .addModifiers(KModifier .PRIVATE )
47+ .addParameter(" map" , MAP .parameterizedBy(STRING , ANY ))
48+ .returns(typeMapper.getKotlinType(type, fieldDirectiveContainer))
49+ .addCode(buildArgumentResolverCodeBlock(argumentName, type, fieldDirectiveContainer))
50+ .build()
5551
52+ /* *
53+ * Will build the [CodeBlock], which contains all the functions to resolve each layer and build the final result
54+ * for the given [type].
55+ */
5656 private fun buildArgumentResolverCodeBlock (
5757 name : String ,
5858 type : GraphQLType ,
@@ -61,7 +61,7 @@ internal class ArgumentCodeBlockGenerator(
6161 val code = CodeBlock .builder()
6262
6363 // Get all layers of the type.
64- val layers = unwrapTypeLayers(type).asReversed()
64+ val layers = GraphQLTypeHelper . unwrapTypeLayers(type).asReversed()
6565
6666 var currentIndex = 0
6767 var lastType: TypeName = ANY
@@ -99,23 +99,8 @@ internal class ArgumentCodeBlockGenerator(
9999 }
100100
101101 /* *
102- * A [GraphQLType] can be wrapped with unmodifiable types (e.g. List, NonNull).
103- * This method will unwrap until an actual type.
102+ * Will build the [CodeBlock] which will resolve the given [type].
104103 */
105- private fun unwrapTypeLayers (type : GraphQLType ): List <GraphQLType > {
106- val wraps = mutableListOf<GraphQLType >()
107-
108- var c = type
109- while (c is GraphQLModifiedType ) {
110- wraps.add(c)
111- c = c.wrappedType
112- }
113-
114- wraps.add(c)
115-
116- return wraps
117- }
118-
119104 private fun buildLayerParser (
120105 type : GraphQLType ,
121106 index : Int ,
0 commit comments