Skip to content

Modern webserver in Haskell: Graphql + Postgresql + Authentication + DB migration + Dotenv and more

License

Notifications You must be signed in to change notification settings

dandoh/web-haskell-graphql-postgres-boilerplate

Repository files navigation

Modern Haskell Webserver Boilerplate

  • Graphql API
      type User {
          id: Int!
          email: String!
          name: String!
          updatedAt: String!
          createdAt: String!
      }
    
      type Session {
          token: String!
          user: User!
      }
    
      type Query {
          login(email: String!, password: String!): Session!
          myUserInfo: User!
      }
    
      type Mutation {
          register(email: String!, password: String!, name: String!): Session!
          changePassword(oldPassword: String!, newPassword: String!): Boolean!
      }
  • Database:

This boilerplate wires up:

  • Reading .env using envy
  • Database
  • Graphql API
  • Authorization using JWT
  • Monad transformers

Running

  • Feed in you database & secret in .env:
    $ cp .env.default .env
    
    DATABASE_URL="postgres://Dandoh:[email protected]:5432/webhaskell?sslmode=disable"
    JWT_SECRET="my_jwt_secret"
  • Migrations
    $ dbmate up
    
  • Run webserver
    $ stack run
    

Running on Docker

  • Feed in you database & secret in .env:
    $ cp .env.default .env
    
  • (Optional) Edit anything you need in the .env file
  • Create and start docker containers
    $ docker-compose up -d
    
  • Enter inside the docker workspace container
    $ docker exec -it web-haskell-graphql-postgres-boilerplate_workspace_1 /bin/bash
    
  • Migrations
    $ dbmate up
    
  • Run webserver
    $ stack run
    
  • Now you can visit: http://localhost:8080/ in your local machine.