Giter Club home page Giter Club logo

serverless-postgraphql's Introduction

Serverless graphql endpoint for PostgresSQL database using AWS, serverless and postgraphql

How to use:

Setup

๐Ÿ’พ Install Serverless

๐Ÿ‘ฏ Clone the repo

git clone https://github.com/rentrop/serverless-postgraphql
cd serverless-postgraphql

๐Ÿ’พ Install

npm install

๐Ÿš€ Rebuild and Deploy

npm run rebuild-and-deploy

โ˜• Coffeetime: AWS takes ~10min to setup the Postgres DB

  • From the result of the serverless deployment take the pgEndpoint and insert it in:
    • package.json-file in the config of PGCON (line 7)
    • serverless.yml-file in the environment-variable named PGCON (line 21)

๐Ÿš€ Rebuild and Deploy Again

npm run rebuild-and-deploy

You are all set now. You can now query the resulting endpoint as you wish via POST and GET.

One example to authenticate a user would be:

mutation {
  authenticate(input: {email: "[email protected]", password: "iFbWWlc"}) {
    jwtToken
  }
}

You can try this by entering the following in your browser:

your-url/dev/graphql?query=mutation%20%7B%0Aauthenticate%28input%3A%20%7Bemail%3A%20%22spowell0%40noaa.gov%22%2C%20password%3A%20%22iFbWWlc%22%7D%29%20%7B%0AjwtToken%0A%7D%0A%7D

For most other queries you need to be authorised. Authorization in postgraphql is done via the jwtToken. Set this in your following requests as Authorization header:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoxLCJiIjoyLCJjIjozfQ.hxhGCCCmGV9nT1slief1WgEsOsfdnlVizNrODxfh1M8

Running Locally

๐Ÿ’พ Install Postgres ๐Ÿ˜

โŒจ๏ธ Initialize the database

npm run init-local-db

โŒจ๏ธ Run the local server

npm run local-server

TODO/Ideas

serverless-postgraphql's People

Contributors

rentrop avatar

Watchers

 avatar

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.