Repository navigation
Let findMany read records through a view - #32465
FelixMalfait wants to merge 3 commits into
Conversation
A record list rendered outside Twenty (an MCP App, an app's front component) should show a view's records as the record table does, without reimplementing how views turn into queries. groupBy already accepts a viewId for its filters; findMany now accepts one too. - `findMany(viewId)` combines the caller's filter with the view's filters, preset filter and search text. When the caller passes no orderBy, the records come back in the view's order, resolved in computeArgs so cursors encode the order rows come back in. - groupBy's view filter building moves into `ViewRecordQueryService`, shared by both runners. A view that is missing or belongs to another object is now rejected instead of silently filtering on nothing. - `computeRecordGqlOperationOrderByFromFlatMaps` moves from the workflow module to `engine/utils`, next to its filter counterpart, and becomes the server's single sorts-to-orderBy translation. It gains relation target sorts and orders unsorted records by position, as the record table does. `computeViewSortsOrderBy` is removed: it produced orderBys strict validation rejects for composite fields, so `get_view_query_parameters` now returns the table's order. - REST find-many accepts `view_id`. The REST viewId parser read `viewId` while OpenAPI documents `view_id` like every other query parameter, so the documented name now works and `viewId` no longer does.
…felix/wizardly-sagan-upeo1x-find-view-filters
|
🚀 Preview Environment Ready! Your preview environment is available at: https://gardening-exciting-supervisor-briefs.trycloudflare.com This environment will automatically shut down after 5 hours. |
|
Let's rebase this one to target main so that we can merge it directly |
🤖 PR Review
🛡️ Security Review✅ No high-severity vulnerabilities detected. 🚦 Auto-approve🙋 Manual review recommended for the following reason(s):
Automated pre-review — human approval still required. |
🟡 Quality review · 13 findings
High-level — Pulling the view filter and sort logic into ViewRecordQueryService and moving the order-by util into engine fits the architecture, but the REST viewId→view_id rename silently changes group-by and the new view lookup skips the visibility check that an existing ViewService method already does. 💬 12 inline comments on the diff. Not tied to a specific line
Reviewed against the |
| ) { | ||
| return undefined; | ||
| } | ||
| const viewId = request.query.view_id; |
There was a problem hiding this comment.
🟡 Nit · High-level · deploy strategy
The shared REST parser now reads view_id instead of viewId, which silently changes the existing group-by REST endpoint
REST group-by clients that send ?viewId= (rest-api-group-by.handler.ts:86) get no error after deploy: the view's filters are dropped and they get aggregates over the whole table. Keep accepting viewId as a deprecated alias next to view_id, or call out the breaking change in the PR description.
There was a problem hiding this comment.
Intentional: view_id is the documented REST parameter and the undocumented viewId spelling is dropped on purpose, as acknowledged on this PR. Leaving it without an alias.
Generated by Claude Code
| operand: viewFilter.operand, | ||
| recordFilterGroupId: viewFilter.viewFilterGroupId, | ||
| positionInRecordFilterGroup: viewFilter.positionInViewFilterGroup, | ||
| subFieldName: viewFilter.subFieldName as CompositeFieldSubFieldName, |
There was a problem hiding this comment.
🟡 Nit · Low-level · No as casts
The added lines use as casts (including as unknown as) to force types onto subFieldName, logicalOperator and the options array instead of fixing the types or adding a mapper.
Also on lines 124, 142.
There was a problem hiding this comment.
These casts come over unchanged from the group-by runner on main (the logicalOperator one points at #14746). Typing them properly belongs with that issue rather than in this move, so I am leaving them.
Generated by Claude Code
| it('should return undefined if viewId missing', () => { | ||
| const request: any = { query: {} }; | ||
| const buildRequest = (query: AuthenticatedRequest['query']) => | ||
| ({ query }) as AuthenticatedRequest; |
There was a problem hiding this comment.
🟡 Nit · Low-level · No as casts · A cast in a spec is a signature bug
The added helper uses ({ query }) as AuthenticatedRequest to force a partial object into the full request type.
There was a problem hiding this comment.
This partial-request cast is the pattern the existing spec on main already uses for this parser; leaving it as is.
Generated by Claude Code
| !isDefined(flatFieldMetadata) || | ||
| flatFieldMetadata.objectMetadataId !== flatObjectMetadata.id | ||
| ) { | ||
| throw new Error( |
There was a problem hiding this comment.
🟡 Nit · Low-level · Throw CustomException, never a generic Error``
The added code throws a generic Error instead of the module's CustomException.
Also on lines 88–89.
There was a problem hiding this comment.
This throw comes over unchanged from the workflow util that moved here; changing its exception type would change the errors workflow steps surface, so it stays out of this PR.
Generated by Claude Code
| ) as ObjectRecordOrderBy; | ||
| : sortsOrderBy; | ||
|
|
||
| return orderBy.length > 0 ? (orderBy as ObjectRecordOrderBy) : undefined; |
There was a problem hiding this comment.
🟡 Nit · Low-level · No as casts
The added return line uses as ObjectRecordOrderBy to force the type instead of fixing the array's type or using a mapper.
There was a problem hiding this comment.
Carried over unchanged from the workflow util on main; leaving it with the move.
Generated by Claude Code
Confidence Score: 4/5
[High impact] The PR changes how several server query paths apply views and order records. Fix the date-filter timezone mismatch before merging so external views show the same records as Twenty. Findings
SummaryAdds
Intentional changes acknowledged by FelixMalfait:
Diagram%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart TD
A[GraphQL viewId or REST view_id] --> B[findMany computeArgs]
B --> C[Use caller sort or view sort]
C --> D[Combine caller filter with view filters, preset, and search]
D --> E[Apply field-read checks]
E --> F[Fetch records and build cursors]
Reviews (1) · Last reviewed commit: "Merge branch 'felix/wizardly-sagan-upeo1..." · Reviewed by Greptile |
TODOs/FIXMEs:
|
Stack (MCP Apps, Twenty as an MCP Apps server), merge in order: 1. runtime → 2. resources → 3. tool binding → 4. generic mode → 5. findMany through a view → 6. View Cards app.
What
A record list rendered outside Twenty (an MCP App, an app's front component) should show a view's records the way the record table does, without reimplementing how views turn into queries. groupBy already accepts a
viewIdfor its filters; findMany now accepts one too, over GraphQL and REST.Changes
findMany(viewId)combines the caller's filter with the view's filters, preset filter and search text. When the caller passes no orderBy, records come back in the view's order. That order is resolved incomputeArgs, so cursors encode the order rows come back in.ViewRecordQueryService, which both runners share.computeRecordGqlOperationOrderByFromFlatMapsmoves from the workflow module toengine/utils, next to its filter counterpart, and becomes the server's single sorts-to-orderBy translation. It gains relation-target sorts, and orders unsorted records by position, as the record table does.computeViewSortsOrderByis removed.Behaviour changes
view_id(breaking, undocumented usage). The REST parser readviewIdwhile OpenAPI documentsview_id, like every other query parameter. The documented name now works andviewIdno longer does.computeViewSortsOrderByproduced orderBys that strict validation rejects for composite fields, soget_view_query_parametersnow returns the table's order (e.g.[{ name: 'DescNullsLast' }, { position: 'AscNullsFirst' }]).Tests
find-many-with-view.integration-spec.tscovers seven cases:view_id;The orderBy util spec covers the moved translation, and the MCP view tools suite is updated.
https://claude.ai/code/session_01BC19MT31DvLYvxzeBBUKWi
Generated by Claude Code