Skip to content

Instantly share code, notes, and snippets.

@riivanov
Created February 1, 2023 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riivanov/62aca7e133d71cd24712c0c18b099fd1 to your computer and use it in GitHub Desktop.
Save riivanov/62aca7e133d71cd24712c0c18b099fd1 to your computer and use it in GitHub Desktop.
Todo entity that is both an ORM entity, and part of a GQL schema definition
import { Field, ID, InputType, ObjectType } from "type-graphql";
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@ObjectType()
@Entity()
export class Todo {
@Field()
@PrimaryGeneratedColumn()
id: number;
@Field()
@Column()
task: string;
}
export type ITodo = { [K in keyof Todo]: Todo[K] };
@InputType()
export class TodoInput implements Partial<Todo> {
@Field({ nullable: true })
id: number;
@Field()
task: string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment