@libresat/service

A minimal, modular and optionally opinionated library for building microservices

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@libresat/service
0.0.1-764 years ago4 years agoMinified + gzip package size for @libresat/service in KB

Readme

LibreSat Service
A minimal, modular and optionally opinionated library for building microservices for microplatforms based on GraphQL via Apollo Server and MongoDB via Mongoose. If you want to, it allows you to easily use the MTRC (Model - TypeDef - Resolver - Controller) paradigm to make your microservices maintainable and reduce boilerplate to the absolute minimum.
Part of LibreSat

Usage

See global README.

Documentation

First, setup a project directory:
$ mkdir todos
$ cd todos

$ git init
(...)
$ npm init
(...)

Next, add LibreSat Service and TypeScript:
$ npm i -s @libresat/service
$ npm i -D typescript
$ echo \
'{
  "extends": "./node_modules/@libresat/service/tsconfig.json"
}' > tsconfig.json

Now, add an index.ts and start.ts script:
$ mkdir src/
$ echo \
'import { GraphQLMongoDB as Service, loadPath } from "@libresat/service";

const service = new Service(
  "libresat-todos",
  3000,
  "mongodb://localhost:27017",
  loadPath(__dirname, "typeDefs"),
  loadPath(__dirname, "resolvers")
);

export { service };
' > src/index.ts

$ echo \
'import { service } from "./index";
const {
  name,
  description: pkgDescription,
  version,
  author,
  license,
  homepage
} = require("../package.json");

const description = `LibreSat Todos
${pkgDescription}

  Usage: libresat-todos [OPTION...]

  -p,     --port            Port to run the GraphQL server on
  -db,    --database-url    MongoDB server to connect to
  -hds,   --headers         Whether to use HTTP headers for authentication or not

Version: ${name}#${version} by ${author}
License: ${license}
More info: ${homepage}`;

service.startWithArgs(description, process.argv);
' > src/start.ts

Nice, you can start adding some MRTCs! Consider checking out LibreSat Identity for a complete example and best practices.