Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Fix Missed Translation For CustomFields With If Early Eag… #2457

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading