Skip to content

Table Football – GraphQL API Server, a supporting backend service for the Table Football React Web App front-end project (https://github.com/R-H-T/football)

Notifications You must be signed in to change notification settings

R-H-T/tf-graphql

Repository files navigation

Table Football – GraphQL API Server

This server was intended as a supporting backend service for the Table Football React Web App front-end project I made earlier. Both are still work in progress, the master-branch contains the stable version of the project.


Index:


Getting Started

Setup (Step-by-Step)

Run all the terminal commands within the project root directory.

1. Node.JS 📦

This Project was developed using Node v8.11.3. (see https://nodejs.org for how to setup Node)

Upgrade npm to the latest version (Recommended):

$ sudo npm i -g npm@latest

Install The Global Dependencies:

$ sudo npm i -g prisma@ graphql-cli

Install Project Dependencies:

$ npm i

2. Docker & Docker Compose 🐳

Mac & Windows Users

See Docker for easy setup instructions for Mac & Windows users (https://www.docker.com/get-started).

Linux Users:

Auto-detected by script:

$ curl -fsSL get.docker.com -o get-docker.sh && sh det-docker.sh

(Note: Verify that https://get.docker.com is the same script as install.sh at https://github.com/docker/docker-install before you run this command).

Ubuntu:

$ apt-get update && apt-get upgrade && apt-get install docker python-pip && pip install docker-compose

Alpine Linux:

$ apk update && apk upgrade && apk add docker py-pip && pip install docker-compose

Docker Compose runs the GraphQL Database Container (aka the Data Layer) – which will be directly connected with our GraphQL API Backend (aka the Business Layer containing all the logic, and filtering the access to the Data Layer).

Run the following command to start the server:

$ cd database; docker-compose up -d; cd -

3. Prisma🔺

This was installed in the steps specified for 1. Node.JS. Prisma will generate some files to to the src/generated directory based on your schema specifications inside the database/prisma.graphql file.

Deploy the existing database schema:

$ prisma deploy

Start The GraphQL API Server 🖲

Make sure that the docker-compose containers are up and running the command $ docker-compose ps.

Start The Server

$ npm start

The project should be running on https://localhost:3001 and you should see a GraphQL playground to test your queries.

Example GraphQL Queries

query getInfo {
  info
}

query allPlayers {
  players {
    id
    name
  }
}

(Note: See the GraphQL Playground Schema-tab or the source code's src/schema.graphql file for available queries, mutations, inputs, subscriptions, etc. Run the signup query to retrieve an Authorization token for the Headers section inside the playground, add eg.: { "Authorization" : "Bearer YOUR-AUTH-TOKEN-HERE" })

Direct Access

To directly access the data layer, run the following commands:

$ prisma playground

This fires up another playground for directly modifying the database. Though, in order to send queries – you'll need an authorization token. Run the following command to generate one:

$ prisma token

Add that token to the GraphQL Playground's Headers section, eg.:

  { "Authorization" : "Bearer YOUR-AUTH-TOKEN-HERE" }

Enjoy!


Future Plans

Planning to make this project run within its own Docker container or/and just deploy it to Heroku and Amazon Web Services (AWS). And do some API documentation.


License

TBD Copyright ©2018 – Roberth Hansson-Tornéus – R-H-T ([email protected])