Skip to content

Commit

Permalink
Readable error "scalar not configured"
Browse files Browse the repository at this point in the history
  • Loading branch information
ermadmi78 committed Jun 29, 2021
1 parent 5ccba0d commit 1cb3c35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,11 @@ kobby {
kotlin {
scalars = mapOf(
"Date" to typeOf("java.time", "LocalDate"),
"JSON" to typeMap.parameterize(typeString, typeAny.nullable())
)
}
}

val kotlinJvmVersion: String by project
tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = kotlinJvmVersion
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
}

val jacksonVersion: String by project
dependencies {
compileOnly("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
Expand Down
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.Duration
import java.time.Instant

Expand Down Expand Up @@ -46,7 +45,7 @@ subprojects {
println("${currentProject.group}:${currentProject.name}")

tasks {
withType<KotlinCompile> {
compileKotlin {
kotlinOptions {
jvmTarget = kotlinJvmVersion
freeCompilerArgs = listOf("-Xjsr305=strict")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ data class KotlinLayout(
val adapter: KotlinAdapterLayout,
val resolver: KotlinResolverLayout
) {
private fun getScalarType(name: String): KotlinType {
val result = scalars[name]
if (result == null) {
val message = "Kotlin data type for scalar '$name' not found. " +
"Please, configure it by means of 'kobby' extension. https://github.com/ermadmi78/kobby"
System.err.println(message)
throw IllegalStateException(message)
}

return result
}

// *****************************************************************************************************************
// DTO
// *****************************************************************************************************************
Expand All @@ -38,7 +50,7 @@ data class KotlinLayout(
get() = when (this) {
is KobbyListType -> LIST.parameterizedBy(nested.dtoType)
is KobbyNodeType -> when (node.kind) {
SCALAR -> scalars[node.name]!!.typeName
SCALAR -> getScalarType(node.name).typeName
else -> node.dtoClass
}
}.let { if (nullable) it.nullable() else it }
Expand Down Expand Up @@ -185,7 +197,7 @@ data class KotlinLayout(
private fun KobbyType.toEntityType(makeNullable: Boolean): TypeName = when (this) {
is KobbyListType -> LIST.parameterizedBy(nested.toEntityType(false))
is KobbyNodeType -> when (node.kind) {
SCALAR -> scalars[node.name]!!.typeName
SCALAR -> getScalarType(node.name).typeName
ENUM, INPUT -> node.dtoClass
else -> node.entityClass
}
Expand Down

0 comments on commit 1cb3c35

Please sign in to comment.