Refactor graphql query runner and add mutation resolvers (#7418)
Fixes https://github.com/twentyhq/twenty/issues/6859 This PR adds all the remaining resolvers for - updateOne/updateMany - createOne/createMany - deleteOne/deleteMany - destroyOne - restoreMany Also - refactored the graphql-query-runner to be able to add other resolvers without too much boilerplate. - add missing events that were not sent anymore as well as webhooks - make resolver injectable so they can inject other services as well - use objectMetadataMap from cache instead of computing it multiple time - various fixes (mutation not correctly parsing JSON, relationHelper fetching data with empty ids set, ...) Next steps: - Wrapping query builder to handle DB events properly - Move webhook emitters to db event listener - Add pagination where it's missing (findDuplicates, nested relations, etc...)
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
import { isPlainObject } from '@nestjs/common/utils/shared.utils';
|
||||
|
||||
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
|
||||
|
||||
import { compositeTypeDefinitions } from 'src/engine/metadata-modules/field-metadata/composite-types';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { computeCompositeColumnName } from 'src/engine/metadata-modules/field-metadata/utils/compute-column-name.util';
|
||||
import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import {
|
||||
@ -81,9 +84,15 @@ export function formatResult<T>(
|
||||
if (!compositePropertyArgs && !relationMetadata) {
|
||||
if (isPlainObject(value)) {
|
||||
newData[key] = formatResult(value, objectMetadata, objectMetadataMap);
|
||||
} else if (objectMetadata.fields[key]) {
|
||||
newData[key] = formatFieldMetadataValue(
|
||||
value,
|
||||
objectMetadata.fields[key],
|
||||
);
|
||||
} else {
|
||||
newData[key] = value;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -129,3 +138,18 @@ export function formatResult<T>(
|
||||
|
||||
return newData as T;
|
||||
}
|
||||
|
||||
function formatFieldMetadataValue(
|
||||
value: any,
|
||||
fieldMetadata: FieldMetadataInterface,
|
||||
) {
|
||||
if (
|
||||
typeof value === 'string' &&
|
||||
(fieldMetadata.type === FieldMetadataType.MULTI_SELECT ||
|
||||
fieldMetadata.type === FieldMetadataType.ARRAY)
|
||||
) {
|
||||
return value.replace(/{|}/g, '').split(',');
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user