Hi. I have a question. in the lib graphql-kotlin ...
# reflect
h
Hi. I have a question. in the lib graphql-kotlin reflection is used to create GraphQL schema Types. If you are using a java class it will generate the types with all members being mandatory. After discussing with them they use reflection and the flag “isMarkedNullable” to determin if it is nullable or not. My question is: Why is the return type of the members of a Java class marked as non-nullable? Why is it not nullable as standard? Is there the possibility to determine if it is a javaclass or a kotlin class to work around that?
☑️ 1
u
The problem is that such type is flexible from Kotlin’s point of view, thus it’s neither nullable nor non-null (https://kotlinlang.org/spec/type-system.html#flexible-types). Technically
isMarkedNullable
returns false correctly, in the sense that it is not true that the type has been explicitly marked as nullable, as is the case with Kotlin nullable types, but of course that’s not very useful. Kotlin-reflect doesn’t have an API to detect flexible types, but it should. There’s an open issue about it: https://youtrack.jetbrains.com/issue/KT-15987 You can use a workaround like this to detect Java nullability-flexible types:
Copy code
fun KType.isNullabilityFlexible(): Boolean =
    !isMarkedNullable && this != withNullability(false) && this != withNullability(true)
🙏🏻 1