Netflix / Netflix/dgs-codegen

Unable to generate constructor param and populate companion object in models and enum

Open
#441 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
217
Forks
116
PR merge metrics
No merged PRs in 30d

Description

I am trying to generate an enum class with a label as the constructor param and have a function in the companion object.
The schema GraphQL looks like

type Account {
    accountId: String!
    accountNumber: Int!
    accountStatus: AccountStatus
    accountBalance: Float!
}

enum AccountStatus {
    ACTIVE,
    INACTIVE,
    CLOSED,
    UNKNOWN
}

and the generated enum looks like

@Generated(
  value = ["com.netflix.graphql.dgs.codegen.CodeGen"],
  date = "2022-08-09T22:03:45.581297Z",
)
public enum class AccountStatus {
  ACTIVE,
  INACTIVE,
  CLOSED,
  UNKNOWN,
  ;

  public companion object
}

My goal is to have the following enum class generated

enum class AccountStatus(val label: String) {
    UNKNOWN("UNKNOWN"),
    ACTIVE("ACTIVE"),
    INACTIVE("INACTIVE"),
    LOCKED("LOCKED");

    companion object {
        fun fromLabelString(label: String?): AccountStatus {
            return if (label == null) {
                UNKNOWN
            } else {
                values().find { it.label.equals(label) } ?: UNKNOWN
            }
        }
    }
}

I was unable to find documentation regarding generating custom enums and classes and wanted to know if this is currently possible and if not what would be the recommended way to achieve this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no source files or tests. Start by reviewing the Kotlin enum and model generation options, then compare supported configuration with the requested constructor parameter and companion-object function. Done means establishing whether this behavior is supported and documenting or scoping the required change.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
backend-api-design, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.