Skip to content

A skeleton/seed repository for writing an Apollo GraphQL service

Notifications You must be signed in to change notification settings

subhankarshah/apollo-graphql-server

Repository files navigation

Apollo GraphQL Seed Project

This repository can be used as a basic sturucture to start off with an Apollo GraphQL service. I have made sure most of the heavy-lifting is done, and you can start off by simply cloning the repo and writing business logic. Things I have taken care of:

  • Typescript setup for type safety and Object Oriented Structure
  • Dotenv for configuration using .env.* files
  • Efficient multistage Docker build (rebuilds a layer only if required) & Docker-compose
  • Dependency Injection using Inversify
  • Hot Reload with debugger(for VS Code editor) using nodemon for fast development
  • A basic structure for writing cron jobs using node-cron
  • A simple directory structure in line with following convention:
    • Controllers: Called resolvers in GraphQL terminology, contain application logic and passing user input data to service.
    • Services: The middleware between controller and repository. Gather data from controller, performs validation and business logic, and calling repositories for data manipulation.
    • Repositories: Layer for interaction with models and performing DB operations.
    • Models: A model is called type in GraphQL terminology, they are defined in schema files with relationships.

Hasura is a framework that provides a GraphQL query interface over a postgre database, I have used Hasura as an ORM and datasource in this project. You can use any other ORM over any other database of your choice.

Getting Started

Clone the repository

git clone https://github.com/subhankarshah/apollo-graphql-starter.git
cd apollo-graphql-starter

Setup Node & Install Dependencies

Install Node & Run

npm install

Setup Hasura

Deploy Hasura with one-click on Heroku with the free Postgres add-on:

Deploy to Heroku

Or Deploy Hasura locally using Docker-compose

docker-compose up -d graphql-engine

Create Schema in Hasura

Create a simple schema via Hasura Console as shown in the demo below: Hasura GraphQL Engine Demo

Make the following schema for testing this repo (TODO: add migration to automate this)

  • Create a user schema
  • Create a user table, under this schema
  • Create an id field of type UUID
  • Create fields firstName, lastName, mobile, email of type Text

Environment Variables

The following env varibles: NODE_ENV, HASURA_ADMIN_SECRET, HASURA_END_POINT Are set in docker-compose.yaml for Docker deployments OR in nodemon.json for local development

All other env varialbes are set in .env.{NODE_ENV} files

Development

For hot reload without debugger, run

npm run dev

For hot reload without debugger(VS code), run the command below and attach debugger to node process

npm run dev:debug

Deployment using Docker

Run following commands

docker-compose build
docker-compose up -d apollo-graphql-server

About

A skeleton/seed repository for writing an Apollo GraphQL service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published