Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

GraphQL API Server

GraphQL API server implemented using code-first development approach and optimized for hosting in a serverless environment such as Google Cloud Functions or Google Cloud Run.


This project was bootstrapped with Node.js API Starter Kit. Be sure to join our Discord channel for assistance.

Tech Stack

.
├── scripts                     # Automation scripts
│   ├── deploy.ts               #   - deploys the app to Google Cloud
│   ├── push.ts                 #   - uploads package.zip to GCS bucket
│   ├── update-schema.ts        #   - generates `schema.graphql` file
│   └── update-types.ts         #   - generates TypeScript definitions
├── src                         #
│   ├── auth/                   # Authentication middleware
│   ├── mutations/              # GraphQL API mutation endpoints
│   ├── queries/                # The top-level GraphQL API query fields
│   ├── types/                  # GrapHQL API schema types
│   ├── utils/                  # Helper functions
│   ├── context.ts              # GraphQL API context variable(s)
│   ├── db.ts                   # PostgreSQL client and query builder
│   ├── errors.ts               # Custom error types
│   ├── fields.ts               # Helper functions for GraphQL fields
│   ├── index.ts                # GraphQL API server entry point
│   ├── node.ts                 # GraphQL Relay Node interface
│   ├── schema.ts               # GraphQL API schema definition
│   ├── validator.ts            # User input validator
│   └── session.ts              # Stateless JWT-based session middleware
├── babel.config.js             # Babel.js configuration
├── package.json                # Node.js dependencies
├── README.md                   # This file
├── schema.graphql              # Auto-generated GraphQL API schema
└── tsconfig.json               # TypeScript configuration

Requirements

Getting Started

Ensure that the database schema and data is up-to-date by running:

$ yarn db:reset                 # Re-creates the database and applies migrations and seeds

Launch the app in development mode (using Nodemon):

$ yarn api:start                # Launch the API server on http://localhost:8080/
$ yarn api:start-debug          # Alternatively, launch it with a debugger (chrome inspector)

Optionally pass the --env=#0 argument with one of the pre-configured environmentsdev (default), local, test, or prod.

The app must become available on http://localhost:8080/graphql.

How to Test

$ yarn g:lint .                 # Lint the code in the selected folder using ESLint
$ yarn tsc                      # Check the code for type errors using TypeScript
$ yarn test                     # Run unit tests with Jest

How to Debug

Use yarn start-debug instead of yarn start then attach VS Code debugger to the running instance of the app.

How to Deploy

Compile and bundle the code into package.zip (build), upload application bundle to Google Cloud Storage (push), and finally, deploy or re-deploy a Google Cloud Function straight from GCS (deploy).

$ yarn build
$ yarn push [--version=#0]
$ yarn deploy [--version=#0] [--env=#1]

NOTE: These three separate steps are required in order to optimize the CI/CD workflows.

License

Copyright © 2016-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.