1.0.1 • Published 2 years ago
nodejs-graphql-micorservice-template v1.0.1
nodejs graphql micorservice template
A Nodejs project template in Typescript to quickly have microservices built using graphql. Mongo db is used as database
Microservice directory
All microservices are created under src/. Example microservice - src/my-micro-service
Creating a new microservice
- Copy directory my-micro-service into a new directory say
abc-micro-service - Change the
namefield inpackage.jsonunderabc-micro-service, toabc-micro-service In package.json of the main project, add this
abc-micro-serviceas a local file dependency like"dependencies": { "abc-micro-service": "file:src/abc-micro-service", }
Graphql Schemas
Graphql schemas are under api-schemas/config.json
Microservice Registration
Microservices are served under a specific path , say /graphql/my-micro-service. For a microservice
to start up, register it under src/services/app.ts
import { MAPP as MICROSERVICE1 } from "my-micro-service";
app.use('/graphql/my-micro-service',
MICROSERVICE1);Start the server
npm install
npm startthis will start server at port 3092
Test in browser
Test your microservice(ex:my-micro-service) in browser by hitting http://localhost:3092/my-micro-service
1.0.1
2 years ago