question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with parsing enum values when submitted as a variable in a query

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jbray1982commented, Jan 9, 2019

This is fixed in 7.0.0

1reaction
jbray1982commented, Jan 8, 2019

Yup, I’ll have it soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error with parsing enum values when submitted as a ...
Describe the bug Given an enum like enum Foo { Bar }, line 18 in EnumValueDescriptor.cs creates a string value that is all...
Read more >
asp.net core - Using [FromQuery] to parse enum values
I would like the C# enum value to be one thing (EnumValue01, for example), but the value in the HTTP request to be...
Read more >
Using Enums as Request Parameters in Spring
Learn how to use enums as request parameters in Spring REST controllers and how to handle exceptions triggered by invalid input.
Read more >
Enum.Parse Method (System)
Converts the string representation of the name or numeric value of one or more enumerated constants specified by TEnum to an equivalent enumerated...
Read more >
MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found