0

How to add a where condition in query?

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

I'd like to have:

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

3 Answers3

1

https://lighthouse-php.com/5/api-reference/directives.html#all Look at scope argument on @all directive and read about https://laravel.com/docs/8.x/eloquent#query-scopes. This is what you need. @where directive can be passed only on arguments.

0

You can put the @where with an optional Int and add a orderBy attribute with directive @orderBy like:

projects(
    parent_id: Int @where(key: "parent_id")
    orderBy: _@orderBy(columns: ["id"])
): [Project!]! 
    @all
francisco
  • 1,387
  • 2
  • 12
  • 23
0
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
}