repo_description: Starter template for NestJS 😻 includes GraphQL with Prisma Client, Passport-JWT authentication, Swagger Api and Docker
repo_topics: bcrypt code-first graphql nestjs passport-jwt passportjs prisma
code: import { PrismaService } from 'nestjs-prisma';
  import {
    Resolver,
    Query,
    Parent,
    Mutation,
    Args,
    ResolveField,
  } from '@nestjs/graphql';
  import { UseGuards } from '@nestjs/common';
  import { UserEntity } from '../common/decorators/user.decorator';
  import { GqlAuthGuard } from '../auth/gql-auth.guard';
  import { UsersService } from './users.service';
  import { User } from './models/user.model';
  import { ChangePasswordInput } from './dto/change-password.input';
  import { UpdateUserInput } from './dto/update-user.input';
  
  @Resolver(() => User)
  @UseGuards(GqlAuthGuard)
  export class UsersResolver {
    constructor(
      private usersService: UsersService,
      private prisma: PrismaService,
    ) {}
  
    @Query(() => User)
    async me(@UserEntity() user: User): Promise<User> {
      return user;
    }
  
    @UseGuards(GqlAuthGuard)
    @Mutation(() => User)
    async updateUser(
      @UserEntity() user: User,
      @Args('data') newUserData: UpdateUserInput,
    ) {
      return this.usersService.updateUser(user.id, newUserData);
    }
  
    @UseGuards(GqlAuthGuard)
    @Mutation(() => User)
    async changePassword(
      @UserEntity() user: User,
      @Args('data') changePassword: ChangePasswordInput,
    ) {
      return this.usersService.changePassword(
        user.id,
        user.password,
        changePassword,
      );
    }
  
    @ResolveField('posts')
    posts(@Parent() author: User) {
      return this.prisma.user.findUnique({ where: { id: author.id } }).posts();
    }
  }
  