import { Ctx, Field, ObjectType } from 'type-graphql'; import { Column, Entity, ManyToOne } from 'typeorm'; import { AggregateProductVariant } from '@/entities'; import { ContextType } from '@/types'; import { RetailerProduct } from '..'; import { AbstractRetailerProductData } from '../AbstractRetailerProductData'; @Entity({ name: 'retailer_product_variants' }) @ObjectType({ implements: AbstractRetailerProductData.objectTypeImplements, }) // eslint-disable-next-line max-len export default class RetailerProductVariant extends AbstractRetailerProductData { @ManyToOne(() => RetailerProduct, (product) => product.variants, { nullable: false, }) product!: RetailerProduct; @Column() productId!: string; @ManyToOne(() => AggregateProductVariant, (variant) => variant.retailers, { nullable: false, }) variant!: AggregateProductVariant; @Column() variantId!: string; @Field(() => String) aggregateProductVariantId(): string { return this.variantId; } @Field(() => RetailerProduct, { name: 'product' }) async productResolver( @Ctx() { dbDataLoader }: ContextType ): Promise { return dbDataLoader.retailerProductById.load(this.productId); } }