0.144.3 • Published 4 years ago

signage-next-graphql v0.144.3

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
4 years ago

ScreenCloud Signage Next GraphQL API

ScreenCloud Signage API built on PostgreSQL and GraphQL

Requirements

  • Node.js (>= 13.6)
  • npm (>= 6.13)
  • Docker

Setup

Clone the repo

$ git clone git@github.com:screencloud/signage-next-graphql.git

Install the npm dependencies

$ npm install

Copy the .env file across via the example and make changes accordingly

$ cp .env.development .env.development.local

You must run the API under https://signage-api.dev.next.sc locally, to do this you will need to self-sign a SSL certificate for *.dev.next.sc. See our guide on how to do this on windows or mac.

Add the server.key and server.crt for *.dev.next.sc into a /ssl folder in this repo's root folder.

Ensure you have Docker installed, then create a docker account via the app. Now login to docker via the terminal

$ docker login

Start the Docker instance

$ docker-compose up -d

The -d will run docker in detached mode (background service), omit the -d to keep docker running in the foreground (useful if you want more debugging).

Now we must migrate the database (more on migrations below)

$ npm run migrate

Now start the API

$ npm start

This will run the API through nodemon, which will watch the API and automatically restart the application when file changes in the directory are detected. Run npm start to start the API normally via node. For extra debugging you can run DEBUG="postgraphql*" npm start.

To stop the Docker instance, stop the node process (cmd/ctrl+c) and run

$ docker-compose stop

Reset

To remove the docker instance and destroy the DB (reset everything) you can run

$ docker-compose down

To keep the Docker instance running, but reset the entire database and seed you can run

$ npm run db:reset

This will drop the database, start the docker instance, migrate the database and seed it. It will then start the node service automatically.

Migrations

To migrate your database.

$ npm run migrate

To rollback the last migration.

$ npm run migrate:rollback

To rollback all migrations and reset the database.

$ npm run migrate:reset

To create a new migration file (you should have the sequelize-cli installed globally)

$ sequelize migration:create --name some-name-for-migration

When naming your migration file, please follow the format used by the existing migrations (dashes only - and no underscores _) in /migrations. E.g. create-tablename, alter-tablename-add-column etc.

Seeding

To seed the database.

$ npm run seed

To unseed the database (reset all seeders).

$ npm run seed:reset

To create a new seed file.

$ sequelize seed:create --name=tablename-seeder

Generating new types and mutations:

Make sure the docker instance is running, then...

    npm run migrate:test
    npm run start:test

Now open another terminal tab/window and run:

    npm run get-schema:test
    npm run gen:test

Testing

To run the test suite

$ npm run migrate:test
$ npm run start:test

then in a different terminal

$ npm run gen:test
$ npm run test

Commands

Below is a list of all NPM commands.

# Migrate the database (should be run whenever new migrations are added)
$ npm run migrate
# Rollback to the last migration (revert the last migration)
$ npm run migrate:rollback
# Revert all migrations (reset the DB to default empty state)
$ npm run migrate:reset
# Seed the database
$ npm run seed
# Unseed the database (reset all seeds)
$ npm run seed:reset
# Run the Postgraphile service in development with out JWT authentication
$ NODE_ENV=hack npm start
# Run the Postgraphile service in development, NODE_ENV=development
$ npm start
# Run the Postgraphile service in production, NODE_ENV=production
$ npm start
# Run SchemaSpy against the DB to visualise the DB schema, replace DB_OWNER_ID with your local db owner id
$ DB_USERNAME=DB_OWNER_ID npm run visualize
# Run all tests
$ npm run test
# Recreate all database (drop and recreate)
$ npm run db:recreate
# Reset database data, reset migration and seed then re-run migration and seed
$ npm run db:reset

Create Database Visualize Relation Report

To create the graphical report for tables and relations

$ DB_USERNAME=example_db_username npm run visualize

Content JSON Structure

https://paper.dropbox.com/doc/Refined-Content-JSON-Structure--AISHe6i~4H_xk8mFcn0M8Mg9Ag-JRnVlcHa4JpWWdaMjXbyc

Rules JSON Structure

https://paper.dropbox.com/doc/Contents-Rules-JSON-Structure--AIQEJ1_PiWAOySW35JVMCF8RAg-AiFJ3zatAmBxTLpXap7jc

GraphQL

For query and mutations examples please check inside __test__ folder.

Using the docker image

There are docker images generated for this project, which can be used CI, deploy and dev use-cases. The image is available on Docker Hub here.

The most recent tagged master commit, usually a tag done by semantic-release, is tagged as latest and therefor will be the default image to pull. Additionally all tags on master-branch are also available with matching tags, e.g. get version v1.2.3 by using image screencloud/signage-graphql:v1.2.3

