fun generateKotlinCode()

in graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/shared/GenerateKotlinCode.kt [27:91]


fun generateKotlinCode(
    value: Value<Value<*>>,
    type: TypeName,
    inputTypeDefinitions: Collection<InputObjectTypeDefinition>,
    config: CodeGenConfig,
    typeUtils: KotlinTypeUtils,
): CodeBlock =
    checkAndGetLocaleCodeBlock(value, type)
        ?: checkAndGetLongCodeBlock(value, type)
        ?: checkAndGetBigDecimalCodeBlock(value, type)
        ?: checkAndGetCurrencyCodeBlock(value, type)
        ?: when (value) {
            is BooleanValue -> CodeBlock.of("%L", value.isValue)
            is IntValue -> CodeBlock.of("%L", value.value)
            is StringValue -> CodeBlock.of("%S", value.value)
            is FloatValue -> CodeBlock.of("%L", value.value.toString())
            is EnumValue -> CodeBlock.of("%M", MemberName(type.className, value.name))
            is ArrayValue ->
                if (value.values.isEmpty()) {
                    CodeBlock.of("emptyList()")
                } else {
                    CodeBlock.of(
                        "listOf(%L)",
                        value.values.joinToString { v ->
                            generateKotlinCode(
                                v,
                                type,
                                inputTypeDefinitions,
                                config,
                                typeUtils,
                            ).toString()
                        },
                    )
                }

            is ObjectValue -> {
                val inputObjectDefinition =
                    inputTypeDefinitions.first {
                        val expectedCanonicalClassName =
                            config.typeMapping[it.name] ?: "${config.packageNameTypes}.${it.name}"
                        expectedCanonicalClassName == type.className.canonicalName
                    }

                CodeBlock.of(
                    type.className.canonicalName + "(%L)",
                    value.objectFields.joinToString { objectProperty ->
                        val argumentType =
                            checkNotNull(inputObjectDefinition.inputValueDefinitions.find { it.name == objectProperty.name }) {
                                "Property \"${objectProperty.name}\" does not exist in input type \"${inputObjectDefinition.name}\""
                            }
                        "${objectProperty.name} = ${
                            generateKotlinCode(
                                objectProperty.value,
                                typeUtils.findReturnType(argumentType.type),
                                inputTypeDefinitions,
                                config,
                                typeUtils,
                            )
                        }"
                    },
                )
            }

            else -> CodeBlock.of("%L", value)
        }