Skip to content

Commit

Permalink
Added field resolver for item details
Browse files Browse the repository at this point in the history
  • Loading branch information
FOSSforlife committed Mar 28, 2020
1 parent c44de59 commit 1c8629e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/modules/collection-item/collection-item.resolver.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand All @@ -33,6 +35,11 @@ export class CollectionItemResolver {
return this.service.findOne<CollectionItemWhereUniqueInput>(where);
}

@FieldResolver(() => [Item])
itemDetails(@Root() collectionItem: CollectionItem, @Ctx() ctx: BaseContext): Promise<Item[]> {
return ctx.dataLoader.loaders.CollectionItem.itemDetails.load(collectionItem);
}

@Mutation(() => CollectionItem)
async createCollectionItem(
@Arg('data') data: CollectionItemCreateInput,
Expand Down

0 comments on commit 1c8629e

Please sign in to comment.