Skip to content

p8ul/apollo-graphql-express-boilerplate

Repository files navigation

Coverage Status Build Status

apollo-graphql-express-boilerplate

A GraphQL with Apollo, Express and PostgreSQL boilerplate project.

Features

  • Apollo-server
    • Queries, Mutations, Subscriptions, Error Handling, Playground, Custom Scalars, Authentication, Integration Testing, Schema directives
  • Authentication
    • powered by JWT
    • Sign Up, Sign In
  • PostgreSQL Database with Sequelize
    • entities: Users & Posts
  • Authorization
    • protected resolvers
  • Testing

Stack

  • Node.js
  • Express
  • PostgreSQL
  • Sequelize
  • apollo-server-express
  • JWT authentication
  • Jest
  • Eslint

Installation

  • git clone https://github.com/p8ul/apollo-graphql-express-boilerplate.git
  • cd apollo-graphql-express-boilerplate
  • yarn
  • start PostgreSQL database
  • create two databases for testing and development
  • create a .env file and copy the keys from .env.example file

cp .env.example .env

    # Your Graphql Port
    PORT=4000
    # Decoding Secret
    SECRET="awesome_secret"
    DATABASE_NAME= # the name of the PostgreSQL database
    DATABASE_USERNAME= # username  of the PostgreSQL database
    DATABASE_PASSWORD= # password of the username
    TEST_DATABASE_NAME= # test database name

Running the app

  • yarn start
  • navigate to http://localhost:4000/graphql

Playground

  1. Sign Up
mutation {
  register(name: "admin", email: "admin@example.com", password: "123456") {
    token
  }
}
  1. Login
mutation {
  login(email: "admin@example.com", password: "123456") {
    token
  }
}
  1. List Users
query {
  users {
    email
    name
    id
  }
}
  1. Add Post
mutation {
  addPost(
    title: "Combo House"
    body: "this is a post body"
    file: "http://modern.realhomes.io/wp-content/uploads/2015/07/property-10-exterior-680x510.jpg"
  ) {
    title
  }
}
  1. List Post
query {
  posts{
    title
    id
    file
  }
}
  1. Post added subscription
subscription {
  postAdded {
    title
    body
    file
  }
}

More Schemas.. Schemas

testing

  • run yarn test