PostGraphQL
Creating a Relay compatible GraphQL

server without a line of coding
PostGraphQL
or why the shift key has become

the most used key on my keyboard
auto generated backends
GET /articles
GET /articles
GET /articles/123
GET /articles
GET /articles/123
PUT /articles
GET /articles
GET /articles/123
PUT /articles
GET /articles
GET /articles/123
PUT /articles
GET /authors/abc
GET /articles
GET /articles/123
PUT /articles
GET /authors/abc
PUT /subscriptions/tag
GET /articles
GET /articles/123
PUT /articles
GET /authors/abc
PUT /subscriptions/tag
GET /articles?version=mobile
GET /articles
GET /articles/123
PUT /articles
GET /authors/abc
PUT /subscriptions/tag
GET /articles?version=mobile
client defined queries
per field access control
pagable connections
predictable mutations
define data-model

not custom views
define permissions
not protected routes
define cursors
not custom pagination
standardised mutations
not individual CRUD operations
auto-generated
backends
postgraphql
postgreSQL express graphQL
+ =
A GraphQL schema created by
reflection over a PostgreSQL schema
define your data graph in postgres
define your business logic in postgres
define your access control in postgres
schema definition
articles categories
1 1
1
n
authors
articles categories
articles_authors
1 1
1
1
authors
1 1
id title
article1 Reederei Rickmers kündigt…
id article_id author_id
1 article1 author1
2 article1 author2
id name
author1 Daniel
author2 Marc
ready for take off
PostGraphQL server listening on port 5000 🚀
‣ Connected to Postgres instance postgres://localhost:5432
‣ Introspected Postgres schema(s) public
‣ GraphQL endpoint served at http://localhost:5000/graphql
‣ GraphiQL endpoint served at http://localhost:5000/graphiql
postgraphql --watch
yarn global add postgraphql
relay pagination
sorting
conditions
connections
mutations
auto generated delete, update and
create mutations for all tables
custom mutations possible
relay compatible
demo
access control
connectDB('root','root','localhost:5432')
limited access
client API database
full access
CREATE ROLE 'viewer';
GRANT SELECT ON articles TO viewer;
CREATE ROLE 'editor';
GRANT ALL ON articles TO editor;
CREATE ROLE 'viewer';
GRANT SELECT ON articles TO viewer;
limited access
client API database
scoped access
Header

JWT
{
aud: 'postgraphql',
role: 'editor'
}
mutation {
createArticle(…) {
article {
…
}
}
}
Body

GraphQL
query
query {
allArticles {
nodes {
…
}
}
}
Body

GraphQL
query
defaultRole = 'viewer'
CREATE ROLE 'editor';
GRANT ALL ON articles TO editor;
CREATE ROLE 'viewer';
GRANT SELECT ON articles TO viewer;
id title status
1 Reederei Rickmers kündigt… PUBLISHED
2 Trump will Entscheidung… DRAFT
3 Protest gegen Abschiebung… DEPUBLISHED
4 FC Bayern wird Deutscher… SCHEDULED
SET row_security = on;
CREATE POLICY published ON articles

FOR SELECT TO viewer

USING status = 'PUBLISHED';
computed properties
{
article {
id: '123'
shareURL: 'https://br24.de/123'
}
}
CREATE FUNCTION 

article_share_url(article articles) as $$

SELECT 'https://br24.de/' || article.id;

$$

LANGUAGE SQL STABLE;
{
searchArticles(term: "Merkel") {
edges {
node {
title
}
}
}
}
demo
even more postgres
JSON support
event triggers
full text search
geospatial information
PostGraphQL
@danielbuechele
=

PostGraphQL