1

I've built an API for my system which uses various TypeORM/Type-GraphQL decorated classes.

Here's an example of one entity, which lets me connect to my PostgresSQL database:

import { BaseEntity, PrimaryGeneratedColumn, Column, Entity } from "typeorm";
import { ObjectType, Field } from "type-graphql";

@ObjectType()
@Entity()
export class Disclosure extends BaseEntity {
  @Field()
  @PrimaryGeneratedColumn("uuid")
  id: string;

  @Field()
  @Column()
  first: string;

  @Field()
  @Column()
  last: string;

  @Field()
  @Column({ unique: true })
  link: string;

  @Field()
  @Column()
  title: string;

  @Field()
  @Column()
  date: Date;
}

The current structure of my project includes these classes or entities inside my src folder and inside the entity folder. The Typescript compiler converts them into Javascript which then is placed into the distfolder.

enter image description here

I've got an entirely different project which reuses some of these types. Specifically, I'm using Apollo-Client and would like to be able to reuse these entities to ensure that my post requests conform to the same shape.

What's the best way of reusing these Typescript classes outside of the current project? Is there a clean and organized project structure that others are using?

Harrison Cramer
  • 3,792
  • 9
  • 33
  • 61

0 Answers0