Skip to content

Commit

Permalink
fix(core): It is possible for featuredAsset to resolve to {id: ID} wi…
Browse files Browse the repository at this point in the history
…thout object
  • Loading branch information
taxilian committed Nov 14, 2024
1 parent 7bba907 commit 43419f3
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,6 +13,7 @@ export class OrderLineEntityResolver {
private productVariantService: ProductVariantService,
private assetService: AssetService,
private orderService: OrderService,
private connection: TransactionalConnection,
private fulfillmentService: FulfillmentService,
) {}

Expand All @@ -31,7 +33,19 @@ export class OrderLineEntityResolver {
@Ctx() ctx: RequestContext,
@Parent() orderLine: OrderLine,
): Promise<Asset | undefined> {
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);
Expand Down

0 comments on commit 43419f3

Please sign in to comment.