Giter Site home page Giter Site logo

dandoh / web-haskell-graphql-postgres-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
121.0 5.0 11.0 120 KB

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

License: MIT License

Haskell 78.45% PLpgSQL 11.28% Makefile 0.33% Dockerfile 1.79% Shell 1.84% HTML 6.30%
haskell graphql graphql-server postgresql opaleye morpheus typesafe scotty dbmate migration

web-haskell-graphql-postgres-boilerplate's Introduction

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
    

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.

web-haskell-graphql-postgres-boilerplate's People

Contributors

dandoh avatar emadshaaban92 avatar pacific01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

web-haskell-graphql-postgres-boilerplate's Issues

error: JSON.parse

Hi, I think I set this up correctly and I'm using the query

query {
  myUserInfo {
    name
  }
}

but I just get this error with no much information

{
  "error": "JSON.parse: unexpected character at line 1 column 1 of the JSON data"
}

I admit I don't know graphql that well but what can I do to get a more useful error?

Update template to GHC 9.4.4

Hi, this template looks amazing and it is just what I was looking for!

However, since it is 3 years old and I'm trying to build it with an M1, stack and ghc versions are too old, maybe this could be updated? ๐Ÿ™๐Ÿป

Thanks in advance!

License on the project will be good

Hello.

First of all I wat to thank you (@dandoh) for this boilerplate. It helps me, a lot, to understand how to make a setup for a Haskell web application. I have use it in on of my side project as my base, which led me to think about whether I can use it or not license wise.

It will be great if it can has some license.

I have seen a lot of BSD-3-Clause and MIT aswell in the haskell comunity and both of them will be okay.

Thank you.

Array Objects

Hello,

I noticed that in the most recent commit, things like MaybeObject and ArrayObject were removed in favor of Composed. I was originally trying to return an array of Users with ArrayObject and have since updated to Composed, but either way I have not been able to get it compiling. Would it be possible to include an example that implements the following query?

type Query {
  ...
  allUsers: [User!]!
  ...
}

I tried looking at the morpheus documentation as well, but it looks quite different from the patterns used here. I'm new so I'm sure I'm missing something but any help would be appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.