nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.37k stars 439 forks source link

`@with` inherit `@orderBy` clause of original query #2473

Open exodusanto opened 1 year ago

exodusanto commented 1 year ago

Describe the bug

Seems like the @with inherit @orderBy clause of original query, so if the column doesn't exists also in relation it will fail the query

Maybe the solution is to only add ->reorder() on the builder

Expected behavior/Solution

The ->load should not contain orderBy clause

Steps to reproduce

  1. Create a @hasMany relation on a model
  2. Add @orderBy to args
  3. Add @with to another relation on the same model

Output/Logs

Click to expand ```sql select `users`.*, `circles`.`user_id` as `pivot_user_id`, `circles`.`peer_id` as `pivot_peer_id`, `circles`.`created_at` as `pivot_created_at`, `circles`.`updated_at` as `pivot_updated_at` from `users` inner join `circles` on `users`.`id` = `circles`.`peer_id` where `circles`.`user_id` in (31) order by `created_at` desc ```

**Lighthouse Version** `v6.22.0`
spawnia commented 12 months ago

Could you add a failing test case? Not exactly sure where best to put it since multiple directives are concerned, feel free to choose among WithDirectiveTest, OrderByDirectiveDBTest or HasManyDirectiveTest: