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

Support for meta-annotations #262

Open
marceloverdijk opened this issue Jun 12, 2020 · 4 comments
Open

Support for meta-annotations #262

marceloverdijk opened this issue Jun 12, 2020 · 4 comments

Comments

@marceloverdijk
Copy link

Consider this example:

    @Query("continents")
    @Description("Get a page of continents.")
    public @NonNull ContinentPageType getContinents(
            @Name("page")
            @DefaultValue("0")
            @Description("The page number.")
            Integer page,
            @Name("size")
            @DefaultValue("10")
            @Description("The page size.")
            Integer size) {

The page and size arguments will occur many times in my api.

So I thought about creating a page annotation like:

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Name("page")
@DefaultValue("10")
@Description("The page size.")
public @interface PageSize {

}

Unfortunately this won't work as:

  1. @DefaultValue has only @Target({ElementType.PARAMETER,ElementType.FIELD,ElementType.METHOD}) and not ElementType.ANNOTATION_TYPE. Maybe this could be added to make use of meta-annotations; probably this could be added to other MicroProfile GraphQL annotations as well.

  2. @Description("The page size.") does not generate the expected description in the schema (probably SmallRye implementation specific).

With meta annotation it should be possible to override on a lower level as well.

So with the example above:

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Name("page")
@DefaultValue("10")
@Description("The page size.")
public @interface PageSize {

}

it should be possible to do:

    @Query("continents")
    @Description("Get a page of continents.")
    public @NonNull ContinentPageType getContinents(
            @Name("page")
            @DefaultValue("0")
            @Description("The page number.")
            Integer page,
            @PageSize
            Integer size) {

but also:

    @Query("continents")
    @Description("Get a page of continents.")
    public @NonNull ContinentPageType getContinents(
            @Name("page")
            @DefaultValue("0")
            @Description("The page number.")
            Integer page,
            @PageSize
            @DefaultValue("20")
            Integer size) {
@phillip-kruger
Copy link
Contributor

Hi @marceloverdijk . Thanks for this. Also see issue #29 that will solve your specific use case. However it won't solve othe cases of repeated annotations. I am also not sure if this is a GraphQL spec issue, or a general issue ( meaning you will have the same issue in JAX-RS and other places )

@marceloverdijk
Copy link
Author

Yes I’m aware of #29 and I was about to comment on that one as well in a couple of minutes 😊

@t1
Copy link
Contributor

t1 commented Jun 21, 2020

This is a part of the issue as we discussed on the MP mailing list about mixins and other annotation magic. Stereotypes is just one of the features we discussed.

@t1
Copy link
Contributor

t1 commented Jun 22, 2020

It's a separate requirement, but I hope we can fix it with the same toolset as #111.

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

3 participants