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

Allow users to "annotate" classes outside of their source control #111

Open
andymc12 opened this issue Nov 15, 2019 · 10 comments
Open

Allow users to "annotate" classes outside of their source control #111

andymc12 opened this issue Nov 15, 2019 · 10 comments
Assignees
Milestone

Comments

@andymc12
Copy link
Contributor

The use case here is for users who pull in third party binaries that they want to use as GraphQL entities, but then rename or add a description, etc.

One thought would be to use MP Config to "annotate" the third party classes without changing the code - something like:

mp.graphql.typename=com.mypkg.MyPojo=pojo
mp.graphql.typedescription=com.mypkgs.MyPojo=A pojo is intended for...

This might take some more thought - for type name/description, it might be easy enough to use MP Config, but then users may also want to declaratively rename or ignore certain fields/getters/setters, and then things get a little more complicated.

@phillip-kruger phillip-kruger added this to the 1.1 milestone Dec 11, 2019
@ybroeker
Copy link
Contributor

ybroeker commented Apr 7, 2020

Wouldn’t be something like Jacksons Mixins a useful alternative to MP Config to annotate existing classes?

An existing class like:

public class MyPojo {

    private String field;

    public String getField() {
        return field;
    }
    public void setField(String field) {
        this.field = field;
    }
}

could then be “annotated” with a “mixin”-interface or (abstract-) class like:

@Mixin(MyPojo.class)
@Name("Pojo")
@Description("A pojo is intended for...")
public interface MyPojoMixin {

    @NonNull
    public String getField();
    
    @Ignore
    public void setField(String field);
}

This would just need one new annotation and no new config options, all existing annotations would also be useable on “mixin”-types.

@phillip-kruger
Copy link
Member

Sounds like a good idea ! However we should possibly create our own annotations as to not expose implementations on the boundary.

Mixins might be something that can be shared with other MP api's ?

@ybroeker
Copy link
Contributor

ybroeker commented Apr 8, 2020

As far as I know there is currently no such annotation, so a new annotation need to be created anyways.

This could indeed be useful for other MP api's like MP OpenApi, for the same usecase. Is there any project for such shared "things"?

@phillip-kruger
Copy link
Member

No there is not. At least not as far as I know :)

@ybroeker
Copy link
Contributor

Added an example in https://github.com/ybroeker/smallrye-graphql/tree/feat/mixin, maybe it is interesting for you.

@t1
Copy link
Contributor

t1 commented May 20, 2020

I think that mixins should also consider CDI Stereotype annotations.

The whole annotation resolving mechanism is getting quite complex:

  • Use a class annotation as a fallback, if the method is not annotated.
  • Sometimes even use a package annotation, if the class is not annotated.
  • Resolve Stereotypes (recursively)
  • Resolve Mixins

Spring does even more things like aliases for annotation properties, etc.

As this is required by so many projects, I guess it should become a separate project, maybe even a separate MP standard, so all MP standards can be based on it. It even has the potential of becoming part of CDI some day.

P.S.: A few years ago, I extracted some of these mechanisms to https://github.com/t1/stereotype-helper

@t1
Copy link
Contributor

t1 commented Jun 26, 2020

We've just talked about this issue on the working group weekly. We need feedback on the library that we may want to use: https://github.com/t1/power-annotations
Mixins already work by using Jandex. I'm trying to get basic Stereotypes working now. Then I'll give it a try on the GraphQL Typesafe Client to see how it works out in real code.

@t1
Copy link
Contributor

t1 commented Jul 3, 2020

I'm thinking about another really cool use-case for mixins: say we're developing an application packed with annotations from JPA, which doesn't support mixins (yet). The application also uses a library that supports mixins but doesn't know about JPA, e.g. a future MP GraphQL. We want all JPA @Id annotations to be recognized as synonyms for GraphQL @Id annotations. We could create a simple mixin for the JPA annotation:

@MixinFor(javax.persistence.Id.class)
@org.eclipse.microprofile.graphql.Id
public class PersistenceIdMixin {}

Voila! MP GraphQL would work as if all JPA @Id annotations where it's own.

This would become even more interesting, when the annotation values could be mapped, so, e.g., OpenAPI annotations could also serve as GraphQL @Description annotations.

I'm working on implementing this in Power Annotations.

@t1
Copy link
Contributor

t1 commented Jul 5, 2020

Annotation-mixins work now. Next I'll try to use it for the typesafe client... in a separate branch, as we've discussed.

@t1
Copy link
Contributor

t1 commented Jul 11, 2020

We will work on this in smallrye before we pull it up into MP GraphQL. You may want to look here.

@phillip-kruger phillip-kruger modified the milestones: 1.1, 2.0 Mar 9, 2021
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

4 participants