The image is self-starting and requires a migrated database. Internally it runs the project with PM2.

Configuring the image

All env vars can be either set directly on container start or via a .env-file.

GraphIQL

It doesn't work and we don't intend to fix that. It's an annoying bundling issue and no one is using it anyway...

docker

If you want to run run signage-graphql with USE_SSL=true, prepare a ssl-folder with server.crt and server.key files inside.

If you want to pass in all required env vars via an .env prepare it as well. Alternatively you can inject all env vars via cli or compose files.

docker run

With neither ssl-folder or .env-file simply run with all required env vars:

  • docker run -d -e "<envKey1>:<envValue1>" -e "<envKey2>:<envValue2>" -p 5000:5000 screencloud/signage-graphql

With both ssl-folder and .env-file in your CWD:

  • CMD: docker run -d --env-file .env -v %CD%/ssl:/app/ssl:ro -p 5000:5000 screencloud/signage-graphql
  • Bash: docker run -d --env-file .env -v ${pwd}/ssl:/app/ssl:ro -p 5000:5000 screencloud/signage-graphql
  • PS: docker run -d --env-file .env -v "$($(get-location).Path)/ssl:/app/:ro" -p 5000:5000 screencloud/signage-graphql

To interact with a running container you'll need to retrieve the docker container id using docker ps first, then you can run

  • docker exec <containerId> ls -la inspect the current working directory (aka. /app)
  • docker exec <containerId> ./migrate to migrate the database
  • docker exec <containerId> ./seed to seed the database
  • docker exec <containerId> node sequelize to access sequelize
  • docker exec -it <containerId> sh to start an interactive shell session

docker compose

With both ssl-folder and .env-file add to your docker-compose.yml. In this example the local .env-file is called .env.graphql as its likely near other .env-files. If you're running with USE_SSL as proxy or `false, you can skip the volume mount.

graphql:
  image: screencloud/signage-graphql:${SIGNAGE_GRAPHQL_VERSION:-latest}
  container_name: signage-graphql
  restart: always
  env_file: .env.graphql
  volumes:
    - ./ssl:/app/ssl
  ports:
    - 5000:5000

To interact with the composed container simply run:

  • docker-compose exec graphql ./migrate to migrate the database
  • docker-compose exec graphql ./seed to seed the database
  • docker-compose exec graphql node sequelize to access sequelize-cli
  • docker-compose exec graphql sh to start an interactive shell session

add a signage-graphql-database container

To add a matching database container add another service to your docker-compose.yml

db:
  image: screencloud/signage-graphql-database:${SIGNAGE_GRAPHQL_VERSION:-latest}
  container_name: signage-graphql-database
  restart: always
  environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: password
    POSTGRES_DB: screencloud
  ports:
    - 35432:5432

If you prefer an empty database, with no seeds or migrations applied, instead use:

db:
  image: screencloud/postgres-signage:${POSTGRES_SIGNAGE_VERSION:-10.5}
  container_name: signage-graphql-database
  restart: always
  environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: password
    POSTGRES_DB: screencloud
  ports:
    - 35432:5432
0.144.3

4 years ago

0.144.2

4 years ago

0.144.1

4 years ago

0.144.0

4 years ago

0.143.0

4 years ago

0.142.0

4 years ago

0.141.1

4 years ago

0.141.0

4 years ago

0.139.0

4 years ago

0.138.1

4 years ago

0.140.2

4 years ago

0.140.1

4 years ago

0.140.0

4 years ago

0.140.4

4 years ago

0.140.3

4 years ago

0.137.0

4 years ago

0.138.0

4 years ago

0.136.0

4 years ago

0.135.1

4 years ago

0.135.0

4 years ago

0.134.1

4 years ago

0.134.0

4 years ago

0.133.5

4 years ago

0.133.4

4 years ago

0.133.3

4 years ago

0.133.2

4 years ago

0.133.1

4 years ago

0.133.0

4 years ago

0.132.4

4 years ago

0.132.3

4 years ago

0.132.2

4 years ago

0.132.1

4 years ago

0.131.2

4 years ago

0.131.1

4 years ago

0.132.0

4 years ago

0.131.0

4 years ago

0.130.4

4 years ago

0.130.3

4 years ago

0.130.2

4 years ago

0.130.1

4 years ago

0.130.0

4 years ago

0.129.4

4 years ago

0.129.3

4 years ago

0.129.2

4 years ago

0.129.1

4 years ago

0.129.0

4 years ago

0.128.4

4 years ago

0.128.3

4 years ago

0.128.2

4 years ago

0.128.1

4 years ago

0.128.0

4 years ago

0.127.4

4 years ago

0.127.3

4 years ago

0.127.2

