From e0665ef6a1ad73b62236eb6fbb5e7b12a5019956 Mon Sep 17 00:00:00 2001 From: Richard Bateman Date: Thu, 31 Oct 2024 15:55:32 -0600 Subject: [PATCH] fix(core): It is possible for featuredAsset to resolve to {id: ID} without object --- .../entity/order-line-entity.resolver.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/core/src/api/resolvers/entity/order-line-entity.resolver.ts b/packages/core/src/api/resolvers/entity/order-line-entity.resolver.ts index e8cc63a348..60c1450139 100644 --- a/packages/core/src/api/resolvers/entity/order-line-entity.resolver.ts +++ b/packages/core/src/api/resolvers/entity/order-line-entity.resolver.ts @@ -1,5 +1,6 @@ import { Parent, ResolveField, Resolver } from '@nestjs/graphql'; +import { TransactionalConnection } from '../../../connection/transactional-connection'; import { Asset, FulfillmentLine, Order, OrderLine, ProductVariant } from '../../../entity'; import { AssetService, FulfillmentService, OrderService, ProductVariantService } from '../../../service'; import { RequestContext } from '../../common/request-context'; @@ -12,6 +13,7 @@ export class OrderLineEntityResolver { private productVariantService: ProductVariantService, private assetService: AssetService, private orderService: OrderService, + private connection: TransactionalConnection, private fulfillmentService: FulfillmentService, ) {} @@ -31,7 +33,19 @@ export class OrderLineEntityResolver { @Ctx() ctx: RequestContext, @Parent() orderLine: OrderLine, ): Promise { - if (orderLine.featuredAsset !== undefined) { + if (!!orderLine.featuredAsset) { + // In some scenarios (e.g. modifying an order to add a new item), orderLine.featuredAsset is an object + // with only an `id`, but the rest of the resolver expects the full Asset available so it can e.g. + // use the preview field. So, let's grab the whole thing if we have to. + if (!orderLine.featuredAsset.preview) { + const asset = await this.connection.findOneInChannel( + ctx, + Asset, + orderLine.featuredAsset.id, + ctx.channelId, + ); + return asset; + } return orderLine.featuredAsset; } else { return this.assetService.getFeaturedAsset(ctx, orderLine);