diff --git a/src/items/items.resolver.ts b/src/items/items.resolver.ts index b1b4697..055931f 100644 --- a/src/items/items.resolver.ts +++ b/src/items/items.resolver.ts @@ -22,7 +22,6 @@ export class ItemsResolver { @ResolveField() async parent(@Parent() item: ItemModel) { - if (item.parent) return item.parent; return this.itemsService.getItemParent(item); } diff --git a/src/items/items.service.ts b/src/items/items.service.ts index 8978804..1cdf8aa 100644 --- a/src/items/items.service.ts +++ b/src/items/items.service.ts @@ -22,8 +22,10 @@ export class ItemsService { } async getItemParent(item: ItemModel) { - const itemE = await this.itemRepository.findOneOrFail(item.id); - return (await this.treeRepository.findAncestorsTree(itemE)).parent; + const childItem = await this.itemRepository.findOneOrFail(item.id, { + relations: ['parent'], + }); + return childItem.parent; } async createItem(input: NewItemInput): Promise {