我用的是热巧克力图形。我有一个场景,其中有两个单独的查询类型类。
我的文件夹结构

这就是我如何配置它
.AddAuthorization()
//for inmemory subscription
.AddInMemorySubscriptions()
.AddQueryType<PostQuery>()
.AddQueryType<UserQuery>()
.AddMutationType<Mutation>()
.AddSubscriptionType<Subscription>()
.AddGlobalObjectIdentification()
// Registers the filter convention of MongoDB
.AddMongoDbFiltering()
// Registers the sorting convention of MongoDB
.AddMongoDbSorting()
// Registers the projection convention of MongoDB
.AddMongoDbProjections()
// Registers the paging providers of MongoDB
.AddMongoDbPagingProviders();但是,我得到了以下错误
System.ArgumentException: The root type `Query` has already been registered不管怎么说,它是否可以被配置,或者我必须把所有的东西放在一个类中?
发布于 2022-08-23 09:47:57
您需要注册querytype "Query“,并添加解析器来处理"Query”类型的多个模式。
builder.Services
.AddQueryType(q => q.Name("Query"))
.AddType<PostQuery>()
.AddType<UserQuery>()在查询类中:
[ExtendObjectType("Query")]
public class PostQuery
{
public List<Post> GetAllPosts()
{
return List<Post>{...};
}
}
[ExtendObjectType("Query")]
public class UserQuery
{
public List<User> GetAllUsers()
{
return List<User>{...};
}
}https://stackoverflow.com/questions/73452881
复制相似问题