在字段上使用 UseFiltering() 时,hotchocolate 会抛出错误

hotchocolate throws error when using UseFiltering() on a field

我有一个非常简单的 setyp,我将 graphql 放在 entityframework 数据上下文(sql 服务器)上。

我正在尝试让过滤工作。我试过将 .UseFiltering() 添加到字段描述符中,就像这样...

descriptor.Field(t => t.AccountName).Type<NonNullType<StringType>>().UseFiltering();

但是它在启动时导致这个错误...

HotChocolate.SchemaException: 'Unable to infer or resolve a schema type from the type reference Input: System.Char.'

我假设我在某处做错了...

“UseFiltering”应该用于过滤以某种方式(IQueryable、IEnumerable 等)表示项目集合的数据。 例如,如果您有用户集合并且每个用户都有 AccountName 属性 您可以按 AccountName:

过滤该集合
[ExtendObjectType(Name = "Query")]
public class UserQuery
{
    [UseFiltering]
    public async Task<IEnumerable<User>> GetUsers([Service]usersRepo)
    {
       IQueryable<User> users = usersRepo.GetUsersQueryable();
    }
}

在该示例中,过滤的 HotChocolate 实现将按用户字段生成多个过滤器,您可以按以下方式使用它们:

users(where: {AND: [{accountName_starts_with: "Tech"}, {accountName_not_ends_with: "Test"}]})

根据您的示例:系统认为 AccountName 是一个集合,因此尝试对 AccountName 包含的字符构建过滤。