Setting up a GraphQL Backend without GraphCool

Wijnand Karsens
LECKR
Published in
2 min readMay 9, 2018

First of all, here is how you can set up a GraphQL Server locally. It starts with my basic server setup; I use GraphQL, Express, Sequelize, SQLite, and Git for this.

- git init whole project, create git repo, set remote, commit, push

- code .gitignore server/dist node_modules , client …. 1 git for all

- folder server

- yarn init, yarn add -D nodemon, babel-cli, babel-preset-env, eslint, prettier-eslint

- zorg dat prettier plugin en eslint plugin in VSCode werken en controlleer dit

- add typescript

- ./node_modules/.bin/eslint — init with airbnb preset

- create scripts in package.json

- dev: nodemon — exec babel-node — presets=env — plugins=transform-runtime lib

- build: babel lib -d dist — presets env

- serve pm2 start dist/index.js

- leg ook uit wat deze commandos precies doen en wanneer je ze gebruikt

- create index:

- connectors (sequelize docs)

- schema, resolvers, server execution (apollo graphql docs)

- test it with GraphiQL, SQLite, en DB Browser for SQLite

2) Remote server

Secondly, this is the way to enable a remote server to handle the script

  • Create secure linode server: reference to other article
  • Git push
  • set up nginx, pm2, git, node, mysql, etc
  • create mysql database with proper name
  • git pull
  • yarn, yarn build, yarn serve
  • test with GraphiQL

1) add name servers of preferred domain pointing to cloudflare (dana&paul.ns.cloudflare.com)

2) setup CloudFlare DNS

  • Point CNAME record www and @ to na-west1.surge.sh
  • Point A record server.example.com to server IP
  • Crypto → Origin certificate, save these values!

3) use any static website project but probably the React Bootstrap App theme that I modified, build it, and upload it using “surge ./build/ example.com”

4) setup a server with Ubuntu 16.04 and Nginx that has this in /etc/nginx/sites-enabled/default

server { listen 80;
listen 443 ssl;
ssl_certificate /ssl/cert.pem;
ssl_certificate_key /ssl/key.key;
access_log /var/log/nginx/nginx.vhost.access.log;
error_log /var/log/nginx/nginx.vhost.error.log;
location /yourprojectname {
proxy_pass http://localhost:3045/graphql;
}
}

5) restart nginx: sudo systemctl restart nginx

6) Make sure the process indeed runs on this location and port using pm2

Extra: Add TypeScript, how? Typescript with node or express server

1) Yarn add -D typescript

2) Yarn add tslib

3) TSconfig.json → see online

4) figure out how to compile and build and stuff.

— — -

I’m available for contracting work in the summer of 2018 onwards. Let me know if you’re interested by sending an email to me at karsens AT outlook DOT com. My biggest skills are: React Native, Node JS, GraphQL (Apollo), and MySQL. My expertise is creating MVP’s quickly.

--

--

Wijnand Karsens
LECKR
Editor for

I am a programmer, writer and entrepreneur. Read more from me on http://karsens.com/