簡體   English   中英

無法解析 Graphql HotChocolate 中的字符類型

[英]Could not resolve Char Type in Graphql HotChocolate

如果我嘗試使用 graphQl 公開 class ,則會出現以下錯誤。 我知道這個錯誤是由於我使用的 char 類型造成的,但我無法更改結構。

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

這是我的 class 結構

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

任何幫助,將不勝感激。 提前致謝。

在 GraphQL 中沒有 char 類型。 如果需要,您可以將其顯式綁定到字符串。 啟動文件中添加以下行

services.AddGraphQLServer()     
.BindRuntimeType<char, StringType>()

可以通過將 char 綁定到 graphQl 的 StringType 並添加一個從 char 到字符串的 TypeConverter 來解決該錯誤。 這應該在builder.Services中完成,如下所示

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM