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.
- 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-test
thennpm test
{
viewer {
email
posts {
title
comments {
body
}
}
}
}
mutation{addUser(name:"User", email:"user@test.com", password:"password") }
mutation{createToken(email:"user@test.com", password:"password") }
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
- 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/