Skip to content

Instantly share code, notes, and snippets.

@kdby-io
Last active July 3, 2018 03:50
Show Gist options
  • Save kdby-io/d20cf57eb69b8c22b925b23b30d2ce3d to your computer and use it in GitHub Desktop.
Save kdby-io/d20cf57eb69b8c22b925b23b30d2ce3d to your computer and use it in GitHub Desktop.
An example for graphql-typescript with typeorm
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