@Entity()exportclassContent{
@PrimaryGeneratedColumn("increment")publicid?: number;publicnodeId?: string;
@Column({length: 32,comment: "Identifies how content should behave."})publictag: string;
@Column({length: 128,comment: "Title of the content."})publictitle: string;
@Column({length: 512,comment: "Thumbnail representing the content."})publicimage: string;
@Column({length: 512,comment: "Short description of content."})publicdescription: string;
@Column("jsonb",{comment: "@jsonField children array \n Therapy content.",default: `{"children":[]}`,nullable: false})publicprops?: IProps;
@Column("timestamp without time zone",{default: ()=>"(NOW() AT TIME ZONE 'UTC')"})publiccreatedAt?: Date;
@Column("timestamp without time zone",{default: ()=>"(NOW() AT TIME ZONE 'UTC')"})publicupdatedAt?: Date;}
Example Migration
import{MigrationInterface,QueryRunner}from"typeorm";exportclassTherapy1539901776490implementsMigrationInterface{publicasyncup(queryRunner: QueryRunner): Promise<any>{awaitqueryRunner.query(`CREATE TABLE "content" ("id" SERIAL NOT NULL, "tag" character varying(32) NOT NULL, "title" character varying(128) NOT NULL, "image" character varying(512) NOT NULL, "description" character varying(512) NOT NULL, "props" jsonb NOT NULL DEFAULT '{"children":[]}', "createdAt" TIMESTAMP NOT NULL DEFAULT (NOW() AT TIME ZONE 'UTC'), "updatedAt" TIMESTAMP NOT NULL DEFAULT (NOW() AT TIME ZONE 'UTC'), CONSTRAINT "PK_6a2083913f3647b44f205204e36" PRIMARY KEY ("id"))`);}publicasyncdown(queryRunner: QueryRunner): Promise<any>{awaitqueryRunner.query(`DROP TABLE "content"`);}}
Example graphql
exportconstUPDATE_CONTENT=gql`mutation UPDATE_CONTENT($id: Int!, $tag: String!, $title: String!, $image: String!, $description: String!, $props: JSON!) { updateContentById(input: {id:$id, contentPatch: { tag:$tag, title:$title, image:$image, description:$description, props:$props}}) { content { __typename nodeId id tag title image description props } }}`;exportconstQUERY_CONTENT=gql`query QUERY_CONTENT($id: Int!) { contentById(id:$id) { __typename nodeId id tag title image description props }}`;