Error with parsing enum values when submitted as a variable in a query
See original GitHub issueDescribe 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(KeyValuePair
2 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
This is fixed in 7.0.0
Yup, I’ll have it soon.