diff --git a/src/modules/collection-item/collection-item.resolver.ts b/src/modules/collection-item/collection-item.resolver.ts index 284f099..d5b67f0 100644 --- a/src/modules/collection-item/collection-item.resolver.ts +++ b/src/modules/collection-item/collection-item.resolver.ts @@ -1,6 +1,6 @@ -import { Arg, Args, Mutation, Query, Resolver } from 'type-graphql'; +import { Arg, Args, Mutation, Query, Resolver, FieldResolver, Root, Ctx } from 'type-graphql'; import { Inject } from 'typedi'; -import { Fields, StandardDeleteResponse, UserId } from 'warthog'; +import { Fields, StandardDeleteResponse, UserId, BaseContext } from 'warthog'; import { CollectionItemCreateInput, @@ -13,6 +13,8 @@ import { import { CollectionItem } from './collection-item.model'; import { CollectionItemService } from './collection-item.service'; +import { User } from '../user/user.model'; +import { Item } from '../item/item.model'; @Resolver(CollectionItem) export class CollectionItemResolver { @@ -33,6 +35,11 @@ export class CollectionItemResolver { return this.service.findOne(where); } + @FieldResolver(() => [Item]) + itemDetails(@Root() collectionItem: CollectionItem, @Ctx() ctx: BaseContext): Promise { + return ctx.dataLoader.loaders.CollectionItem.itemDetails.load(collectionItem); + } + @Mutation(() => CollectionItem) async createCollectionItem( @Arg('data') data: CollectionItemCreateInput,