Create a Graphql API in typescript with type-graphql and Typeorm
First, install Yeoman and generator-rest-express-typescript using npm (we assume you have pre-installed node.js).
npm install -g yo
npm install -g generator-graphql-typescriptThen generate your new project:
yo graphql-typescript myapp- Run
npm startto preview and watch for changes - Run
npm run buildto create the production version - Run
npm run testto lauch jest test
query login(
input: $input
) {
... on LoginType {
__typename
token
}
... on UserError {
__typename
message
}
}
}You need to put the token you get from the login query to perform this query. Prefix the authorization header with bearer.
{
"Authorization": "bearer thetoken"
}query {
projects {
name,
owner { email }
}
} mutation {
register(
input: $input
) {
... on User {
__typename
username
email
}
... on UserError {
__typename
message
}
}
}You need to put the token you get from the login query to perform this query. Prefix the authorization header with bearer.
{
"Authorization": "bearer thetoken"
}mutation {
createProject(
input: $input
) {
__typename
... on Project {
name
}
... on UserError {
message
}
}
}- Add subcommand to create a new resolver
See the contributing docs.
MIT © Clément Lafont