4 years ago

0.127.1

4 years ago

0.127.0

4 years ago

0.126.1

4 years ago

0.126.0

4 years ago

0.125.1

4 years ago

0.125.0

4 years ago

0.124.10

4 years ago

0.124.9

4 years ago

0.124.8

4 years ago

0.124.7

4 years ago

0.124.6

4 years ago

0.124.5

4 years ago

0.124.4

4 years ago

0.124.3

4 years ago

0.124.2

4 years ago

0.124.1

4 years ago

0.124.0

4 years ago

0.123.0

4 years ago

0.122.1

4 years ago

0.122.0

4 years ago

0.121.1

4 years ago

0.121.0

4 years ago

0.120.5

4 years ago

0.120.6

4 years ago

0.120.4

4 years ago

0.120.3

4 years ago

0.120.2

4 years ago

0.120.1

4 years ago

0.120.0

4 years ago

0.119.3

4 years ago

0.119.2

4 years ago

0.119.1

4 years ago

0.119.0

4 years ago

0.118.11

4 years ago

0.118.10

4 years ago

0.118.9

4 years ago

0.118.8

4 years ago

0.118.6

4 years ago

0.118.7

4 years ago

0.118.5

4 years ago

0.118.4

4 years ago

0.118.3

4 years ago

0.118.0

4 years ago

0.118.1

4 years ago

0.118.2

4 years ago

0.117.1

4 years ago

0.117.0

4 years ago

0.116.5

4 years ago

0.116.6

4 years ago

0.116.4

4 years ago

0.116.2

4 years ago

0.116.1

4 years ago

0.116.0

4 years ago

0.115.0

4 years ago

0.114.2

4 years ago

0.114.1

4 years ago

0.114.0

4 years ago

0.113.2

4 years ago

0.113.1

4 years ago

0.113.0

4 years ago

0.112.8

4 years ago

0.112.7

4 years ago

0.112.6

4 years ago

0.112.5

4 years ago

0.112.4

4 years ago

0.112.3

4 years ago

0.112.2

4 years ago

0.112.1

4 years ago

0.112.0

4 years ago

0.111.0

4 years ago

0.110.1

4 years ago

0.110.0

4 years ago

0.109.1

4 years ago

0.109.0

4 years ago

0.108.1

4 years ago

0.108.0

4 years ago

0.107.4

4 years ago

0.107.3

4 years ago

0.107.2

4 years ago

0.107.1

4 years ago

0.107.0

4 years ago

0.106.10

4 years ago

0.106.9

4 years ago

0.106.8

5 years ago

0.106.7

5 years ago

0.106.6

5 years ago

0.106.5

5 years ago

0.106.4

5 years ago

0.106.3

5 years ago

0.106.2

5 years ago

0.106.1

5 years ago

0.106.0

5 years ago

0.105.5

5 years ago

0.105.4

5 years ago

0.105.3

5 years ago

0.105.2

5 years ago

0.105.1

5 years ago

0.105.0

5 years ago

0.104.2

5 years ago

0.104.1

5 years ago

0.104.0

5 years ago

0.103.0

5 years ago

0.102.4

5 years ago

0.102.3

5 years ago

0.102.2

5 years ago

0.102.1

5 years ago

0.102.0

5 years ago

0.101.0

5 years ago

0.100.4

5 years ago

0.100.3

5 years ago

0.100.2

5 years ago

0.100.1

5 years ago

0.100.0

5 years ago

0.99.0

5 years ago

0.98.0

5 years ago

0.97.0

5 years ago

0.96.2

5 years ago

0.96.1

5 years ago

0.96.0

5 years ago

0.95.0

5 years ago

0.94.2

5 years ago

0.94.1

5 years ago

0.94.0

5 years ago

0.93.21

5 years ago

0.93.20

5 years ago

0.93.19

5 years ago

0.93.18

5 years ago

0.93.17

5 years ago

0.93.16

5 years ago

0.93.15

5 years ago

0.93.14

5 years ago

0.93.13

5 years ago

0.93.12

5 years ago

0.93.11

5 years ago

0.93.10

5 years ago

0.93.9

5 years ago

0.93.8

5 years ago

0.93.7

5 years ago

0.93.6

5 years ago

0.93.5

5 years ago

0.93.4

5 years ago

0.93.3

5 years ago

0.93.2

5 years ago

0.93.1

5 years ago

0.93.0

5 years ago

0.92.0

5 years ago

0.91.0

5 years ago

0.90.1

5 years ago

0.90.0

5 years ago

0.89.1

5 years ago

0.89.0

5 years ago

0.88.4

5 years ago

0.88.3

5 years ago

0.88.2

5 years ago

0.88.1

5 years ago

0.88.0

5 years ago

