diff --git a/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts index b06c26ec36d4..473c6f8408d8 100644 --- a/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/__tests__/map-field-metadata-to-graphql-query.utils.spec.ts @@ -6,17 +6,19 @@ import { objectMetadataItemMock, } from 'src/engine/api/__mocks__/object-metadata-item.mock'; import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils'; +import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; +import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; describe('mapFieldMetadataToGraphqlQuery', () => { it('should map properly', () => { expect( - mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldNumberMock), + mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], fieldNumberMock), ).toEqual('fieldNumber'); expect( - mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldTextMock), + mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], fieldTextMock), ).toEqual('fieldText'); expect( - mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldLinkMock), + mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], fieldLinkMock), ).toEqual(` fieldLink { @@ -25,7 +27,10 @@ describe('mapFieldMetadataToGraphqlQuery', () => { } `); expect( - mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldCurrencyMock), + mapFieldMetadataToGraphqlQuery( + [objectMetadataItemMock], + fieldCurrencyMock, + ), ).toEqual(` fieldCurrency { @@ -34,4 +39,21 @@ describe('mapFieldMetadataToGraphqlQuery', () => { } `); }); + describe('should handle all field metadata types', () => { + Object.values(FieldMetadataType).forEach((fieldMetadataType) => { + it(`with field type ${fieldMetadataType}`, () => { + const field = { + type: fieldMetadataType, + name: 'toObjectMetadataName', + fromRelationMetadata: { + relationType: RelationMetadataType.ONE_TO_MANY, + }, + }; + + expect( + mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], field), + ).toBeDefined(); + }); + }); + }); }); diff --git a/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils.ts b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils.ts index 7fc9700828d4..4605760eca66 100644 --- a/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils.ts +++ b/packages/twenty-server/src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils.ts @@ -19,14 +19,18 @@ export const mapFieldMetadataToGraphqlQuery = ( FieldMetadataType.UUID, FieldMetadataType.TEXT, FieldMetadataType.PHONE, + FieldMetadataType.EMAIL, FieldMetadataType.DATE_TIME, FieldMetadataType.DATE, - FieldMetadataType.EMAIL, + FieldMetadataType.BOOLEAN, FieldMetadataType.NUMBER, - FieldMetadataType.SELECT, + FieldMetadataType.NUMERIC, + FieldMetadataType.PROBABILITY, FieldMetadataType.RATING, - FieldMetadataType.BOOLEAN, + FieldMetadataType.SELECT, + FieldMetadataType.MULTI_SELECT, FieldMetadataType.POSITION, + FieldMetadataType.RAW_JSON, ].includes(fieldType); if (fieldIsSimpleValue) {