【问题标题】:hotchocolate throws error when using UseFiltering() on a field在字段上使用 UseFiltering() 时 hotchocolate 抛出错误
【发布时间】:2020-07-17 04:03:37
【问题描述】:

我有一个非常简单的 setyp,我将 graphql 放在实体框架数据上下文(sql server)上。

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

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

但它在启动时会导致此错误...

HotChocolate.SchemaException: '无法推断或解析架构 从类型引用 Input: System.Char 中键入。'

我认为我在某处做错了什么......

【问题讨论】:

    标签: graphql hotchocolate


    【解决方案1】:

    “UseFiltering”应该用于过滤以某种方式(IQueryable、IEnumerable 等)表示项目集合的数据。 例如,如果您有 users 集合并且每个用户都有 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 所包含的字符进行过滤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 2015-04-03
      • 2011-05-08
      相关资源
      最近更新 更多