Giter Club home page Giter Club logo

serverless-postgraphql's Introduction

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

Official lambda implementation from the postgraphql-creators: https://github.com/graphile/postgraphile-lambda-example

How to use my implementation:

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

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

serverless-postgraphql's Issues

Trouble getting results

I've followed the how to and am not able to get a good response. I can run the non serverless postgraphsql forum example just fine locally and query it using graphiql.

My pg connection after sls deploy looks like this:

"config": {
  "PGCON": "postgres://example:serverless@MY_PG_ENDPOINT:5432/forumexample"
},

And my YML:

environment:
  PGCON: postgres://example:serverless@MY_PG_ENDPOINT:5432/forumexample
  JWT_SECRET: keyboard_kitten

When I try to run graphiql using postgraphql-local or from the pgcon url using this query:

{
  postById(id: 3) {
    id
    headline
  }
}

yields:

{
  "errors": [
    {
      "message": "permission denied to set role \"forum_example_anonymous\""
    }
  ]
}

Same query with Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoxLCJiIjoyLCJjIjozfQ.hxhGCCCmGV9nT1slief1WgEsOsfdnlVizNrODxfh1M8:

{
  "errors": [
    {
      "message": "invalid signature"
    }
  ]
}

Testing with a custom modified JWT Token I get (expected this):

{
  "errors": [
    {
      "message": "jwt audience invalid. expected: postgraphql"
    }
  ]
}

My remote endpoint deployment response from going to /graphql is this:

{"errors":[{"name":"error","length":113,"severity":"ERROR","code":"42501","file":"guc.c","line":"9604","routine":"call_string_check_hook"}]}

v4 PostGraphile Support

Thanks for making this repo. We're evaluating postgraphql on lambda and this has been super helpful. I have been looking at targeting v4 (aka PostGraphile). It looks like there's introspection caching built in (with "plugin support" that I need to learn more about).

Do you still have energy for this project? Would you be keen to see a PR for v4 support?

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.