Skip to content

Commit

Permalink
fix(core): Fix Missed Translation For CustomFields With If Early Eager (
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun committed Oct 16, 2023
1 parent 8db459a commit 3211d75
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 eagerntity = source[fieldDef.name];
// If the relation is eager-loaded, we can simply try to translate this relation entity if they have translations
if (eagerntity != null) {
return customFieldRelationResolverService.translateEntity(ctx, eagerntity, fieldDef);
}
const entityId = source[ENTITY_ID_KEY];
return customFieldRelationResolverService.resolveRelation({
ctx,
Expand Down

0 comments on commit 3211d75

Please sign in to comment.