ChilliCream / ChilliCream/graphql-platform

Rename AutoGenerated Type for Flags Enum

Open
#7,103 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Type System
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Is your feature request related to a problem?

Not long ago a feature was introduced for supporting enums with [Flags] attribute.
https://github.com/ChilliCream/graphql-platform/pull/5186

Currently there is no way to rename this auto generated type. Example:

[Flags]
public enum MyEnum {
  A
  B
  C
}

public class MyEnumType : EnumType<MyEnum>
{
  protected override Configure(IEnumTypeDescriptor<MyEnum> descriptor)
  {
    descriptor.Name("MyRenamedEnum");
  }
}

Will generate the following:

enum MyRenamedEnum {
  A
  B
  C
}

type MyEnumFlags {
  isA: Boolean!
  isB: Boolean!
  isC: Boolean!
}

Notice that MyEnumFlags is used rather than MyRenamedEnumFlags.

The solution you'd like

Flags enums are supported through TypeInterceptors and not a specific type. As I'm not familiar with these, I'm unsure the best way to support this.

Ideas:
public class MyEnumType : EnumFlagsType<MyEnum>
{
  protected override Configure(IEnumFlagsTypeDescriptor<MyEnum> descriptor)
  {
    descriptor.Name("MyRenamedEnum");
  }
}

Another solution would be to support respecting the original EnumType. The trick here is determining whether the developer
wants the flags type, or actually wants to use the enum type despite flags being enabled.

public class MyEnumType : EnumType<MyEnum>
{
  protected override Configure(IEnumTypeDescriptor<MyEnum> descriptor)
  {
    descriptor.Name("MyRenamedEnum");
  }
}

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

Start by reviewing PR #5186 and the TypeInterceptors that generate the flags enum type. Trace how the original enum name is obtained and confirm that configuring the enum as MyRenamedEnum produces MyRenamedEnumFlags rather than MyEnumFlags; add coverage for the example behavior if the relevant tests are found.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.