-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor triggerUpdateRelationsOptimisticEffect
to compute relationship from Metadatas
#9815
Refactor triggerUpdateRelationsOptimisticEffect
to compute relationship from Metadatas
#9815
Conversation
Log
|
c80242c
to
b09bdb1
Compare
4ac212c
to
cf640e6
Compare
...y-front/src/modules/apollo/optimistic-effect/utils/triggerUpdateRelationsOptimisticEffect.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR refactors the relationship handling in optimistic updates by switching from record data structure inference to metadata-based relationship computation, improving type safety and reliability.
- Added new
computeRecordsToAttachAndDetach
function in/packages/twenty-front/src/modules/apollo/optimistic-effect/utils/triggerUpdateRelationsOptimisticEffect.ts
to determine relationship changes based on metadata - Implemented proper relationship direction handling (ONE_TO_MANY, MANY_TO_ONE, etc.) using
RelationDefinitionType
enum - Enhanced type safety with explicit typing for function arguments and return values in relationship computation
- Added support for handling both connection-based and direct reference relationships through metadata
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
...y-front/src/modules/apollo/optimistic-effect/utils/triggerUpdateRelationsOptimisticEffect.ts
Outdated
Show resolved
Hide resolved
bc81a18
to
fcf12a6
Compare
@@ -7,6 +7,7 @@ export const getRecordsFromRecordConnection = <T extends ObjectRecord>({ | |||
}: { | |||
recordConnection: RecordGqlConnection; | |||
}): T[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remark: Unless I'm mistaken this function could return undefined
}: {
recordConnection: RecordGqlConnection;
}): T[] | undefined => {
if (shouldAttachSourceToAllTargets) { | ||
targetRecordsToAttachTo.forEach((targetRecordToAttachTo) => | ||
// Could it be an invariant ? | ||
if (isDefined(updatedSourceRecord)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remark: This could be an invariant, but implicitly quite though to tell TypeScript
objectMetadataItems, | ||
}); | ||
// Could it be an invariant ? | ||
} else if (isDefined(currentSourceRecord)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remark: This could be an invariant, but implicitly quite though to tell TypeScript
746ae2d
to
8cf4115
Compare
8cf4115
to
cca0c89
Compare
About to create an issue regarding the possible cache corruption due to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
(updates since last review)
This PR continues the refactoring of relationship handling by simplifying the logic and adding robust testing for relationship type determination.
- Added comprehensive test coverage in
isObjectRecordConnection.test.ts
for all relation definition types (MANY_TO_MANY, ONE_TO_MANY, etc.) - Simplified
isObjectRecordConnection
to make decisions purely based on relation direction metadata - Added edge case handling for array injection in cache through
extractTargetRecordsFromRelation
function - Improved error handling with explicit checks for unknown relation directions
3 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile
...wenty-front/src/modules/object-record/cache/utils/__tests__/isObjectRecordConnection.test.ts
Outdated
Show resolved
Hide resolved
...wenty-front/src/modules/object-record/cache/utils/__tests__/isObjectRecordConnection.test.ts
Outdated
Show resolved
Hide resolved
...y-front/src/modules/apollo/optimistic-effect/utils/triggerUpdateRelationsOptimisticEffect.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/object-record/cache/utils/isObjectRecordConnection.ts
Show resolved
Hide resolved
LGTM too |
Introduction
At the moment the relationships are inferred from the record data structure instead of its metadatas
We should refactor the code that computes or not the necessity to detach a relation on a mutation
We've refactored the
isObjectRecordConnection
method to be consuming arelationDefintion
instead of "typeChecking" at the runtime the data structure using zod validation schemaRelated to #9580