Coder Social home page Coder Social logo

gnyani / nodejs-api-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kriasoft/graphql-starter-kit

0.0 0.0 0.0 861 KB

๐Ÿ’ฅ A GraphQL API boilerplate (template) made with Node.js, TypeScript, and PostgreSQL

Home Page: https://graphqlstart.com

License: MIT License

JavaScript 7.53% TypeScript 92.47%

nodejs-api-starter's Introduction

GraphQL
Node.js API Starter Kit

Dependabot

Boilerplate and tooling for authoring (serverless) data API backends with Node.js and GraphQL. It is best suited for developing a GraphQL API endpoint as a standalone (micro)service (demo), backing up web front-ends and/or mobile apps (see React Starter Kit, React Firesbase Starter etc).


This project was bootstrapped with Node.js API Starter Kit (support).

GraphQL Demo
https://graphql-demo.kriasoft.com

Tech Stack

Directory Layout

.
โ”œโ”€โ”€ /build/                     # The compiled output (via Babel)
โ”œโ”€โ”€ /migrations/                # Database schema migrations
โ”œโ”€โ”€ /scripts/                   # Build automation scripts and utilities
โ”œโ”€โ”€ /seeds/                     # Scripts with reference/sample data
โ”œโ”€โ”€ /src/                       # Node.js application source files
โ”‚   โ”œโ”€โ”€ /mutations/             # GraphQL API mutations
โ”‚   โ”œโ”€โ”€ /queries/               # GraphQL API query fields
โ”‚   โ”œโ”€โ”€ /types/                 # GraphQL custom types
โ”‚   โ”œโ”€โ”€ /utils/                 # Utility functions (mapTo, mapToMany etc.)
โ”‚   โ”œโ”€โ”€ /auth.js                # Authentication middleware
โ”‚   โ”œโ”€โ”€ /context.ts             # Data loaders and other context-specific stuff
โ”‚   โ”œโ”€โ”€ /db.ts                  # Database access and connection pooling (via Knex)
โ”‚   โ”œโ”€โ”€ /errors.ts              # Custom errors and error reporting
โ”‚   โ”œโ”€โ”€ /fields.ts              # Helper functions for creating GraphQL query fields
โ”‚   โ”œโ”€โ”€ /index.ts               # Node.js application entry point
โ”‚   โ”œโ”€โ”€ /node.ts                # GraphQL Node interface
โ”‚   โ”œโ”€โ”€ /schema.ts              # GraphQL schema type
โ”‚   โ””โ”€โ”€ /validator.ts           # Input validation helpers
โ”œโ”€โ”€ babel.config.js             # Babel configuration
โ”œโ”€โ”€ docker-stack.yml            # Allows to launch PostgreSQL via Docker
โ”œโ”€โ”€ package.json                # List of project dependencies
โ”œโ”€โ”€ schema.graphql              # GraphQL schema file (auto-generated)
โ””โ”€โ”€ tsconfig.json               # TypeScript configuration

Prerequisites

Getting Started

Just clone the repo, tweak .env file in the root of the project, and run yarn start:

$ git clone https://github.com/kriasoft/nodejs-api-starter.git example-api
$ cd example-api                # Change current directory to the newly created one
$ yarn install                  # Install Node.js dependencies
$ yarn start                    # Launch Node.js API application. Or, yarn start --env=local

The API server must become available at http://localhost:8080/graphql (live demo).

How to Migrate Database Schema

While the app is in development, you can use a simplified migration workflow by creating a backup of your existing database, making changes to the existing migration file (see migrations/20180101000000_initial.ts), re-apply the migration and restore data from the backup file (backup.sql):

$ yarn db-backup --env=dev      # Or, yarn db-backup --env=test
$ yarn db-reset-dev             # Or, yarn db-reset-test

Upon deployment to production, switch to normal migration workflow:

$ yarn db-change <name>         # Create a new database migration file
$ yarn db-migrate --env=dev     # Migrate database to the latest version

HINT: Test your migration thoroughly with a local instance of the DB first (by using --env=local or --env=dev (default) flag) then apply it to your test or prod database instance using --env=test or --env=prod command argument.

Other helpful database scripts:

$ yarn db-version --env=dev     # Print the version number of the last migration
$ yarn db-rollback --env=dev    # Rollback the latest migration
$ yarn db-restore --env=dev     # Restore database from backup.sql
$ yarn db-seed --env=dev        # Seed database with test data
$ yarn db --env=dev             # Open Knex.js REPL shell (type ".exit" for exit)
$ yarn psql --env=dev           # Open PostgreSQL shell (type "\q" for exit)

How to Test

$ yarn lint                     # Check JavaScript and CSS code for potential issues
$ yarn lint-fix                 # Attempt to automatically fix ESLint warnings
$ yarn check                    # Check source code for type errors
$ yarn test                     # Run unit tests. Or, `yarn test --watch`

For more information visit https://jestjs.io/docs/getting-started

How to Deploy

$ yarn build                    # Build the app in production mode (NODE_ENV=production)
$ yarn deploy-test              # Deploy the app to TEST environment
$ yarn deploy-prod              # Deploy the app to PROD environment

For more information refer to the Deployment guide in the project's Wiki.

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 Update

If you keep the original Git history after cloning this repo, you can always fetch and merge the recent updates back into your project by running:

$ git remote add upstream https://github.com/kriasoft/nodejs-api-starter.git
$ git checkout master
$ git fetch upstream
$ git merge upstream/master
$ yarn install

NOTE: Try to merge as soon as the new changes land on the master branch in the upstream repository, otherwise your project may differ too much from the base/upstream repo. Alternatively, you can use a folder diff tool like Beyond Compare for keeping your project up to date with the base repository.

How to Contribute

Anyone and everyone is welcome to contribute. Start by checking out the list of open issues marked help wanted. However, if you decide to get involved, please take a moment to review the guidelines.

Related Projects

  • GraphQL.js โ€” The JavaScript reference implementation for GraphQL
  • DataLoader โ€” Batching and caching for GraphQL data access layer
  • React Starter Kit โ€” Isomorphic web app boilerplate (React, Node.js, Babel, Webpack, CSS Modules)
  • React Static Boilerplate โ€” Single-page application (SPA) starter kit (React, Redux, Webpack, Firebase)
  • Membership Database โ€” SQL schema boilerplate for user accounts, profiles, roles, and auth claims

License

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


Made with โ™ฅ by Konstantin Tarkus (@koistya, blog) and contributors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.