Skip to content

A tool to automatically add @field decorators to TypeScript classes with @ObjectType, @inputType, and @ArgsType decorators.

License

Notifications You must be signed in to change notification settings

Ancss/add-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

add-field

A tool to automatically add @Field decorators to TypeScript classes with @ObjectType, @InputType, and @ArgsType decorators.

Installation

You can use this tool directly with npx:

Example

Given the following class:

@InputType()
class CreateUserInput {
  id: number;
  name: string;
  email: string;
  password: string;
  account: Account;
  orders?: Order[];
  scores: number[];
  isAdmin: boolean;
}

After running the tool:

npx add-field src/**/*.ts

The class will be transformed into:

@InputType()
class CreateUserInput {
  @Field()
  id: number;
  @Field()
  name: string;
  @Field()
  email: string;
  @Field()
  password: string;
  @Field(() => Account)
  account: Account;
  @Field(() => [Order], { nullable: true })
  orders?: Order[];
  @Field(() => [Number])
  scores: number[];
  @Field()
  isAdmin: boolean;
}

About

A tool to automatically add @field decorators to TypeScript classes with @ObjectType, @inputType, and @ArgsType decorators.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published