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

Could @GraphQLNonNull be used as an ElementType.METHOD annotation? #91

Closed
tekopabara opened this issue Mar 23, 2018 · 8 comments
Closed

Comments

@tekopabara
Copy link

tekopabara commented Mar 23, 2018

Everything is working great in our project with SPQR except for required fields : we're using Kotlin so getters/setters are generated, which makes it impossible to put the @GraphQLNonNull as parameter annotations.

Would it be possible to use this annotation as ElementType.METHOD?

Thanks!

@kaqqao
Copy link
Member

kaqqao commented Mar 23, 2018

I don't think this would actually solve your problem. @GraphQLNonNull is much more fine-grained, and can be used e.g. to produce nullable lists of non-nullable items, e.g. List<@GraphQLNonNull Book> which would be impossible to express.

Even if the annotation itself would be allowed on a method, much of the information would still be lost, due to a bug JetBrains doesn't care to fix. As a result, Kotlin properties simply don't work with Java's TYPE_USE annotations and AnnotatedType which are at the root of how SPQR works.

If I'd change the annotations, only some cases would start working in Kotlin at the expense of creating long term complications and confusion. So it makes no sense from the project perspective to go there. I'm sorry to say, but with the situation as it is, Kotlin support is currently a non-goal. I'll do what I can to make it compatible where possible, but as long as the bug is there, I can't do all that much without sacrifices bigger than I'm willing to make...

@kaqqao kaqqao closed this as completed Mar 23, 2018
@kaqqao
Copy link
Member

kaqqao commented Mar 23, 2018

You can see more discussion and links here.

Is it possible to write explicit getters/setters in these cases?

@kaqqao
Copy link
Member

kaqqao commented Mar 30, 2018

The scariest part is that the property annotations are inaccessible even to Kotlin's reflection. This bug is even labeled as Major priority, yet with no attention for over a year...

@tekopabara
Copy link
Author

@kaqqao sorry for the late answer and thank you for taking the time to explain what's happening with Kotlin. We'll write getters/setters manually.

@kaqqao
Copy link
Member

kaqqao commented May 3, 2018

Interestingly enough, so many people have been complaining about this recently (I like to believe it's because of SPQR) that it finally attracted some attention from JetBrains. We even got a response from the assigned developer saying that he'll try implementing it in the next full release of Kotlin!
Please do vote and comment on those issues! It seems to be helping..

@alediaferia
Copy link

alediaferia commented Mar 17, 2019

Hey, I've created an example schema transformer that infers nullability information from Kotlin runtime.

You can have a look here: https://github.com/alediaferia/graphql-spqr-kotlin-example/blob/master/src/main/kotlin/com/alediaferia/graphql/spqr/kotlin/KotlinTypesSchemaTransformer.kt

Have a look at the tests to better understand what it does.

@kaqqao let me know if there's anything you want me to include in the example and BTW: awesome work with this library, it's very well organized.

@williamboman
Copy link

williamboman commented Sep 6, 2019

@alediaferia Thank you for sharing this ❤️

edit: also thanks kaqqao for this awesome lib of course

@abdussametkaci
Copy link

Hey, I've created an example schema transformer that infers nullability information from Kotlin runtime.

You can have a look here: https://github.com/alediaferia/graphql-spqr-kotlin-example/blob/master/src/main/kotlin/com/alediaferia/graphql/spqr/kotlin/KotlinTypesSchemaTransformer.kt

Have a look at the tests to better understand what it does.

@kaqqao let me know if there's anything you want me to include in the example and BTW: awesome work with this library, it's very well organized.

Hello, I saw your configuration and improved it a little more. I used your code as a source. So I wrote a configuration like this: SchemaTransformerConfiguration

Thanks for sharing :)

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

No branches or pull requests

5 participants