Repository navigation
Conversation
Add an `include` query param (JSON:API style, e.g. `include=company.people,pointOfContactForOpportunities`) that selects specific relations up to 2 levels deep, instead of fetching every relation. It combines with `depth` and `fields`, is checked against object and field permissions at every level, and rejects unknown or unreadable relations with a 400. Share the readable-relation check between depth and include.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Confidence Score: 4/5
[Medium impact] The change affects relation selection across REST record endpoints. The existing rejection of included fields should be fixed before merging. Findings
SummaryAdds explicit REST relation paths through
Diagram%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart LR
A[REST request] --> B[Parse depth, fields, and include]
B --> C[Load readable objects and fields]
C --> D[Build field and relation selections]
D --> E[Check nested relations and query complexity]
E --> F[Read or write records]
F --> G[Load selected related records]
G --> H[REST response]
Reviews (2) · Last reviewed commit: "Support explicit depth-2 relations in th..." · Reviewed by Greptile |
| ...buildRelationSelectionFromInclude({ | ||
| includeTree, |
There was a problem hiding this comment.
GET /rest/companies?fields=id,people&include=people returns 400 instead of expanding people. REST defaults to depth=0, so validateRequestedFields rejects this one-to-many field before the new include selection runs. The same request succeeds when people is omitted from fields.
Let requested-field checks recognize relations expanded by includeTree, without requiring depth=1 and loading unrelated relations.
🤖 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 · 5 findings
High-level — The additive REST 💬 5 inline comments on the diff. Reviewed against the |
|
|
||
| // Unknown and unreadable relations share one error so the response does | ||
| // not reveal fields hidden by permissions | ||
| if (!isDefined(relationTargetObjectMetadata)) { |
There was a problem hiding this comment.
🟡 Nit · High-level · engineering architecture — production cardinality / extend existing seams
The include builder is a second relation-selection path that skips isRelationTargetExcludedFromSelection, so include=timelineActivities (or company.timelineActivities) expands the timeline relation that depth deliberately leaves out
buildRelationSelectionFromDepth skips timelineActivity because expanding it for every record turns one page into thousands of rows. ?include=company.timelineActivities on a 200-record find-many reopens that load path. Put the exclusion check in the shared getReadableRelationTargetFlatObjectMetadata, or call it in the include builder too, so the two paths can't drift apart again.
|
|
||
| const ALL_OBJECT_IDS = [PERSON_ID, COMPANY_ID, NOTE_ID]; | ||
|
|
||
| const compute = ( |
There was a problem hiding this comment.
🟡 Nit · Low-level · More than one argument means one object argument
The compute helper takes two positional arguments (includeTree and an options object) instead of a single object argument, so call sites cannot read as named parameters.
| }) | ||
| : undefined; | ||
|
|
||
| // Unknown and unreadable relations share one error so the response does |
There was a problem hiding this comment.
🟡 Nit · Low-level · A kept comment is one line
The added explanatory comment spans two // lines, but the reason (shared error so permissions aren't revealed) can be stated in one line.
Also on line 50.
| // Unknown and unreadable relations share one error so the response does | ||
| // not reveal fields hidden by permissions | ||
| if (!isDefined(relationTargetObjectMetadata)) { | ||
| throw new CommonSelectFieldsException( |
There was a problem hiding this comment.
🟡 Nit · Low-level · Exceptions take a single object parameter
The CommonSelectFieldsException is constructed with a bare template string instead of a single object parameter carrying the message.
Also on lines 53–54.
|
|
||
| const RELATION_FIELD_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9]*$/; | ||
|
|
||
| const addRelationPathToIncludeTree = ( |
There was a problem hiding this comment.
🟡 Nit · Low-level · More than one argument means one object argument
addRelationPathToIncludeTree takes two positional parameters (the tree and the path array) instead of a single object parameter with named fields.
Also on lines 15–17.
Fixes twentyhq/core-team-issues#1674
Problem
REST relations stop at
depth=1. The old depth-2 implementation pulled in every relation at both levels (75 relations forpeopleon a seeded workspace), so it timed out and ignored field-level permissions. There was no way to ask for a specific relation two levels deep.Changes
includequery param on the record endpoints, e.g.GET /rest/people?include=company.people,pointOfContactForOpportunities. Each path can be up to 2 relations deep and expands only what it names.includecombines withdepth: withdepth=1, every direct relation is expanded and theincludepaths add their nested relations. Included relations are returned even when they aren't listed infields.CommonSelectFieldsBuilder.buildFromDepth(newincludeTreeoption), next torequestedFields. The REST handlers only parse the param and pass it through.getReadableRelationTargetFlatObjectMetadata).getIsFlatFieldAJoinColumnandgetIsFlatFieldAJunctionRelationFieldnow takePick<FlatFieldMetadata, 'name' | 'settings'>. This fixes two type errors on main inbuildRelationSelectionFromDepth, which passes a narrowed field type to them.developers/extend/api.mdxdocumentinclude.Performance
The existing runner guards still apply: a one-to-many nested in another one-to-many is rejected, and the query complexity limit is enforced. Unlike
depth, an explicitincludecan expand timeline activities, since it's opt-in.Testing
engine/apiunit tests pass (1,007).