Describe the bug
Given an enum like
enum Foo { Bar },
line 18 in EnumValueDescriptor.cs creates a string value that is all uppercase, ie: "BAR".
Then, if you make a query where that Enum is submitted in a variable in a query, an exception is thrown if you submit the value as BAR.
"Requested value 'BAR' was not found.\r\n\r\n at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)\r\n at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)\r\n at HotChocolate.Execution.DictionaryToObjectConverter.VisitValue(Object value, DeserializationContext context)\r\n at HotChocolate.Execution.DictionaryToObjectConverter.VisitField(KeyValuePair2 field, DeserializationContext context)\r\n"`
However, if you submit the value as "Bar" it works fine.
The schema documentation generated is therefore confusion.
I suggest either getting rid of "ToUpperInvariant()" on line 18 of EnumValueDescriptor.cs or changing line 98 on DictionaryToObjectConverter from context.Object = Enum.Parse(context.Type, s); to context.Object = Enum.Parse(context.Type, s, true); to have it ignore the case of the string being parsed.
To Reproduce
I can't find an easy reproduction case without standing up an entire schema. To see the issue in pieces, note that the test on line 51 of EnumTypeDescriptorTests.cs confirms that the values generated are capitalized and the following test:
[Fact]
public void DictionaryToObjectConverterCanParseImplicitlyAddedValues()
{
var converter = new DictionaryToObjectConverter();
var context = new DeserializationContext();
context.Type = typeof(FooEnum);
converter.Visit("BAR1", context);
}
throws the Exception
Expected behavior
The values generated for the schema should be able to be parsed when submitted as variables
context.Object = Enum.Parse(context.Type, s, true);
this one should be the fix. Do you want to make a pull request?
The GraphQL spec does not force upper-case enums but strongly urges to make enum values upper case.
Enum values are represented as unquoted names (ex. MOBILE_WEB). It is recommended that Enum values be “all caps”. Enum values are only used in contexts where the precise enumeration type is known. Therefore it’s not necessary to supply an enumeration type name in the literal.
Yup, I'll have it soon.
It looks like I was working off an old version of the code when I wrote up this bug report. 0.6.11. Looking through the code it appears that 0.7.0-preview has fixed this issue. Unfortunately because I can't figure out how the new DataLoaderRegistry is supposed to work, I can't test it.
This is fixed in 7.0.0
Great :)