0

If I try to expose a class using graphQl I'm getting below error. I know this error is due to char type that I'm using, but I cannot change the structure.

HotChocolate.SchemaException: For more details look at the Errors` property.

Unable to infer or resolve a schema type from the type reference Output: Char.

at HotChocolate.Configuration.TypeInitializer.DiscoverTypes()
at HotChocolate.Configuration.TypeInitializer.Initialize()

This is my class structure

class Room{
 [StringLength(1)]
 public char RoomStatus { get; set; }
}

Any help would be appreciated. Thanks in advance.

Gowtham Raj
  • 103
  • 8

2 Answers2

1

In GraphQL there is no char type. You can explicitly bind it to string if you want to. In Startup file add below line

services.AddGraphQLServer()     
.BindRuntimeType<char, StringType>()
Gowtham Raj
  • 103
  • 8
0

The error can be resolved by binding char to StringType of graphQl and adding a TypeConverter from char to string. This should be done in the builder.Services as follows

builder.Services.
AddGraphQLServer().
BindRuntimeType<char, StringType>().
AddTypeConverter<char, string>(from => from.ToString());