Skip to content

Rename AutoGenerated Type for Flags Enum #7103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tscott-servicetitan opened this issue May 13, 2024 · 1 comment
Open

Rename AutoGenerated Type for Flags Enum #7103

tscott-servicetitan opened this issue May 13, 2024 · 1 comment

Comments

@tscott-servicetitan
Copy link

Product

Hot Chocolate

Is your feature request related to a problem?

Not long ago a feature was introduced for supporting enums with [Flags] attribute.
#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");
  }
}
@kmcc049
Copy link

kmcc049 commented May 28, 2025

The second suggestion where you can opt out per type would be really handy. We've worked around the flags enum problem in other ways for existing enums but would like to use the inbuilt flags handling for new enums. However turning on the option on the server makes many breaking schema changes. If we could opt out the existing ones and go back and fix them then we could use this option going forwards.

@michaelstaib michaelstaib added this to the HC-15.3.0 milestone May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants