Implementation ExpressJS modular approach with ES6 and GraphQL example
This is an example of ExpressJS modular approach that uses ES6 and include GraphQL example.
-
Make sure you have NodeJS and npm or yarn installed. And also nodemon to monitor the source and automatically restart the server when any changes in the source.
-
Install dependencies
$ cd path/to/expressjs-modular
Using
yarn
$ yarn
Using
npm
$ npm install
-
Configuration
a. Set the listener port to run the server
b. Set the database connection
c. Set the authentication secret using random text
d. Set administrator email to create super admin user
-
Run Using yarn
$ yarn start
Using npm
$ npm start
-
Test Using yarn
$ yarn test
Using npm
$ npm test
root // root folder
|- config // server configuration files
|- src // main sources
| |- graphql-schema // graphql schema
| |- helpers // helper classes
| |- hooks // global hook middleware
| |- models // database model classes
| |- services // service and hook modules
|
|- test // test unit module
# POST /graphql
+ headers: Authorization token with generated JWT
+ payload: Graphql query and mutation
# GET /users/:id
# GET /users
# POST /users
+ payload object
# UPDATE /users/:id
+ payload object
# DELETE /users/:id
# GET /banks/:id
# GET /banks
# POST /banks
+ payload object
# UPDATE /banks/:id
+ payload object
# DELETE /banks/:id
# GET /accounts/:id
# GET /accounts
# POST /accounts
+ payload object
# UPDATE /accounts/:id
+ payload object
# DELETE /accounts/:id
# GET /transactions/:id
# GET /transactions
# POST /transactions
+ payload object
# UPDATE /transactions/:id
+ payload object
# DELETE /transactions/:id
# POST /auth/token
+ payload object
-
Restful API with authorization method in the hook of each service modules.
-
GraphQL API with authorization method and can be added in the first line of each resolve methods and wrapped by try-catch.
-
Add another graphql schema to handle all CRUD processes
-
Completing transaction module
-
Add authentication in graphql method
-
Add reset authentication token method
Copyright (c) 2019
Licensed under the MIT license.