1.0.0 • Published 4 years ago

api-enveve v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

API Enveve

Monorepo structure for API Enveve.

API Design


See Single API Structure and API Queries

API Gateway and Services


Important guidelines


Entities (Apollo docs)

Entities (we can see them as Shared Types between services) are defined in /libs/shared-types/ and must be defined and used throughout the services following the docs provided above.

They must provide at least one field set in @key directive, then can be extended by adding fields (and relative resolvers). Services that use such Entities will have a specific folder api/_externals where they will be defined.

Example

Types such as Auth, Image, Location are extensively used from several other Types in different services.

Scalars and interfaces

Scalars and interfaces can be shared between services, but can be resolved in different ways (individually for each service that uses them).

  • A Scalar can be defined (with the same name) in every service that need to use it. Every service may parse or serialize the scalar in a different way.

    Scalars such as `DateTime` allows to create a "custom field type" that renders a date. Every service can format the date in a different way.
  • An Interface can be defined (with the same name) in every service that need to use it. Every type that implements that interface, must provide the same fields. Every definition in every services must provide the same fields, but they can have different resolvers.

    Interface `TimeEntity` provides two very common field `creationDate` and `lastModifyDate`. Every service can then find and resolve those field in different ways.

Folder structure


  • apps/ Contains all apps/api (agronomeet, resilience-engine, users, etc... + gateway)
  • libs/ Common libraries/code such as utils for queries (you can import libs by using the alias $libs)

Libraries and packages


  • package.json is unique and shared to all services, this will prevent mismatching versions as well as saving disk space
  • /libs use it for any internal code/utils/package, in this way we won't need to create any npm package (it will also avoid dependency/versioning problems)

Graph Manager


  • New versions of the schemas will be automatically updated on Graph Manager, we'll receive a Slack notification whenever there has been some minor changes (adding types or field) or breaking changes (removing input fields or types)

Getting started


  • Run Agronomeet SSH npm run ag:ssh, then Agronomeet API DEV npm run ag:dev
  • Run Resilience Engine SSH npm run re:ssh, Resilience Engine API DEV npm run re:dev
  • Run Users API on Oauth Server npm run users:dev
  • Run Gateway API npm run gw:dev

How to deploy


  • Connect to ag:ssh
  • cd build/api-enveve
  • git pull
  • Then ./api_deploy.sh [ ag | re | gw | users ] [ master | beta | dev ]

    • According to what has been modified, deploy just the corresponding service.
    • Gateway (gw) needs to be deployed only if something changes in libs/shared-types or in gateway itself
    • If something changes in libs/, deploy the affected services.