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
.
├── 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- 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 seedsLaunch 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 . # 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 JestUse 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.