nuwave / nuwave/lighthouse

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

Open
#2,473 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs reproduction
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

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
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Schema/Directives/RelationDirectiveHelpers.php at the builder code linked in the report, and reproduce the @hasMany, @orderBy, and @with combination described in the steps. Check how the related load inherits the original query ordering. Done means the generated related query no longer contains the original orderBy clause and the reported relation query succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.