Carry each relation selection with its arguments through the common query layer
Refactor with no behavior change. It prepares relation aliases (#30465) and was split out of that PR so this mechanical part can be reviewed on its own.
After #30347, the GraphQL parser describes the selected relations twice: relations, a tree of which relations to load, and nestedRelationQueryArgsByFieldName, a parallel tree of their filter / orderBy / first. Every reader had to walk both in step. This PR merges them into one relationSelections tree.
Changes
- Model:
CommonRelationSelection = { fieldName, filter?, orderBy?, first?, relationSelections }, andCommonRelationSelectionsmaps a key to one of these. In this PR the key is always the field name; #30465 makes it the GraphQL response key.getRelationSelectionEntrieslists the entries. TheNestedRelationQueryArgs*types are removed. - Producer: the relation parser builds one entry per relation, with its resolved arguments and its nested selections.
- Readers move to the single tree:
- the nested relation loader;
buildColumnsToSelect/buildColumnsToReturnandgetRequiredRelationColumns;computeMaxFieldCountPerRecord;- record visibility (
collectRecordsByObjectNameSingular); - the timeline column helper;
- the group-by-with-records service;
- the object-record event publisher.
- Query runners: the
isDefined(relations)guards are gone, because the tree is always set.processQueryResult(args)takes oneCommonQueryResultProcessingArgsobject instead of five positional arguments. - Result getters:
processRecord/processRecordArraytake named fields and walk relations from the selection instead of guessing them from record keys.
Testing
- Unit: compute-max-field-count, collect-records, result getters (including file signing in nested relations), build-columns-to-select, and the relation parser. 1146 tests pass under
src/engine/api, timeline and subscriptions. - Integration suites, unchanged from #30347, all pass: nested relation query arguments, group-by with records (plus RLS), nested per-parent limit (plus RLS), relation join RLS, soft-deleted relations, mutate by relation field, message visibility, timeline, REST find-many and depth (142 tests).
- Server typecheck.
Stack
The work is split into short tracks that can be reviewed and merged in parallel. Each PR targets main or the one PR it builds on. Two PRs need several others; they target an integration branch (felix/relaxed-einstein-vxil3q-base-*, not a PR) that merges exactly their dependencies, so their diff shows only their own changes. A PR can merge once everything in its "Builds on" column is merged; retarget it to main at that point.
Size counts changed lines outside tests and generated files: S < 300, M 300–800, L > 800. Sizes are a snapshot and are not kept in sync with every push.
| Track | PR | What it does | Size | Code | Tests / generated | Builds on |
|---|---|---|---|---|---|---|
| Server: views | #30339 | Per-column settings on view fields (label, record limit) | S | +300 −2 | +703 −152 | main |
| Server: views | #30341 | A view can be owned by a one-to-many view field (scope view) | M | +584 −56 | +891 −4 | main |
| Server: views | #30472 | Lookup: a view field shows one field of its related record | M | +280 −38 | +428 −4 | #30339 |
| Server: views | #30466 | upsertViewFieldWithScope: save a column with its settings, lookup and scope in one migration (~600 lines moved out of view-widget-upsert) | L | +1330 −567 | +1117 −256 | #30339, #30341, #30472 |
| Server: views | #30450 | Expose column scopes and lookups in the view AI tools | S | +31 | +222 | #30339, #30341, #30472 |
| Server: query engine | #30347 | Honor filter / orderBy / first on nested one-to-many relations | M | +462 −86 | +509 | main |
| Server: query engine | #30473 👈 | One relation-selection tree through the common query layer (refactor, no behavior change) | L | +663 −685 | +277 −46 | #30347 |
| Server: query engine | #30465 | Each alias of a nested relation gets its own arguments and rows | L | +595 −237 | +727 −21 | #30473 |
| Front | #30468 | Query a relation under an alias with its own filter, sort and limit | S | +140 −19 | — | main |
| Front | #30469 | Don't recreate a saved sort that comes back under a new id | S | +21 −17 | +8 | main |
| Front | #30348 | Extra table columns and the Edit column panel, behind IS_COLUMN_SETTINGS_ENABLED | M | +718 −76 | +152 −30 | #30339 |
| Front | #30349 | Scope one-to-many columns from the Edit column panel | L | +1053 −92 | +316 −18 | #30348, #30466, #30468, #30469, #30465 |
| Front | #30439 | Lookup columns in the table, editable from their cells (absorbs #30440) | L | +805 −223 | +283 −30 | #30349 |
| Front | #30458 | Lookup and scoped columns on boards and calendars | M | +404 −284 | +140 −7 | #30439 |
The longest dependency chain is #30339 → #30348 → #30349 → #30439 → #30458; everything else is one or two levels deep. #30339, #30341 and #30472 each add a 2.59 instance command, so whichever merges after another may need a fresh timestamp.
Generated by Claude Code