graphql-dotnet/conventions

Error when using optional nullable enums

Cherepoc opened this issue · 3 comments

Having this in my input type:
public Optional<MyEnum?> Num { get; set; }
Gives me this message when trying to execute the request:
System.ArgumentException: Type provided must be an Enum.
Parameter name: enumType
at System.RuntimeType.GetEnumNames()
at GraphQL.Conventions.Types.Resolution.ObjectReflector.GetEnumValues(TypeInfo typeInfo)

Removing Optional works fine.

I believed that Nullable<MyEnum> is optional by itself in opposite to just MyEnum, doesn't it?

It's optional, but still in graphql there's a difference between not providing a value versus explicitly providing a null, and just having a nullable type does not let you differentiate between those two cases, which is why Optional type was added. See #128

tlil commented

Marked as "won't fix" - but if you wanted to hazard a try, I'm happy to accept a PR.