NextJS starter with GraphQL API routes and sequelize to interface with a postgres database. This starter is set up for remote development (i.e. without internet access) -- it uses Apollo's Graphql Playground and a local version of sequelize-cli.
- Clone repo
- Create new database1
- Create new
.envfile based on.env.example. Optionally update it with different database info - Run initial migration and seed with
yarn db:seed - Install deps:
yarn - Run project:
yarn dev
GraphQL playground is available at http://localhost:3000/api/graphql. The site index displays a list of todo items.
└───database
│ └───config
│ └───migrations
│ └───models
│ └───seeders
└───graphql
│ └───resolvers
│ └───schemas
└───src
│ └───pages
│ │ └───api
│ │ │ │ graphql.js
│ │ │ _app.js
│ │ │ index.js
│ └───client
│ │ index.js
database: This folder has been bootstrapped withsequelize-cligraphql: Folder for graphql schema and resolverssrc: Source folder.graphql.jsis the api route._app.jsimports the Apollo Client fromclient/index.js
- Generate a new model:
yarn model:generate --name Model --attributes name:string - Update model in
database/models/model.js - (Optional) Generate and write seed file
yarn seed:generate --name model-seed - Add model to graphql schema in
graphql/schema/model.js. Import and export schema file ingraphql/schema/index.js - Add resolvers to graphql schema in
graphql/resolvers/model.js. Import and export resolver file ingraphql/resolvers/index.js
sequelize-cli is a dev dependency of this starter, so some of the most frequently used commands have been aliased with yarn.
db:create: create database
db:drop: drop database
db:migrate: run migrations
model:generate: generate a new model. usually used with `--name Name --attributes Attributes`
seed:generate: generate a new seed file. usually used with `--name seed-name`
db:seed: run seed files
db:seed:undo: undo all seed files
db:reseed: drop database, create database, run migrations, seed database1: I recommend using psql. Run psql postgres to spin up a postgres command line. Then run create database ${database_name}.↩