Automatically create TypeORM EntitySchema's, GraphQL resolvers, GraphQL Mutation, Query, and Input schemas from TypeORM annotated(directive) types.
npm i graphql_typeorm
type Author @Entity {
id: Int! @PrimaryGeneratedColumn
name: String! @Column
rating: Float @Column(type: "float")
books: [Book] @Relationship(type: "one-to-many", target: "Book")
}
type Book @Entity {
id: Int! @Column(type: "int", primary: true, generated: true)
title: String! @Column(type: "string")
author: [Author]! @Relationship(type: "many-to-one", target: "Author")
}
Name | Options | Description |
---|---|---|
@Entity | EntitySchemaOptions | Determines what GraphQL Types get converted to TypeORM EntitySchema Models. |
@Column | EntitySchemaColumnOptions | Determines what model fields are stored in database. |
@Relationship | EntitySchemaRelationshipOptions | Determines that a relationship field should be created. |
@PrimaryColumn | EntitySchemaColumnOptions | Shortcut for Column type with primary = true |
@PrimaryGeneratedColumn | EntitySchemaColumnOptions | Shortcut for Column type with primary = true and generated = true |
@CreateDateColumn | EntitySchemaColumnOptions | Shortcut for Column type with type = 'timestamp with time zone' and createDate = true |
@UpdateDateColumn | EntitySchemaColumnOptions | Shortcut for Column type with type = 'timestamp with time zone' and updateDate = true |
npx graphql_typeorm dir=./schemas outDir=./generated
Option | Default | Description |
---|---|---|
file | .graphql schema file to generate from | |
dir | Directory to find .graphql files to generate from | |
outDir | ./generated | Directory to write generated files to |
format | ts | Output format. Valid options = ts/js |
contextPath | ../context | Override with custom context type. Currently must include field connection: Connection. Note: path must be relative to generated root directory. |
See src/cli.ts
Located within folders generatedTS and generatedJS.
- Handle resolvers as normal vs connections. (Naming convention? New directive? Either?)
- Finish adding/handling EntitySchemaOptions (indices, etc...)