简体   繁体   中英

Could not resolve Char Type in Graphql HotChocolate

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM