title: NestJS - Avoid returning user's password
body: <p>I have a little problem with my project using GraphQL and Mongoose (code-first approach). I have a findCurrentUser query in my user's resolver that returns the information about the currently authenticated user, but I don't want to return the user's password, how I can avoid this?</p>
  <p>User's Resolver:</p>
  <pre class="lang-js prettyprint-override"><code>@Query(() =&gt; User)
  @UseGuards(GqlAuthGuard)
  async findCurrentUser(@CurrentUser() user: JwtPayload): Promise&lt;User&gt; {
    return await this.usersService.findCurrent(user.id);
  }
  </code></pre>
  <p>User's Service:</p>
  <pre class="lang-js prettyprint-override"><code>async findCurrent(id: string): Promise&lt;User&gt; {
      try {
        // find the user
        const user = await this.userModel.findOne({ _id: id });
  
        // if the user does not exists throw an error
        if (!user) {
          throw new BadRequestException('User not found');
        }
  
        // we should not return the user's password
        // TODO: this is a temporary solution, needs to be improved
        user.password = '';
  
        return user;
      } catch (error) {
        throw new InternalServerErrorException(error.message);
      }
    }
  </code></pre>
  <p>User's Entity:</p>
  <pre class="lang-js prettyprint-override"><code>import { ObjectType, Field, ID } from '@nestjs/graphql';
  import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
  import { Document, Schema as MongooseSchema } from 'mongoose';
  import { nanoid } from 'nanoid';
  
  @Schema()
  @ObjectType()
  export class User {
    @Field(() =&gt; ID)
    _id: MongooseSchema.Types.ObjectId;
  
    @Field(() =&gt; String, { nullable: false })
    @Prop({ type: String, required: true, trim: true })
    firstName: string;
  
    @Field(() =&gt; String, { nullable: true })
    @Prop({ type: String, required: false, trim: true })
    lastName?: string;
  
    @Field(() =&gt; String, { nullable: true })
    @Prop({ type: String, required: false, default: nanoid(10) })
    username: string;
  
    @Field(() =&gt; String, { nullable: false })
    @Prop({
      type: String,
      unique: true,
      required: true,
      lowercase: true,
      trim: true
    })
    email: string;
  
    @Field(() =&gt; String, { nullable: false })
    @Prop({ type: String, required: true, trim: true, minlength: 6 })
    password: string;
  
    @Field(() =&gt; Boolean, { defaultValue: true })
    @Prop({ type: Boolean, default: true })
    isActive: boolean;
  
    @Field(() =&gt; Date, { defaultValue: Date.now() })
    @Prop({ type: Date, default: Date.now() })
    createdAt: Date;
  }
  
  export type UserDocument = User &amp; Document;
  
  export const UserSchema = SchemaFactory.createForClass(User);
  
  </code></pre>
  <p>In the documentation, the NestJS team mentions &quot;Serialization, &quot; but I already tried and didn't work. I get the following error on my GraphQL Playground:</p>
  <blockquote>
  <p>&quot;message&quot;: &quot;Cannot return null for non-nullable field User._id.&quot;</p>
  </blockquote>