Enigmatis / graphql-java-annotations

GraphQL Annotations for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Mixins (annotations on third-party classes)

TheSpiritXIII opened this issue · comments

Sometimes you can't put annotations because you don't define the underlying class in your project. Other Java annotation libraries such as Jackson solved this with "Mixins".

The way it works in Jackson is that you define either an interface or abstract class with the annotations. Then, you register it with the third-party class in the ObjectMapper (the object responsible for doing the conversions). Finally, whenever the third-party class is serialized, it will use the annotations from the Mixin to figure out which fields to serialize and how and when it is deserialized, it will just create an instance of the third-party class.

Here is their documentation: https://github.com/FasterXML/jackson-docs/wiki/JacksonMixInAnnotations

If this is possible through other means with this library, please let me know. An alternative would be to create delegate objects, but then that's annoying because each call site will have to wrap or unwrap the delegated object and I would like to avoid that.

commented

If I usderstand it correctly, you want to create a mapping between an existing class (A), to another class (B), and then parse the graphql fields as the fields of class B?

Though it's interesting, it seems like a very specific use case and I'm not sure if I would spend time on developing that in this library. But you are welcome to PR us if you think it can be usefull.

To explain it with an example, imagine class A is owned by third-party library so you're unable to add annotations to it because you're not the one who defines it. The proposed feature would allow you to create either an interface or abstract class B whose method signatures match class A, but have annotations. I propose some API named GraphQLAnnotation.mixin where you pass in A and B as input. Your output will be a GraphQLObjectType which is mapped to class A, but whose mapping is created using the annotations from B.

I will give an implementation a go. If I'm successful, I will send a PR your way. :)

Hi @TheSpiritXIII ,

We're helping with project maintenance and reviewing the list of opened PRs and Issues.

This issue was created quite a while ago, we were wondering if you were still interested in the outcome, please let us know if this is the case.

Without an answer by July 1st, 2023, this issue will be closed as "inactive" (and can always be re-opened later on if needed).

Thanks,