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 support #72
Comments
Thanks for the kind words!
I'll add the support for While I would certainly love for SPQR to work with Kotlin, I have no capacity to support it... I do not know enough about it nor have the time to go into it without the rest of the project suffering, as I'm currently the only active developer. Are there any other problems in Kotlin currently? It's important to note though that almost everything about SPQR is customizable and extensible externally, so you could actually add support for Also, there's a SPQR-powered Spring Boot starter in the works that will be much more convenient to use than anything else out there :) |
Thanks for your fast response! I checked the bytecode that Kotlin generates, and I can clearly see that it implicitly annotates non-null types with the If you could add these annotation to SPQR's schema-gen it would be fantastic. As for the SPQR-powered Spring Boot starter, it sounds awesome, can't wait for it. Thanks! |
I'm planning the next release by the end of the week. Btw, if you're versatile with Kotlin, maybe you can help troubleshoot the issue with |
I've put a breakpoint in both classes, and I guess the problem can came from the fact that the I'll try to explain, please have a look at the following code:
This is a Kotlin class that has a firstName property, so a getter and a setter method will be created by Kotlin. The
or on the field directly like this:
But I can't do it because the annotation's target is set to What I can see from Is this possible or I am completely wrong here? |
As far as the parameter names are concerned, now I've got it to work without the In Gradle you can do it like this:
So one mystery solved :) |
Aaah, nice analysis! I think you're on the spot with the annotation target mismatch. Yes,
The reason it's a Also, thanks for the help :) |
Well the syntax you proposed is syntactically correct, but unfortunately |
I experimented a bit... The annotation is nowhere to be found with Java reflection. Not on the field return type, not on the getter return type and not even on the constructor parameter. It's only available in |
So the only possible solution is to write a Kotlin extension to SPQR and provide a Kotlin implementation of |
That's good to hear :) Actually, I think it's the |
I opened a question on SO and it got a very interesting answer... At least partially, this seems to be a bug in Kotlin :( And if you dig through the related issues, it just gets scarier... |
Wow, that's weird. So once they fix this in Kotlin it is going to work as intended? |
If KT-13228 would get fixed, yes. But I wouldn't hold my breath as it's been ignored for 2 years now... It doesn't seem like JetBrains actually cares for Kotlin outside of Android. I'll think some more if anything can be done in SPQR to alleviate the problem. |
I added support for |
I've published a POC for Kotlin support (it leverages runtime reflection) https://github.com/williamboman/graphql-spqr-kotlin. (I don't recommend using it for any production code though, but great fit for hobby projects if you want to use Kotlin + graphql-spqr). |
Why not recommended to use this on production? |
It's more a POC which I've only tested with basic implementations. I also don't recommend doing it because of:
That's just my advice, feel free to do with it what you will! |
I don't understand what @williamboman 's code is doing, but with this bug in Kotlin fixed it should be possible to implement a |
Actually... now that I think about it, it should probably be a custom |
Would the |
For Kotlin 1.3.70+ as mentioned in KT-13228 when added the compiler argument |
is |
Hi!
Awesome library I love it, I even dropped graphql-java-tools and graphql-spring-boot-started for it.
However, it would be awesome to have Kotlin support in the library. For example, it could automatically pick up annotations like:
org.jetbrains.annotations.NotNull
, which tells spqr which field is nullable and which is not.Right now, I can't even get the
@GraphQLNonNull
annotation to work in Kotlin:What can go wrong here? Also do you plan to support Kotlin?
My final question would be that, is it possible with this library that I don't need to specify
@GraphQLArgument(name = "username")
in the example mentioned above?It could automatically infer the name from the name of the variable with the -parameter javac option enabled.
Thanks,
Gabor
The text was updated successfully, but these errors were encountered: