stokilo / pg-public

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Postgraphile + AWS lambda + SST

Proof of concept of deploying Postgraphile on AWS Lambda.

https://www.graphile.org/postgraphile/

Official documentation for AWS lambda deployment:

https://github.com/graphile/postgraphile-lambda-example

This repository has some additional integrations i.e.

Data migration from npm scripts
Typescript typings
Schema generation and caching
SST integration
React app integration. 

Build

Install dependencies

yarn

Run SST in dev mode (remove sso script from package.json in case you don't use SSO)

yarn start

Run react client

yarn run dev

Login to the AWS Console -> Api Gateway -> Copy API URL. Replace Rest API URL in main.tsx

Data migration

Run

yarn migrate

It will create database schema and populate with initial data.

Features

Run the server and open http://127.0.0.1:5173/todo

Todo list implementation based on GraphQL schema autogenerated from RDS.

Typescript models are generated with graphql codegen tool. URQL is used on the client side.

img_2.png

Viewer to play around with autogenerated schema: http://127.0.0.1:5173/view

Schema is generated under generated/schema.gql. Typescript models under generated/api.d.ts. You can change database in the stacks/migration/db/init.sql, add new tables with relations 1-N, N-N, run yarn migrate. This will regenerate all typings and you can use viewer to query the data.

img.png

Only queries are generated from the database. Mutations are disabled and implemented in the Typescript (Lambda code).

Notes

This is sandbox app. Some stacks are unsafe i.e. RDS endpoint is placed in public subnet!!!. Some settings are hardcoded i.e. API URL in the file main.tsx.

Change also S3 bucket names in the S3Migration.ts - these originally are assigned to author's package name.

About


Languages

Language:PLpgSQL 51.5%Language:TypeScript 41.9%Language:JavaScript 4.4%Language:CSS 1.4%Language:HTML 0.4%Language:Shell 0.3%