【问题标题】:GraphQl LightHouse Where Condition not workingGraphQl LightHouse Where Condition 不工作
【发布时间】:2021-09-26 08:04:50
【问题描述】:

如何在查询中添加where 条件?

projects: [Project!]! @all @orderBy(column: "id", direction: DESC)

我想要:

projects: [Project!]! @all @orderBy(column: "id", direction: DESC) @where('parent_id','=',0)

【问题讨论】:

    标签: laravel graphql laravel-lighthouse


    【解决方案1】:

    https://lighthouse-php.com/5/api-reference/directives.html#all 查看@all 指令上的scope 参数并了解https://laravel.com/docs/8.x/eloquent#query-scopes。这就是你需要的。 @where 指令只能在参数上传递。

    【讨论】:

    • @Bartomiej Gajda 实际上不需要。对于范围在下面添加了我的答案
    【解决方案2】:

    您可以将@where 与可选的Int 放在一起,并使用指令@orderBy 添加orderBy 属性,例如:

    projects(
        parent_id: Int @where(key: "parent_id")
        orderBy: _@orderBy(columns: ["id"])
    ): [Project!]! 
        @all
    

    【讨论】:

      【解决方案3】:
      Adding a where condition was too easy but was not clear in lighthouse docs.
      
      projects(query: QueryCondition): [Project!]!
              @all
              @orderBy(column: "id", direction: DESC)
      
      input QueryCondition {
          parent_id: ID @eq
      }
      

      【讨论】:

        猜你喜欢
        • 2018-09-20
        • 1970-01-01
        • 2019-12-02
        • 2020-04-20
        • 1970-01-01
        • 2022-11-05
        • 2022-07-12
        • 1970-01-01
        • 2018-07-10
        相关资源
        最近更新 更多