From b74c5ebe6a39c4fd39ad2469c8709c90d5feeb6c Mon Sep 17 00:00:00 2001 From: Pierre Chabardes Date: Wed, 4 May 2022 15:44:30 +0200 Subject: [PATCH] feature(hero): add equip item mutation in resolver --- src/graphql.ts | 1 + src/heroes/interface/graphql/hero.graphql | 1 + src/heroes/interface/graphql/hero.resolver.ts | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/src/graphql.ts b/src/graphql.ts index 174b22c..bc0f989 100644 --- a/src/graphql.ts +++ b/src/graphql.ts @@ -25,6 +25,7 @@ export interface IMutation { attackDragon(heroId: string, dragonId: string): boolean | Promise; generateNewDragon(input?: Nullable): boolean | Promise; createHero(name: string): boolean | Promise; + equipItem(heroId: string, itemId: string): boolean | Promise; } export interface Dragon { diff --git a/src/heroes/interface/graphql/hero.graphql b/src/heroes/interface/graphql/hero.graphql index 91d86e7..0ce3421 100644 --- a/src/heroes/interface/graphql/hero.graphql +++ b/src/heroes/interface/graphql/hero.graphql @@ -9,6 +9,7 @@ type Hero { type Mutation { createHero(name: String!): Boolean! + equipItem(heroId: ID!, itemId: ID!): Boolean! } type Query { diff --git a/src/heroes/interface/graphql/hero.resolver.ts b/src/heroes/interface/graphql/hero.resolver.ts index 18743fd..b4fbff5 100644 --- a/src/heroes/interface/graphql/hero.resolver.ts +++ b/src/heroes/interface/graphql/hero.resolver.ts @@ -19,6 +19,8 @@ import { GetAllHeroesQuery, GetAllHeroesQueryResult, } from '../../core/application/queries/get-all-heroes/get-all-heroes.query'; +import { EquipItemCommand } from '../../core/application/commands/equip-item/equip-item.command'; +import { Item } from '../../../items/core/domain/item.entity'; @Resolver('Hero') export class HeroResolver { @@ -64,4 +66,13 @@ export class HeroResolver { } return result.isOk(); } + + @Mutation() + public async equipItem( + @Args('heroId') heroId: Hero['id'], + @Args('itemId') itemId: Item['id'], + ): Promise { + await this.commandBus.execute(new EquipItemCommand({ heroId, itemId })); + return true; + } }