0.1.29 • Published 5 years ago
type-graph-orm v0.1.29
type-graph-orm
Simple integration between TypeORM and GraphQL.js.
import * as GraphORM from 'type-graph-orm'
import {
Column,
Field,
Int,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
String,
} from 'typeorm'
import { graphql } from 'graphql'
// Define TypeORM entities
@GraphORM.DatabaseObjectType({
views: [{
// API users can directly query `users` field via this *view*.
isDirectView: true,
name: 'users'
}]
})
export class User {
@PrimaryGeneratedColumn()
public id: number
@Column()
public name: string
@Column()
public age: number
@OneToMany(() => Post, post => post.user)
public posts: Post[]
}
@GraphORM.DatabaseObjectType()
class Post {
@PrimaryGeneratedColumn()
public id: number
@Column()
public title: string
@ManyToOne(() => User, user => user.posts)
public user: User
}
// Create executable schema
const schema = await buildExecutableSchema({
entities: [
User,
Post,
],
})
// Simple query
const result = await graphql(schema, `
query {
users {
id
name
age
posts {
id
title
}
}
}`
)
// Complex filters
const result = await graphql(schema, `
query {
users(where: {name: "Foo"}) {
id
age
posts(where: {id: 2}) {
title
}
}
}`
)
To run tests
Create .env
file at the project root and fill it with database information.
TEST_DB_HOST=localhost
TEST_DB_TYPE=mysql
TEST_DB_NAME=test
TEST_DB_USERNAME=root
TEST_DB_PASSWORD=mypassword
TEST_DB_PORT=3316
If you want, you can run a Docker container of MySQL for test based on .env
file.
docker-compose up -d
Now you can run tests.
yarn test
Notes
Implementation is now at experimental stage. It's currently tested on the simplest cases.
0.1.29
5 years ago
0.1.28
5 years ago
0.1.27
5 years ago
0.1.26
5 years ago
0.1.25
5 years ago
0.1.23
5 years ago
0.1.22
5 years ago
0.1.21
5 years ago
0.1.20
5 years ago
0.1.19
5 years ago
0.1.18
5 years ago
0.1.17
5 years ago
0.1.16
5 years ago
0.1.15
5 years ago
0.1.14
5 years ago
0.1.13
5 years ago
0.1.12
5 years ago
0.1.11
5 years ago
0.1.10
5 years ago
0.1.9
5 years ago
0.1.8
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.4
5 years ago
0.1.3
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago