Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Apollo server playground

A full-fledged Apollo Server 2 with Apollo Client 2 starter project with Express and PostgreSQL.

Graphql you say..

Fetch all data in a single roundtrip, and provide structured documentation for our APIs


  • Node.js with Express and Apollo Server 2
    • cursor-based Pagination
  • PostgreSQL Database with Sequelize
    • entities: users, messages
  • Rest api resolver for Ticketmaster using new datasource API
  • Authentication
    • powered by JWT and local storage
    • Sign Up, Sign In, Sign Out
  • Authorization
    • protected endpoint (e.g. verify valid session)
    • protected resolvers (e.g. e.g. session-based, role-based)
    • protected routes (e.g. session-based, role-based)
  • performance optimizations
    • example of using Facebook's dataloader
  • E2E testing

Postgres setup

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres

PSQL commands

docker exec -it some-postgres bash
psql -d postgres -U postgres
\l #list databases
\dt #list tables
\dn #list schemas
\s #command history

SELECT * from users;
SELECT text from messages;
CREATE DATABASE mytestdatabase; #create test database 

Install PgAdmin


nvm use \
&& yarn \
&& cp .env.example .env \
&& yarn start

Running queries locally

You’ll need to get one API key:


Sample headers

{"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywiZW1haWwiOiJzbGVlMUBzZWVrLmNvbS5hdSIsInVzZXJuYW1lIjoic2hhbmUxIiwiaWF0IjoxNTQzODA5NjU2LCJleHAiOjE1NDM4MTE0NTZ9.hKV1vR6kV3hCCAMxBtGsuXeZ5MUq1TIwQSGcvk_gb_M"}

Error handling

Error handling


To disable stacktraces for production, pass debug: false to the Apollo server constructor or set the NODE_ENV environment variable to ‘production’ or ‘test’. Note that this will make the stacktrace unavailable to your application. If you want to log the stacktrace, but not send it in the response to the client, see Masking and logging errors below.

Deployment options


replace value below for TM_API_KEY

DOCKER_BUILDKIT=1 docker build   -t shanelee007/graphql:1.0.0 -t  shanelee007/graphql:latest .
docker run -d -e TM_API_KEY=REDACTED -p 8000:8000 --link some-postgres  shanelee007/graphql:1.1.0


Easy and Repeatable Kubernetes Development

brew install skaffold
skaffold init #initialise the project with yaml config
skaffold config set --global local-cluster true #do not push images after building
skaffold dev -v=info #run locally/watching changes production mode

Release upgrade

brew upgrade skaffold
skaffold fix --overwrite

Run locally

There is a new feature for local dev to sync files, instead of rebuilding the whole artifact's image

profiles allows you to define build and deployment configurations for different contexts

To run in dev mode with sync run the following profile

skaffold dev -p dev -v=info #run locally/watching changes dev mode

If you like, you can try the experimental gui mode

skaffold dev -p dev -v=info --experimental-gui



replace secret for TM_API_KEY

echo -n 'XXX' | base64

replace value for key TM_API_KEY inside kubernetes/secret.yaml

NOTE both containers (graphql-api and postgres) are running inside the same pod. To productionise you would extract out the database and run AWS aurora for example

Kubernetes 1.13 now supports server dry run

kubectl create ns graphql

#need to have kubectl 1.13 installed or higher
kubectl apply -f kubernetes/ --server-dry-run

kubectl apply -f kubernetes/ -n graphql --record #this will create the deployment, service and the config on the cluster

kubectl exec -it <pod_name> -c graphql-api -n graphql  sh #inspect the container
kubectl logs -f <pod_name> -c graphql-api -n graphql #inspect the logs

kubectl exec -it <pod_name> -c postgres -n graphql bash #inspect the database
psql -d postgres -U postgres
\l #list databases

get the service to discover the public port exposed to access the api

$ kgsvcowide
NAME                                        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE       SELECTOR
graphql-api                                 NodePort    <none>        8000:30537/TCP   40m       app=graphql

Now using playground, you can for example access the endpoint over http://localhost:30537/graphql


Linkerd is a service mesh for Kubernetes and other frameworks. It makes running services easier and safer by giving you runtime debugging, observability, reliability, and security—all without requiring any changes to your code.

curl -sL | sh
export PATH=$PATH:$HOME/.linkerd2/bin
linkerd version
linkerd install | kubectl apply -f - #install to cluster
linkerd check #check its running
linkerd dashboard #explore control plane

Inject side car container to graphql deployment

kubectl get -n graphql deploy -o yaml \
 | linkerd inject - \
 | kubectl apply -f -

linkerd -n graphql check --proxy
linkerd -n graphql stat deploy

tap shows the stream of requests across the deployment

Linkerd includes Grafana to visualize all the great metrics collected by Prometheus and ships with some extremely valuable dashboards.




You can’t perform that action at this time.