From 025a9c7fa05717c4c03275fc93c256783089e64a Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Thu, 25 Apr 2024 13:27:42 +0200 Subject: [PATCH] fix(core): Improved loading of eager-loaded custom field relations Closes #2775, Relates to #2687 --- packages/core/src/api/config/generate-resolvers.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/api/config/generate-resolvers.ts b/packages/core/src/api/config/generate-resolvers.ts index 2a162f57a1..2d72f8af57 100644 --- a/packages/core/src/api/config/generate-resolvers.ts +++ b/packages/core/src/api/config/generate-resolvers.ts @@ -13,6 +13,7 @@ import { shopErrorOperationTypeResolvers } from '../../common/error/generated-gr import { Translatable } from '../../common/types/locale-types'; import { ConfigService } from '../../config/config.service'; import { CustomFieldConfig, RelationCustomFieldConfig } from '../../config/custom-field/custom-field-types'; +import { Logger } from '../../config/logger/vendure-logger'; import { Region } from '../../entity/region/region.entity'; import { getPluginAPIExtensions } from '../../plugin/plugin-metadata'; import { CustomFieldRelationResolverService } from '../common/custom-field-relation-resolver.service'; @@ -212,7 +213,17 @@ function generateCustomFieldRelationResolvers( const eagerEntity = source[fieldDef.name]; // If the relation is eager-loaded, we can simply try to translate this relation entity if they have translations if (eagerEntity != null) { - return customFieldRelationResolverService.translateEntity(ctx, eagerEntity, fieldDef); + try { + return await customFieldRelationResolverService.translateEntity( + ctx, + eagerEntity, + fieldDef, + ); + } catch (e: any) { + Logger.debug( + `Error resolving eager-loaded custom field entity relation "${entityName}.${fieldDef.name}": ${e.message as string}`, + ); + } } const entityId = source[ENTITY_ID_KEY]; return customFieldRelationResolverService.resolveRelation({