我正在使用星球大战示例测试 HotChocolate。
我添加了 Enityframework 和 sql nuggets,并将所有内容与名为“Merchants”的表连接起来。
到目前为止,一切正常,我可以使用 Graphiql 查询我的商家表。
我的问题是当我像这样在 startup.cs 中添加商家类型时:
services.AddGraphQL(sp => SchemaBuilder.New()
.AddServices(sp)
// Adds the authorize directive and
// enable the authorization middleware.
.AddAuthorizeDirectiveType()
.AddQueryType<QueryType>()
.AddMutationType<MutationType>()
.AddSubscriptionType<SubscriptionType>()
.AddType<HumanType>()
.AddType<DroidType>()
.AddType<EpisodeType>()
.AddType<MerchantType>() ///----> My addition
.Create(),
new QueryExecutionOptions
{
TracingPreference = TracingPreference.Always
});
这是类型
public class MerchantType : ObjectType<Merchant>
{
protected override void Configure(IObjectTypeDescriptor<Merchant> descriptor)
{
descriptor.Name("Merchant");
descriptor.Field("Id")
.Type<NonNullType<StringType>>();
descriptor.Field("MerchantName")
.Type<StringType>();
descriptor.Field("MerchantSlogan")
.Type<StringType>();
}
}
我的应用程序启动后立即收到此错误:
HotChocolate.SchemaException: 'Multiple schema errors occured:
The field `Merchant.Id` has no resolver. - Type: Merchant
The field `Merchant.MerchantName` has no resolver. - Type: Merchant
The field `Merchant.MerchantSlogan` has no resolver. - Type: Merchant
'
我需要为每个字段实现解析器吗?即使我没有更改数据。