Skip to content

Let findMany read records through a view - #32465

Open
FelixMalfait wants to merge 3 commits into
felix/wizardly-sagan-upeo1x-mcp-app-generic-modefrom
felix/wizardly-sagan-upeo1x-find-view-filters
Open

FelixMalfait wants to merge 3 commits into
felix/wizardly-sagan-upeo1x-mcp-app-generic-modefrom
felix/wizardly-sagan-upeo1x-find-view-filters

Conversation

@FelixMalfait

@FelixMalfait FelixMalfait commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

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 viewId for 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 in computeArgs, so cursors encode the order rows come back in.
  • groupBy's view-filter building moves into ViewRecordQueryService, which both runners share.
  • 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.

Behaviour changes

  • REST view_id (breaking, undocumented usage). The REST parser read viewId while OpenAPI documents view_id, like every other query parameter. The documented name now works and viewId no longer does.
  • Missing or foreign views are rejected. groupBy with a view that is missing or belongs to another object used to filter on nothing silently. It now returns an input error, and findMany does the same.
  • Composite sorts. computeViewSortsOrderBy produced orderBys that strict validation rejects for composite fields, so get_view_query_parameters now returns the table's order (e.g. [{ name: 'DescNullsLast' }, { position: 'AscNullsFirst' }]).
  • Workflow "find records" with no sort now orders by position when the object has one, matching the table, instead of leaving the order unspecified.

Tests

find-many-with-view.integration-spec.ts covers seven cases:

  • view filters combined with search;
  • the view's sort order;
  • an explicit orderBy overriding the view's;
  • REST view_id;
  • another object's view, rejected;
  • an unknown view, rejected;
  • groupBy with another object's view, rejected.

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

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
@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

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

@FelixMalfait
FelixMalfait marked this pull request as ready for review December 5, 2026 13:38
@FelixMalfait

Copy link
Copy Markdown
Member Author

Let's rebase this one to target main so that we can merge it directly

@twenty-ci-bot-public

Copy link
Copy Markdown

🤖 PR Review

Check Result
🔍 Build safety ⏭️ skipped — external-only
🧭 Triage ⏭️ skipped — external-only
📐 Quality ✅ passed — 13 nit(s)
🛡️ Security ✅ passed
🚦 Auto-approve 👀 needs review — Complexity is high
🔐 Permissions ⏭️ skipped: no endpoint permission change

🛡️ Security Review

✅ No high-severity vulnerabilities detected.


🚦 Auto-approve

🙋 Manual review recommended for the following reason(s):

  • Complexity is high

  • 🧠 Complexity: high

  • 📏 Size: +710 / -431 lines across 22 file(s)


View details

Automated pre-review — human approval still required.

@twenty-ci-bot-public

Copy link
Copy Markdown

🟡 Quality review · 13 findings

Mergeable after a look at two non-blocking issues, both in the rollout and the view lookup

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.
Low-level — 11 rule violations found — 1306 rule questions over 25 piece(s) of 20 file(s)

💬 12 inline comments on the diff.

Not tied to a specific line

  • 🟡 Nit · High-level · extend existing seams — packages/twenty-server/src/engine/api/common/common-query-runners/view/services/view-record-query.service.ts:516
    findViewOfObjectOrThrow adds a second view lookup next to ViewService.findByIdVisibleToCallerOrThrow (view.service.ts:566) and skips its visibility check. With viewId now on every findMany (GraphQL and REST), a caller can apply another user's private view filters and sorts, and only the preset filter and search text are gated. Add the object check to the existing visible-to-caller lookup and reuse it here, or explain why private views should be usable.

Reviewed against the pr-review standard — high-level then low-level. Advisory; human review still required. Run details.

) {
return undefined;
}
const viewId = request.query.view_id;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carried over unchanged from the workflow util on main; leaving it with the move.


Generated by Claude Code

@greptile-apps

greptile-apps Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[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

  1. P1 Date filters use the wrong timezone ▶

Summary

Adds viewId to findMany over GraphQL and REST.

  • Find-many returns records that match a view and its saved order.
  • GroupBy uses the shared view rules and rejects views it cannot apply.
  • View and workflow queries use the same sort rules and position order.

Intentional changes acknowledged by FelixMalfait:

  • Removes undocumented REST viewId usage in favor of documented view_id.
  • Rejects missing views and views belonging to another object, including in groupBy.
  • Orders unsorted workflow records by position.

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

Reviews (1) · Last reviewed commit: "Merge branch 'felix/wizardly-sagan-upeo1..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

TODOs/FIXMEs:

  • // TODO - NOT filter not supported for record groups #14746: packages/twenty-server/src/engine/api/common/common-query-runners/common-group-by-query-runner.service.ts
  • // TODO: see if we use workspace member timezone here: packages/twenty-server/src/engine/api/common/common-query-runners/common-group-by-query-runner.service.ts

Generated by 🚫 dangerJS against 7152ae7

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant