Skip to content

Commit

Permalink
fix(core): Fix custom field resolver for eager translatable relation (#…
Browse files Browse the repository at this point in the history
…2457)

Fixes #2453
  • Loading branch information
tianyingchun authored Oct 17, 2023
1 parent 3942690 commit 09dd7df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export class CustomFieldRelationResolverService {

const result = fieldDef.list ? await qb.getMany() : await qb.getOne();

return await this.translateEntity(ctx, result, fieldDef);
}

async translateEntity(
ctx: RequestContext,
result: VendureEntity | VendureEntity[] | null,
fieldDef: RelationCustomFieldConfig,
) {
if (fieldDef.entity === ProductVariant) {
if (Array.isArray(result)) {
await Promise.all(result.map(r => this.applyVariantPrices(ctx, r as any)));
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/api/config/generate-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ function generateCustomFieldRelationResolvers(
args: any,
context: any,
) => {
if (source[fieldDef.name] != null) {
return source[fieldDef.name];
}
const ctx: RequestContext = context.req[REQUEST_CONTEXT_KEY];
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);
}
const entityId = source[ENTITY_ID_KEY];
return customFieldRelationResolverService.resolveRelation({
ctx,
Expand Down

0 comments on commit 09dd7df

Please sign in to comment.