dotansimha / dotansimha/graphql-code-generator-community

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

Open
#605 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

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

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

```graphql
type Project {
name: String!
}
```

generates:

```kotlin
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](https://www.baeldung.com/kotlin/extend-data-class) 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.
https://github.com/dotansimha/graphql-code-generator-community/compare/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`:

```kotlin
class Project(
val name: String
)
```

Using `typesType: interface`:

```kotlin
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.