graphql-express-postgres
graphql-express-postgres copied to clipboard
A reference graphql api.
graphql-express-postgres

A reference graphql api built with node and postgres.
The schema follows the classic user, posts, comments structure.
- Uses Apollo Server
- Examples of sql query caching using data loader
- Schema definitions are built using graphql-tools.
- Data access built on the Objection ORM and knex.
- Authentication handled by express-jwt middleware.
- For protected resolvers simply wrap the function in
authenticated(). - Tests use jest and execute against a database instance seeded with test data.
Install:
- run locally with nodemon + babel:
npm run dev - build and run on a server:
npm start - db migrations:
npm run migrate - format code:
npm run prettier - lint code:
npm run eslint - tests:
createdb blog-testthennpm test
Samples
Queries
{
viewer {
email
posts {
title
comments {
body
}
}
}
}
Mutations
mutation{addUser(name:"User", email:"[email protected]", password:"password") }
mutation{createToken(email:"[email protected]", password:"password") }
Database
Manually run the migrations/seeds
createdb blog-test
./node_modules/.bin/babel-node ./node_modules/.bin/knex migrate:latest --env test
./node_modules/.bin/babel-node ./node_modules/.bin/knex seed:run --env test
Prior Art:
- express/babel setup: https://github.com/vmasto/express-babel
- knex ideas: https://github.com/dYale/knexBlogBackend
- graphql schema: https://github.com/mrblueblue/graphql-express-sqlite
- authentication: https://scaphold.io/community/blog/authentication-in-graphql/
- data loader: https://spin.atomicobject.com/2017/05/15/optimize-graphql-queries/