This is documentation for v10, which is no longer actively maintained.
For up-to-date documentation, see the latest version.

Enum Type

Enum types consists of a set of named constants called the enumerator list.

SDL
enum Day {
SATURDAY
SUNDAY
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
}

Hot Chocolate can bind enumerations to a various set of types. The simplest thing is to bind GraphQL enum types to .NET enum types.

C#
public class DayType : EnumType<Day> { }

When you bind GraphQL enum types to .NET enum types then Hot Chocolate will infer everything for you. But you can still overwrite what we have inferred by overriding the Configure method.

C#
public class DayType : EnumType<Day>
{
protected override void Configure(IEnumTypeDescriptor<Day> descriptor)
{
descriptor.Value(Day.Monday)
.Name("MY_CUSTOM_NAME")
.Description("This is the description of this value")
.Directive(new MyCustomDirective());
}
}

You can also bind the enumeration type to any other .NET type.

C#
public class DayType : EnumType<string>
{
protected override void Configure(IEnumTypeDescriptor<string> descriptor)
{
descriptor.Value("monday")
.Name("MY_CUSTOM_NAME")
.Description("This is the description of this value")
.Directive(new MyCustomDirective());
}
}