Skip to content

Commit 4a5ffcc

Browse files
carbonFibreCodeArun kumarlucasbordeau
authored
[Fix] Bug with one to many update in table #16340 (#17416)
fixes #16340 we are updating the cache partially to prevent the flow of the corrupted fields into the cache the fields get corrupted during the mutation process potentially overriding the recoil cache as we are passing the `newRecordCache` directly in `upsertRecordsInStore`, the newRecordCache is thin and hence the recoil wipes out the fields that are undefined or empty we prevent this by extracting the partial data ( only the data which is being updated in the field ) and passing it to `upsertRecordsInStore`, as it only touched the specific fields and updates the data, leaving the other fields untouched. https://github.com/user-attachments/assets/5256bef7-70c3-47b3-b2ce-dd02ee1a2de8 --------- Co-authored-by: Arun kumar <arunkumar@Aruns-MacBook-Air.local> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
1 parent 406e269 commit 4a5ffcc

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

packages/twenty-front/src/modules/object-record/graphql/record-gql-fields/utils/__tests__/__snapshots__/generateDepthRecordGqlFieldsFromObject.test.ts.snap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`generateDepthRecordGqlFieldsFromObject should generate depth one record gql fields from object 1`] = `
44
{
@@ -29,6 +29,10 @@ exports[`generateDepthRecordGqlFieldsFromObject should generate depth one record
2929
"name": true,
3030
"noteTargets": {
3131
"id": true,
32+
"note": {
33+
"id": true,
34+
"title": true,
35+
},
3236
},
3337
"opportunities": {
3438
"id": true,
@@ -44,6 +48,10 @@ exports[`generateDepthRecordGqlFieldsFromObject should generate depth one record
4448
"tagline": true,
4549
"taskTargets": {
4650
"id": true,
51+
"task": {
52+
"id": true,
53+
"title": true,
54+
},
4755
},
4856
"timelineActivities": {
4957
"id": true,

packages/twenty-front/src/modules/object-record/graphql/record-gql-fields/utils/generateDepthRecordGqlFieldsFromFields.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
2+
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
13
import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
24
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
35
import { getImageIdentifierFieldMetadataItem } from '@/object-metadata/utils/getImageIdentifierFieldMetadataItem';
46
import { getLabelIdentifierFieldMetadataItem } from '@/object-metadata/utils/getLabelIdentifierFieldMetadataItem';
57
import { type RecordGqlFields } from '@/object-record/graphql/record-gql-fields/types/RecordGqlFields';
8+
import { generateActivityTargetGqlFields } from '@/object-record/graphql/record-gql-fields/utils/generateActivityTargetGqlFields';
69
import { generateJunctionRelationGqlFields } from '@/object-record/graphql/record-gql-fields/utils/generateJunctionRelationGqlFields';
710
import { isJunctionRelationField } from '@/object-record/record-field/ui/utils/junction/isJunctionRelationField';
811
import { FieldMetadataType, RelationType } from 'twenty-shared/types';
@@ -54,6 +57,28 @@ export const generateDepthRecordGqlFieldsFromFields = ({
5457
);
5558
}
5659

60+
const isActivityTargetField =
61+
fieldMetadata.name === CoreObjectNamePlural.NoteTarget ||
62+
fieldMetadata.name === CoreObjectNamePlural.TaskTarget;
63+
64+
if (isActivityTargetField && depth === 1) {
65+
const activityTargetObjectNameSingular =
66+
fieldMetadata.name === CoreObjectNamePlural.NoteTarget
67+
? CoreObjectNameSingular.Note
68+
: CoreObjectNameSingular.Task;
69+
70+
const activityTargetGqlFields = generateActivityTargetGqlFields({
71+
activityObjectNameSingular: activityTargetObjectNameSingular,
72+
objectMetadataItems,
73+
loadRelations: 'activity',
74+
});
75+
76+
return {
77+
...recordGqlFields,
78+
[fieldMetadata.name]: activityTargetGqlFields,
79+
};
80+
}
81+
5782
if (isJunctionRelationField(fieldMetadata)) {
5883
const junctionGqlFields = generateJunctionRelationGqlFields({
5984
fieldMetadataItem: fieldMetadata,

packages/twenty-front/src/modules/object-record/hooks/__mocks__/personFragments.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ export const PERSON_FRAGMENT_WITH_DEPTH_ONE_RELATIONS = `
129129
node {
130130
__typename
131131
id
132+
note {
133+
__typename
134+
id
135+
title
136+
}
132137
}
133138
}
134139
}
@@ -154,6 +159,11 @@ export const PERSON_FRAGMENT_WITH_DEPTH_ONE_RELATIONS = `
154159
node {
155160
__typename
156161
id
162+
task {
163+
__typename
164+
id
165+
title
166+
}
157167
}
158168
}
159169
}

0 commit comments

Comments
 (0)