0.0.103 • Published 5 years ago
@cortical/ts2graphql v0.0.103
Cortical GraphQL Transpiler
A runtime tranpiler and generator that converts your TypeScript code into GraphQL types
Key aspects
- It doesn't use decorators to transpile code
- It inflicts a folder/file export pattern
- Depends on TypeDoc JSON generator
How to use it
Set your enviroment to have the following directories
./types
Include all GraphQL types in separated files that export the TypeScript type.
Interface
Interface TypeScript types are converted to GraphQL Input Object Type
input
// types/Login.ts
/**
* Login input
*/
export interface Login {
/**
* The user's email address
*/
email: string;
/**
* The user's plain password
*/
password: string;
}
output
// schema/Login.graphql
# Login input
input Login {
# The user's email address
email: String!
# The user's plain password
password: String!
}
Class
Class TypeScript types are converted to GraphQL Object Type
// types/User.ts
import { Post } from './Post';
/**
* User object
*/
export class User {
/**
* The user's unique id
*/
id: string;
/**
* The user's email address
*/
email: string;
/**
* The user's plain password
* @GraphQL.disable
*/
password: string;
/**
* Get latest user's posts
*/
async getLatestPosts(
args: {
/**
* The maximum number of posts to fetch
*/
limit?: number = 10
},
context: any
): Promise<Post[]> {
// ...
}
/**
* Check user password
* @GraphQL.disable
*/
checkPassword(password: string): boolean {
// ...
}
}
output
// schema/User.graphql
# User object
type User {
# The user's unique id
id: String!
# The user's email address
email: String!
# Get latest user's posts
getLatestPosts(
# The maximum number of posts to fetch
limit: Float = 10
): [Post]
}
It comes with a CLI
ts2graphql -p src -o build/graphql
TODO: More examples and tutorials
0.0.103
5 years ago
0.0.102
6 years ago
0.0.101
6 years ago
0.0.99
6 years ago
0.0.98
6 years ago
0.0.97
6 years ago
0.0.96
6 years ago
0.0.95
6 years ago
0.0.94
6 years ago
0.0.93
6 years ago
0.0.92
6 years ago
0.0.91
6 years ago
0.0.90
6 years ago
0.0.89
6 years ago
0.0.88
6 years ago
0.0.87
6 years ago
0.0.86
6 years ago
0.0.85
6 years ago
0.0.84
6 years ago
0.0.82
6 years ago
0.0.81
6 years ago
0.0.79
6 years ago
0.0.78
6 years ago
0.0.77
6 years ago
0.0.75
6 years ago
0.0.74
6 years ago
0.0.73
6 years ago
0.0.72
6 years ago