dandoh/web-haskell-graphql-postgres-boilerplate

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

Haskell

123

52 commits

updated Mar 29, 2023

See the code

README

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:dandoh@127.0.0.1:5432/webhaskell?sslmode=disable"
    JWT_SECRET="my_jwt_secret"
    
  • Migrations
    $ dbmate up
    
  • Run webserver
    $ stack run
    

Now GraphQL API is at http://localhost:8080/api

You can also access Graphql Playground at http://localhost:8080/graphiql

Playground

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
    
  • Now you can visit: http://localhost:8080/ in your local machine.

  • Migrations will automatically run, and you can run them manually anytime using

    $ docker-compose up dbmate
    
  • Stack will restart whenever you change any .hs file, thanks to entr

Contributors

PR are more than welcome. The only note is we use ormolu to format codes.

database
dbmate
graphql
graphql-api
graphql-server
haskell
jwt
jwt-authentication
migration
morpheus
opaleye
postgresql
scotty
stack
stack-haskell
typesafe
web
webserver
webserver-setup

Contributors

dandoh

44 commits

Pacific01

7 commits

emadshaaban92

1 commits

dandoh/web-haskell-graphql-postgres-boilerplate

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

Haskell

123

52 commits

updated Mar 29, 2023

See the code

README

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:dandoh@127.0.0.1:5432/webhaskell?sslmode=disable"
    JWT_SECRET="my_jwt_secret"
    
  • Migrations
    $ dbmate up
    
  • Run webserver
    $ stack run
    

Now GraphQL API is at http://localhost:8080/api

You can also access Graphql Playground at http://localhost:8080/graphiql

Playground

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
    
  • Now you can visit: http://localhost:8080/ in your local machine.

  • Migrations will automatically run, and you can run them manually anytime using

    $ docker-compose up dbmate
    
  • Stack will restart whenever you change any .hs file, thanks to entr

Contributors

PR are more than welcome. The only note is we use ormolu to format codes.

database
dbmate
graphql
graphql-api
graphql-server
haskell
jwt
jwt-authentication
migration
morpheus
opaleye
postgresql
scotty
stack
stack-haskell
typesafe
web
webserver
webserver-setup

Contributors

dandoh

44 commits

Pacific01

7 commits

emadshaaban92

1 commits

Languages

Haskell

78.4%

PLpgSQL

11.3%

HTML

6.3%

Shell

1.8%

Dockerfile

1.8%