Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin nullability feature for typesafe client (client model) #2263

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mskacelik
Copy link
Contributor

/cc @jmartisk
Ok, so with nullabilities in Kotlin, it is a bit complicated; when not having an ? nullable operator for types, Kotlin automatically adds its own Kotlin @NonNull annotations, but not ALWAYS. For example, when having a List<String>, the annotation is only applied on the List<> part but not the argument String. So, making these two codes indistinguishable (via Jandex):

List<String?> // List<String>

On top of that, there are some weird behaviors like annotation is applied only on MethodParameterInfo and not the Type

So, I only added a simple Kotlin nullability feature (see tests). So it can be consistent with the server side.
Java reflection implementation of typesafe client still does not have Kotlin nullability checking (todo?).

issue: #2142
@robp94

@jmartisk
Copy link
Member

@robp94 would you be willing to give this a try and see if it suits your expectations?

@mskacelik mskacelik force-pushed the kotlin-nullability-client branch 2 times, most recently from fb6b194 to c899e34 Compare January 30, 2025 08:46
@robp94
Copy link
Contributor

robp94 commented Jan 30, 2025

Looks good to me.

@mskacelik
Copy link
Contributor Author

mskacelik commented Jan 30, 2025

I played a bit with the MP @NonNull annotations now (with -Xemit-jvm-type-annotations flag) and it seems to work with Kotlin now if we explicitly annotate inside of wrappers.

@Mutation
    fun testMatrix(working: List<@NonNull String>): Boolean {
        println("hello world")
        return true
    }

schema:

"Mutation root"
type Mutation {
  testMatrix(working: [String!]!): Boolean!
}

edit: I know it worked before the PR, but it could be substitute of an explicit nullability of Kotlin (inside generic arguments). Gonna try add some server-side tests.

@jmartisk
Copy link
Member

@mskacelik please add a little note (about having to add this flag) to our documentation, it will be useful to many developers

@mskacelik mskacelik force-pushed the kotlin-nullability-client branch from c899e34 to af9b182 Compare January 30, 2025 11:57
@mskacelik
Copy link
Contributor Author

mskacelik commented Jan 30, 2025

Ok, it seems to have some problems regarding nested Lists, i.e.: List<List<Int>> only generates [Int] (only in Kotlin, Java works (server side)).

But I think I found a bigger problem, in Quarkus @NonNull annotations seem to be very inconsistent after HOT RELOAD.
For example:

>quarkus dev
List<@NonNull String> => generates [String!]!
changes code to Array<@NonNull String> => generates [String]! (HOT RELOAD)
...terminates app...
>quarkus dev
Array<@NonNull String> => generates [String!]! 
changes code to List<@NonNull String> => generates [String]! (HOT RELOAD)

Very strange (once again AFAIK only Kotlin is doing this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants