Skip to content
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

Rename AutoGenerated Type for Flags Enum #7103

Open
tscott-servicetitan opened this issue May 13, 2024 · 0 comments
Open

Rename AutoGenerated Type for Flags Enum #7103

tscott-servicetitan opened this issue May 13, 2024 · 0 comments
Labels

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");
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant