A clean template combining TypeScript, GraphQL and Node.js together.
- Clone/fork repository
git clone https://github.com/senhungwong/ts-gql-node.git
- Install dependency
cd ts-gql-node && npm install # OR yarn
- Set app environment
cp .env.example .env
- Start server
npm start # OR yarn serve
-
GraphQL schema
-
Create GraphQL schema file and store them into
./src/schemas/
-
Merge schemas
# For modularization, schemas are defined in multiple files # The following script merges them into one schema npm run merge-schemas # OR yarn merge-schemas
-
Generate TypeScript definition
# We can generate TypeScript type definition by using the schema npm run gql2ts # OR yarn gql2ts
-
-
GraphQL resolver
-
Create service in
./src/services/
. All complex logics should be here -
Map field services to resolvers in
./src/resolvers/
-
Write service tests in
./tests/
and testnpm run test # OR yarn test
-
Validate arguments in
./src/validators/
and map them in./src/validators/index.ts
-
See treehole implementation: