Type Functions

Example

You can reuse type functions in your resolvers. The example below shows how to use OutputType in a resolver.

import { OutputType, BaseService, InjectBaseService } from 'dryerjs';
 
@Resolver()
export class AuthResolver {
  constructor(@InjectBaseService(User) public userService: BaseService<User, Context>) {}
 
  @Query(() => OutputType(User))
  async whoAmI(@Ctx() ctx: Context) {
    return await this.User.findById(ctx, { _id: ctx.user._id });
  }
}

Other type functions

  • CreateInputType
  • UpdateInputType
  • FilterType
  • SortType
  • PaginateOutputType
  • BulkCreateOutputType
  • BulkUpdateOutputType
  • BulkRemoveOutputType

Use with Mapped types

You can mix the type functions with NestJS Mapped types to create your own types.

@InputType()
export class SignInInput extends Pick(CreateInputType(User), ['email', 'password']) {}

There are Partial, Pick, Omit, Intersection and Composition mapped types available.

Read more about NestJS Mapped types (opens in a new tab).