Skip to content

Commit

Permalink
feat: ✨ Use DTO in resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumeisongsong committed Nov 18, 2024
1 parent 2048584 commit 264a605
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions libs/users/presentation/resolver/src/lib/users.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Args, ID, Query, Resolver, ResolveReference } from '@nestjs/graphql';
import { UsersService } from '@users/application';
import { User } from '@user/domain';
import { UserDto } from '@users/presentation-dto';

@Resolver(() => User)
@Resolver(() => UserDto)
export class UsersResolver {
constructor(private usersService: UsersService) {}

@Query(() => User, { nullable: true })
getUser(@Args({ name: 'id', type: () => ID }) id: string): User | undefined {
return this.usersService.findById(id);
@Query(() => UserDto, { nullable: true })
getUser(@Args({ name: 'id', type: () => ID }) id: string): UserDto | null {
const user: User | undefined = this.usersService.findById(id); // Domain entity
return user ? new UserDto(user.id, user.name) : null;
}

@ResolveReference()
Expand Down

0 comments on commit 264a605

Please sign in to comment.