我声明了(UserQuery)和(PostQuery),如下所示:
namespace Blogging.API.Query
{
[ExtendObjectType("Query")]
public class UserQuery
{
[UseFiltering]
[UseSorting]
public async Task<List<User>> GetAll([Service] IUserResolver resolver)
{
return await resolver.GetAll();
}
public async Task<User> GetById([Service] IUserResolver resolver,int id)
{
return await resolver.GetById(id);
}
}
}
namespace Blogging.API.Query
{
[ExtendObjectType("Query")]
public class PostQuery
{
private readonly IPostResolver _postResolver;
public PostQuery(IPostResolver postResolver)
{
_postResolver = postResolver;
}
[UseFiltering]
[UseSorting]
public Task<List<Post>> GetAll()
{
return _postResolver.GetAll();
}
public async Task<Post> GetById(int id)
{
return await _postResolver.GetById(id);
}
[UseFiltering]
[UseSorting]
public async Task<List<Post>> GetUserPosts(int userId)
{
return _=await _postResolver.GetUserPosts(userId);
}
}
}
并在program.cs中配置它们,如下所示:
builder.Services
.AddGraphQLServer()
.AddQueryType(q=>q.Name("Query"))
.AddType<UserQuery>()
.AddType<PostQuery>()
.AddFiltering().AddSorting();
但是当我打开 /graphql 时,它给了我(没有架构),而如果我删除了其中一个查询类,它会显示架构!
我想知道这有什么问题。
尝试重命名方法 GetAll 和 GetById - 两者都在查询类中可用。 GraphQL 需要唯一的方法名称。