0.87.0

5 years ago

0.86.8

5 years ago

0.86.7

5 years ago

0.86.6

5 years ago

0.86.5

5 years ago

0.86.4

5 years ago

0.86.3

5 years ago

0.86.2

5 years ago

0.86.1

5 years ago

0.86.0

5 years ago

0.85.0

5 years ago

0.84.1

5 years ago

0.84.0

5 years ago

0.83.1

5 years ago

0.83.0

5 years ago

0.82.0

5 years ago

0.81.1

5 years ago

0.81.0

5 years ago

0.80.0

5 years ago

0.79.1

5 years ago

0.79.0

5 years ago

0.78.0

5 years ago

0.77.2

5 years ago

0.77.1

5 years ago

0.77.0

5 years ago

0.76.0

5 years ago

0.75.0

5 years ago

0.74.1

5 years ago

0.74.0

5 years ago

0.73.2

5 years ago

0.73.1

5 years ago

0.73.0

5 years ago

0.72.2

5 years ago

0.72.1

5 years ago

0.72.0

5 years ago

0.71.1

5 years ago

0.71.0

5 years ago

0.70.3

5 years ago

0.70.2

5 years ago

0.70.1

5 years ago

0.70.0

5 years ago

0.69.1

5 years ago

0.69.0

5 years ago

0.68.0

5 years ago

0.67.0

5 years ago

0.66.0

5 years ago

0.65.3

5 years ago

0.65.2

5 years ago

0.65.1

5 years ago

0.65.0

5 years ago

0.64.0

5 years ago

0.63.0

5 years ago

0.62.0

5 years ago

0.61.0

5 years ago

0.60.1

5 years ago

0.60.0

5 years ago

0.59.0

5 years ago

0.58.2

5 years ago

0.58.1

5 years ago

0.58.0

5 years ago

0.57.4

5 years ago

0.57.3

5 years ago

0.57.2

5 years ago

0.57.1

5 years ago

0.57.0

5 years ago

0.56.1

5 years ago

0.56.0

5 years ago

0.55.1

5 years ago

0.55.0

5 years ago

0.54.0

5 years ago

0.53.2

5 years ago

0.53.1

5 years ago

0.53.0

5 years ago

0.52.0

5 years ago

0.51.0

5 years ago

0.50.0

5 years ago

0.49.0

5 years ago

0.48.1

5 years ago

0.48.0

5 years ago

0.47.0

5 years ago

0.46.0

5 years ago

0.45.0

5 years ago

0.44.0

5 years ago

0.43.0

5 years ago

0.42.4

5 years ago

0.42.3

5 years ago

0.42.2

5 years ago

0.42.1

5 years ago

0.42.0

5 years ago

0.41.0

5 years ago

0.40.4

5 years ago

0.40.3

5 years ago

0.40.2

5 years ago

0.40.1

5 years ago

0.40.0

5 years ago

0.39.1

5 years ago

0.39.0

5 years ago

0.38.9

5 years ago

0.38.8

5 years ago

0.38.7

5 years ago

0.38.6

5 years ago

0.38.5

5 years ago

0.38.4

5 years ago

0.38.3

5 years ago

0.38.2

5 years ago

0.38.1

5 years ago

0.38.0

5 years ago

0.37.1

5 years ago

0.37.0

5 years ago

0.36.3

5 years ago

0.36.2

5 years ago

0.36.1

5 years ago

0.36.0

5 years ago

0.35.1

5 years ago

0.35.0

5 years ago

0.34.1

5 years ago

0.34.0

5 years ago

0.33.0

5 years ago

0.32.0

5 years ago

0.31.0

5 years ago

0.30.6

5 years ago

0.30.5

5 years ago

0.30.4

5 years ago

0.30.3

5 years ago

0.30.2

5 years ago

0.30.1

5 years ago

0.30.0

5 years ago

0.29.0

5 years ago

0.28.0

5 years ago

0.27.0

5 years ago

0.26.2

5 years ago

0.26.1

5 years ago

0.26.0

5 years ago

0.25.2

5 years ago

0.25.1

5 years ago

0.25.0

5 years ago

0.24.4

5 years ago

0.24.3

5 years ago

0.24.2

5 years ago

0.24.1

5 years ago

0.24.0

5 years ago

0.23.2

5 years ago

0.23.1

5 years ago

0.23.0

5 years ago

0.22.1

5 years ago

0.22.0

5 years ago

0.21.3

5 years ago

0.21.2

5 years ago

0.21.1

5 years ago

0.21.0

5 years ago

0.20.0

5 years ago

0.19.0

5 years ago

0.18.0

5 years ago

0.17.0

5 years ago

0.16.0

5 years ago

0.15.2

5 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.14.2

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.1

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago