Skip to content

[discussion]: Automatically transforms enums to CAPITALIZED_WITH_UNDERSCORES style #1832

@kasvith

Description

@kasvith

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

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

In GraphQL world, enums are represented as CAPITALIZED_WITH_UNDERSCORES. This is described in the GraphQL spec as well.

GraphQL

enum CatStatus {
    HAPPY_AND_HEALTHY
    SAD_AND_HEALTHY
}

In the typescript world, it's common to use PascalCase for enum representations.

Typescript

enum CatStatus {
   HappyAndHealthy,
   SadAndHealthy
}

Code-First approach in the docs suggests using CAPITALIZED_WITH_UNDERSCORES as enum values. But that doesn't play nice with Typescript world.

Describe the solution you'd like

Automatically transform AnyCase, anyCase , any_case to the respective GraphQL enum representation on code generation and map to correct internal representation in NestJS side.

So,

Typescript

enum CatStatus {
   happy_AndHealthy,
   SadAndHealthy
}

Will become

GraphQL

enum CatStatus {
    HAPPY_AND_HEALTHY
    SAD_AND_HEALTHY
}

in GraphQL

This will allow us to follow best practices in both worlds.

For example, Elixir Absinthe follows this pattern

Teachability, documentation, adoption, migration strategy

This can be a breaking change, so it can be added as an optional argument to registerEnumType

What is the motivation / use case for changing the behavior?

Enforcing best practices in both GraphQL and Typescript

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions