【问题标题】:Laravel Lighthouse paginate field resultLaravel Lighthouse 分页字段结果
【发布时间】:2020-08-23 14:41:43
【问题描述】:

我在灯塔中定义了一个查询:

extend type Query {
    products(input: ListInput @spread): [Product]
        @field(resolver: "App\\GraphQL\\Queries\\BusinessInformation\\ProductComplex@index")
}

但是products 的结果没有分页。我不能同时使用@field@paginate,因为应该只有一个解析器。如何使用自定义解析器对 eloquent 查询进行分页?

我已经搜索并发现可以使用我 builder,但是当我定义了适当的模型时,我不想使用查询构建器。

【问题讨论】:

  • 你解决了吗?如果你这样做了,你介意自己回答这个问题吗?我正在为同样的事情苦苦挣扎。

标签: laravel graphql lighthouse laravel-lighthouse


【解决方案1】:

我设法找到了解决方案:

extend type Query {
    products(captionId: ID, subFieldId: ID, q: String): [Product]
    @paginate(type: "paginator" defaultCount: 10 maxCount: 100
        builder: "App\\GraphQL\\Queries\\CustomerManagement\\TariffBook\\ProductComplex@index")
}

只需要在paginate 指令中使用builder

【讨论】:

    【解决方案2】:

    只需将分页添加到您的查询$posts = DB::table('posts')->paginate(12);

    此外,您还可以在这里找到解决此问题的几种方法: How to use pagination with laravel DB::select query

    欢呼。

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 2020-12-31
      • 2017-02-24
      • 2015-07-17
      • 1970-01-01
      • 2017-01-12
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多