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.
- Node.js
v12
, Yarnv2
, TypeScript, Babel, Prettier, ESLint — core platform and dev tools - GraphQL.js, GraphQL.js Relay, DataLoader, Validator.js — GraphQL schema and API endpoint(s)
- PostgreSQL, Knex.js,
pg
,@google-cloud/storage
— data access jswonwebtoken
,google-auth-library
— stateless JWT-based sessions and authentication- Jest - unit and snapshot testing
.
├── 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
- Node.js v12 or higher, Yarn package manager
- Local or remote instance of PostgreSQL (see Postgres.app, Google Cloud SQL)
- VS Code editor (highly recommended)
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
environments — dev
(default), local
, test
, or prod
.
The app must become available on http://localhost:8080/graphql
.
$ 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
Use yarn start-debug
instead of yarn start
then attach VS Code debugger to
the running instance of the app.
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.
Copyright © 2016-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.