dotansimha / graphql-code-generator-community

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: [java & kotlin] Generate types as interfaces

tristanlins opened this issue · comments

Is your feature request related to a problem? Please describe.

Currently, the kotlin plugin generates types as data class. This graphql type:

type Project {
  name: String!
}

generates:

data class Project(
  val name: String
)

The downside of data classes are, that they are effectively final, and it is not easy to inherit them.
This baeldung article says in short:

data classes do not work well with inheritance

Especially when implementing the server-side, interfaces are much more suitable. These can be used with proxies and code generation to optimize the server.

Describe the solution you'd like

An option to change the data class to class or interface types.

Additional context

I have already implemented a potential solution for Kotlin.
main...tristanlins:graphql-code-generator-community:feature-kotlin-interfaces

With the configuration option typesType (any better suggestions?), the generation can be controlled, and instead of generating data class, class or interface types can be generated.

Using typesType: class:

class Project(
  val name: String
)

Using typesType: interface:

interface Project {
  val name: String
}

Additionally, I have added an option to suppress the generation of input transformers. In my scenario, I only need the input types, but not the transformers.
I would like to implement the same change for the Java plugin as well. Should I submit this as a separate merge request?