Skip to content

Latest commit

 

History

History
 
 

api

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

.
├── auth/                       # Authentication middleware
├── enums/                      # GraphQ enumeration types
├── 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
├── package.json                # Node.js dependencies
├── schema.graphql              # Auto-generated GraphQL API schema
├── schema.ts                   # GraphQL API schema definition
├── server.js                   # Application launcher for local development
├── session.ts                  # Stateless JWT-based session middleware
└── 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 [--no-cache]      # Lint code with ESLint
$ yarn g:test                   # Run unit tests with Jest
$ yarn tsc                      # Check the code for type errors using TypeScript

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.