resource-watch/graph-client

View on GitHub
README.md

Summary

Maintainability
Test Coverage
# Graph client Microservice

[![Build Status](https://travis-ci.com/resource-watch/graph-client.svg?branch=dev)](https://travis-ci.com/resource-watch/graph-client)
[![Test Coverage](https://api.codeclimate.com/v1/badges/5fbe8f9c23d81587d091/test_coverage)](https://codeclimate.com/github/resource-watch/graph-client/test_coverage)

## Dependencies

You will need [Control Tower](https://github.com/control-tower/control-tower) up and running - either natively or with Docker. Refer to the project's README for information on how to set it up.

The Graph client microservice is built using [Node.js](https://nodejs.org/en/), and can be executed either natively or using Docker, each of which has its own set of requirements.

Native execution requires:
- [Node.js](https://nodejs.org/en/)
- [MongoDB](https://www.mongodb.com/)

Execution using Docker requires:
- [Docker](https://www.docker.com/)
- [Docker Compose](https://docs.docker.com/compose/)

Dependencies on other Microservices:
- [Dataset](https://github.com/resource-watch/dataset/)

## Getting started

Start by cloning the repository from github to your execution environment

```
git clone https://github.com/resource-watch/graph-client.git && cd graph-client
```

After that, follow one of the instructions below:

### Using native execution

1 - Set up your environment variables. See `dev.env.sample` for a list of variables you should set, which are described in detail in [this section](#configuration-environment-variables) of the documentation. Native execution will NOT load the `dev.env` file content, so you need to use another way to define those values

2 - Install node dependencies using yarn:
```
yarn
```

3 - Start the application server:
```
yarn start
```

The endpoints provided by this microservice should now be available through Control Tower's URL.

### Using Docker

1 - Create and complete your `dev.env` file with your configuration. The meaning of the variables is available in this [section](#configuration-environment-variables). You can find an example `dev.env.sample` file in the project root.

2 - Execute the following command to run Control tower:

```
./graphClient.sh develop
```

The endpoints provided by this microservice should now be available through Control Tower's URL.

## Testing

There are two ways to run the included tests:

### Using native execution

Follow the instruction above for setting up the runtime environment for native execution, then run:
```
npm test
```

### Using Docker

Follow the instruction above for setting up the runtime environment for Docker execution, then run:
```
./graphClient.sh test
```

## Configuration

### Environment variables

- PORT => TCP port in which the service will run
- NODE_PATH => relative path to the source code. Should be `app/src`
- MICROSERVICE_TOKEN => 

You can optionally set other variables, see [this file](config/custom-environment-variables.json) for an extended list.


This repository is the node skeleton microservice to create node microservice for WRI API

1. [Getting Started](#getting-started)

## Getting Started

### OS X

**First, make sure that you have the [API gateway running
locally](https://github.com/control-tower/control-tower).**

We're using Docker which, luckily for you, means that getting the
application running locally should be fairly painless. First, make sure
that you have [Docker Compose](https://docs.docker.com/compose/install/)
installed on your machine.

```

git clone https://github.com/Vizzuality/graph-client
cd graph-client
./service.sh develop
./service.sh test
```text

You can now access the microservice through the CT gateway.

```

### Configuration

It is necessary to define these environment variables:

* GATEWAY_URL => Control Tower URL
* NODE_ENV => Environment (prod, staging, dev)

## Database constraints

Add the next constraints in Neo4j:

```
// only one dataset node with the same id
CREATE CONSTRAINT ON (dataset:DATASET) ASSERT dataset.id IS UNIQUE

// only one widget node with the same id
CREATE CONSTRAINT ON (widget:WIDGET) ASSERT widget.id IS UNIQUE

// only one layer node with the same id
CREATE CONSTRAINT ON (layer:LAYER) ASSERT layer.id IS UNIQUE

// only one metadata node with the same id
CREATE CONSTRAINT ON (metadata:METADATA) ASSERT metadata.id IS UNIQUE


```