Apply filter, orderBy and first on nested one-to-many connections

Merged
FE
1d ago
+1158-120

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 getResolverSelectedFields collector; it replaces the graphql-fields dependency, 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_INPUT instead 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_INPUT before a mutation writes anything.
  • Applied per parent: filter and order run in the per-parent LATERAL subquery with an id tie-breaker (also when first comes without orderBy, so the limit is deterministic) and LIMIT min(first, 60); the hydration query is ordered the same way. Row-level permissions still apply; first: 0 returns nothing.
  • Aggregates: nested totalCount and aggregates honour the filter and are read per parent, so first: 1 still 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 deletedAt rule.
  • 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, offset stay 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; first without orderBy limited by id; variables; order by a relation field; cursor args ignored; filtered totalCount; 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-relation pass.
  • Unit: argument collection (variables, conflicting alias arguments, Object.prototype not polluted), nested argument extraction.

Generated by Claude Code