matt-sm / graphql-express-postgres

A reference graphql api.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

graphql-express-postgres Build Status Coverage Status

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-test then npm test

Samples

Queries

{
  viewer {
    email
    posts {
      title
      comments {
        body
      }
    }   
  }
}

Mutations

mutation{addUser(name:"User", email:"user@test.com", password:"password") }
mutation{createToken(email:"user@test.com", 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:

About

A reference graphql api.

License:MIT License


Languages

Language:JavaScript 100.0%