IMPORTANT: This is a WORK IN PROGRESS, it is not complete.
This is my boilerplate for using typescript to build out an http(s) service. Typescript is an amazing addition to the Node.JS/Javascript. This is just a starting point, I do not claim to cover all use cases, or even use all the best options. This is what I find useful and helpful.
Pull requests to improve are always welcome, but I'm not interesting to making this cover all use cases, keep it simple is the idea here.
- - Adding in JWT Authentication
- - Document GraphQL Modifications
- - Document Database Modifications (including Migrations)
- - Document Adding Routes
To get started developing, you need to first run npm install
after that npm run watch
and start modifying code. The watch
script fires up two nodemon processes concurrently. One watches for graphql schema change and re-renders the typescript necessary for it to work properly, and the second watches for any typescript or javascript file changes and reloads.
Ready for building for Docker from the start.
docker build -t project .
This is just the guideline that I like to use.
src/graphql
- Everything GraphQL relatedsrc/instances
- Instances of "things", like config, logger, restify, database, etcsrc/lib
- Library like import/requiressrc/typings
- Custom typings for the project
- TypeScript
- Restify
- Bunyan
- Apollo (for GraphQL)
- RC (for Configuration)
Add the following to your .boilerplaterc
file.
{
"graphql": {
"playground": true
}
}
- Add your type definitions to
graphql/schema.graphql
type User {
id: String!
username: String!
}
- Modify the
type Query
ingraphql/schema.graphql
to include a query for users
type Query {
users: [User]
}
- Add a
users
resolver ingraphql/resolvers.query.ts
also import the User Type fromschema-types.ts
import { User as UserType } from '../schema-types.ts';
import { UserModel } from '../../db';
export const QueryResolvers = {
async users(source: any, args: any, context: any, ast: any): Promise<UserType[]> {
return UserModel.findAll();
},
};
If you've been using npm run watch
this entire type, your system will have rebuild the schema.json
file and the schema-types.ts
for you and the new GraphQL query will be ready for use.