Netflix / dgs-codegen

Apache License 2.0
177 stars 92 forks source link

GraphQL interfaces should still be annotated when using the `@annotate` directive #687

Open THE-ORONCO opened 2 months ago

THE-ORONCO commented 2 months ago

Given an interface and a type, both of which have the @annotate directive placed on them, annotations are only generated for the GraphQL type.

For example (you can also find it as a cloneable repo):

interface TestInterface @annotate(name: "com.example.badinterfacegeneration.TestAnnotation") {
    name: String! @annotate(name: "com.example.badinterfacegeneration.TestAnnotation", target: "get")
}

type TestType @annotate(name: "com.example.badinterfacegeneration.TestAnnotation") {
    name: String! @annotate(name: "com.example.badinterfacegeneration.TestAnnotation", target: "get")
}

generates the following class:

@TestAnnotation
public class TestType {
  private String name;

  public TestType() {
  }

  public TestType(String name) {
    this.name = name;
  }

  @TestAnnotation
  public String getName() {
    return name;
  }
  // ... the rest of the generated code
}

and interface:

public interface TestInterface {
  String getName();

  void setName(String name);
}

The Interface does not have any annotations despite having them defined in the GraphQL schema. This is not the behaviour I expect. There should either be an error that indicates that annotations cannot be placed on interfaces or annotations should be placed on the generated interface.

I don't know how feasible this feature is to implement. If it is not possible, an addition to the documentation or a warning during generation would be nice.