Last active
July 3, 2018 03:50
-
-
Save kdby-io/d20cf57eb69b8c22b925b23b30d2ce3d to your computer and use it in GitHub Desktop.
An example for graphql-typescript with typeorm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Entity, Column, PrimaryGeneratedColumn, getRepository, CreateDateColumn, UpdateDateColumn } from 'typeorm' | |
import { Type, Field, ID, String, Mutation } from 'graphql-typescript' | |
class CreateUserArguments { | |
@Field(String) username: string | |
@Field(String) password: string | |
} | |
@Entity({ name: 'User' }) | |
@Type | |
export class User { | |
@PrimaryGeneratedColumn() | |
@Field(ID) | |
id: string | |
@Column({ type: 'varchar', unique: true }) | |
@Field(String) | |
username: string | |
@Column('varchar') | |
password: string | |
@CreateDateColumn() | |
createdAt: Date | |
@UpdateDateColumn() | |
updatedAt: Date | |
@Mutation(User) | |
createUser(_: any, args: CreateUserArguments) { | |
return getRepository(User).save(await User.create(args)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment