Nest Query Utils
Vizorous
byInstall
npm install @vizorous/nest-query-utils
yarn add @vizorous/nest-query-utils
pnpm add @vizorous/nest-query-utils
@CF
-
CF is a custom decorator which stands for Column Field.
-
It combines @Column (TypeORM), @Field (NestJS) and @Expose (Class Transformer) decorators.
-
Can be utilized to easily define a column in a TypeORM entity and expose it in a GraphQL schema.
import { CF } from "@vizorous/nest-query-utils"; import { ObjectType } from "@nestjs/graphql"; import { Entity } from "typeorm"; @ObjectType() @Entity() export class User { @CF() name: string; @CF({ nullable: true }) phone?: string; }
@CFF()
-
CFF is a custom decorator which stands for Column Filterable Field.
-
It combines @Column (TypeORM), @FilterableField (Nestjs Query) and @Expose (Class Transformer) decorators.
-
Can be utilized to easily define a column in a TypeORM entity and expose a filterable field it in a GraphQL schema.
import { CF } from "@vizorous/nest-query-utils"; import { ObjectType } from "@nestjs/graphql"; import { Entity } from "typeorm"; @ObjectType() @Entity() export class User { @CFF({ fieldOptions: { allowedComparisons: ["in", "is", "like"] } }) name: string; @CF({ nullable: true }) phone?: string; }
BaseEntity
-
BaseEntity is a custom class which can be used to extend TypeORM entities. It contains;
-
id
column usinguuid
type -
createdAt
column usingDate
type -
updatedAt
column usingDate
type -
deletedAt
column usingDate
type
-
-
This is useful for creating entities with common fields.
import { CF } from "@vizorous/nest-query-utils"; import { BaseEntity } from "@vizorous/nest-query-utils"; import { ObjectType } from "@nestjs/graphql"; import { Entity } from "typeorm"; @ObjectType() @Entity() export class User extends BaseEntity { @CFF() name: string; @CF({ nullable: true }) phone?: string; }
CreateType
- Creates a DTO class for creation with unnecessary fields such as createdAt, updatedAt, etc. omitted. You can omit other fields as well by passing a list of fields to omit to omitKeys.
@InputType() export class CreateTodo extends CreateType(Todo, [ "done", "subTasks", "category", ]) { //you can add more custom fields here }
UpdateType
-
Creates a DTO class for update with unnecessary fields omitted AND required fields set. You can omit other fields as well by passing a list of fields to omit to omitKeys.
@InputType() export class UpdateTodo extends UpdateType(Todo, ["category"], ["done"]) { //you can add more custom fields here }
@IDExpose()
- Combination of @IDField and @Expose decorators.
import { IDExpose } from "@vizorous/nest-query-utils";
import { ObjectType } from "@nestjs/graphql";
import { Entity, PrimaryGeneratedColumn } from "typeorm";
@ObjectType()
@Entity()
@Keyset()
export class User {
@IDExpose(() => ID, { idOptions: { allowedComparisons: ["eq", "in"] } })
@PrimaryGeneratedColumn("uuid")
id: string;
}