Skip to content

Commit

Permalink
feature(hero): add equip item mutation in resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Chabardes committed May 24, 2022
1 parent 7e57384 commit b74c5eb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IMutation {
attackDragon(heroId: string, dragonId: string): boolean | Promise<boolean>;
generateNewDragon(input?: Nullable<DragonCreationInput>): boolean | Promise<boolean>;
createHero(name: string): boolean | Promise<boolean>;
equipItem(heroId: string, itemId: string): boolean | Promise<boolean>;
}

export interface Dragon {
Expand Down
1 change: 1 addition & 0 deletions src/heroes/interface/graphql/hero.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Hero {

type Mutation {
createHero(name: String!): Boolean!
equipItem(heroId: ID!, itemId: ID!): Boolean!
}

type Query {
Expand Down
11 changes: 11 additions & 0 deletions src/heroes/interface/graphql/hero.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<boolean> {
await this.commandBus.execute(new EquipItemCommand({ heroId, itemId }));
return true;
}
}

0 comments on commit b74c5eb

Please # to comment.