Added relations to SSE events (#17683)
Fixes https://github.com/twentyhq/core-team-issues/issues/2192 This PR implements what is necessary to re-create the query that we build on the frontend to obtain the returned object record from a mutation, but on the backend, which was only partially implemented for REST API. Usually we want to have relations with only their id and label identifier field to have lighter payloads. In the event we only had depth 0 fields, with this PR we have all events with depth 1 relations. We have depth 2 for many-to-many cases, like updateOne or updateMany result : - Junction tables - Activity target tables
This commit is contained in:
-42
@@ -255,46 +255,4 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
`"Should never occur, encountered unknown fields unknwon, foo, bar in objectMetadataItem person"`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error if recordInput contains both the relationFieldId and relationField', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
expect(() =>
|
||||
computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
objectMetadataItems: generatedMockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
recordInput: {
|
||||
companyId: '123',
|
||||
company: {},
|
||||
},
|
||||
cache,
|
||||
objectPermissionsByObjectMetadataId: {},
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Should never provide relation mutation through anything else than the fieldId e.g companyId and not company, encountered: company"`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error if recordInput contains both the relationFieldId and relationField even if null', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
expect(() =>
|
||||
computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
objectMetadataItems: generatedMockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
recordInput: {
|
||||
companyId: '123',
|
||||
company: null,
|
||||
},
|
||||
cache,
|
||||
objectPermissionsByObjectMetadataId: {},
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Should never provide relation mutation through anything else than the fieldId e.g companyId and not company, encountered: company"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
-12
@@ -140,12 +140,6 @@ export const computeOptimisticRecordFromInput = ({
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isUndefined(recordInputFieldValue)) {
|
||||
throw new Error(
|
||||
`Should never provide relation mutation through anything else than the fieldId e.g companyId and not company, encountered: ${fieldMetadataItem.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
const relationGqlFieldWithId = getForeignKeyNameFromRelationFieldName(
|
||||
fieldMetadataItem.name,
|
||||
);
|
||||
@@ -202,12 +196,6 @@ export const computeOptimisticRecordFromInput = ({
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isUndefined(recordInputFieldValue)) {
|
||||
throw new Error(
|
||||
`Should never provide relation mutation through anything else than the fieldId e.g companyId and not company, encountered: ${fieldMetadataItem.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
const relationGqlFields = fieldMetadataItem.morphRelations?.map(
|
||||
(morphRelation) => {
|
||||
return computeMorphRelationFieldName({
|
||||
|
||||
Reference in New Issue
Block a user