skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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>()
    

  2. 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());
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search