Apply filter, orderBy and first on nested one-to-many connections
Merged
FE
1d ago+1158+1158+0123456789012345678901234567890123456789-120-120-012345678901234567890123456789
The workspace GraphQL schema already declares filter, orderBy, first (and cursor/offset args) on one-to-many relation fields, but the query runners dropped them: nested connections returned up to 60 unordered, unfiltered records per parent. This PR applies those arguments per parent, keyed by the relation's field name. It has no knowledge of columns or views.
Changes
- Argument collection: resolvers collect field arguments with variables resolved, per field name, through one
getResolverSelectedFieldscollector; it replaces thegraphql-fieldsdependency, which is removed. Direct execution formats its results from the same collector, so the formatter and the resolver read a request the same way. - Aliases: aliases of one relation share a selection and its arguments. Aliases of one field with different arguments are rejected with
INVALID_QUERY_INPUTinstead of one silently winning. - Validation at parse time: the selected-fields parser validates nested arguments with the root filter and orderBy processors at every depth, so a malformed value fails with
INVALID_QUERY_INPUTbefore a mutation writes anything. - Applied per parent: filter and order run in the per-parent
LATERALsubquery with an id tie-breaker (also whenfirstcomes withoutorderBy, so the limit is deterministic) andLIMIT min(first, 60); the hydration query is ordered the same way. Row-level permissions still apply;first: 0returns nothing. - Aggregates: nested
totalCountand aggregates honour the filter and are read per parent, sofirst: 1still reports the full count. The nested aggregate query is skipped when no aggregates are requested. - Soft delete: the id and hydration queries apply the same
deletedAtrule. - Fix: relations nested under a to-one relation (e.g.
people { company { people } }) came back empty because the to-one record was assigned as a copy before its own relations loaded. - Unchanged:
last,before,after,offsetstay accepted and ignored on nested connections.
Behaviour change: nested filter / orderBy / first used to be ignored and are now applied. No caller in the repo sends them today.
Stack
Standalone, on main. It is not needed by the lookup columns stack (#30472 → #30348 → #30439).
Testing
- Integration
nested-relation-query-arguments: filter, order and limit per parent;firstwithoutorderBylimited by id; variables; order by a relation field; cursor args ignored; filteredtotalCount; arguments through a to-one relation; malformed arguments rejected, including before a mutation runs; aliases of one relation with different arguments rejected. - Integration
message-visibility,group-by-with-records-resolver,nested-relation-per-parent-limit(-rls),soft-deleted-relationpass. - Unit: argument collection (variables, conflicting alias arguments,
Object.prototypenot polluted), nested argument extraction.
Generated by Claude Code