DEV Community


Make a fast Auto GraphQL Server with NodeJS and Postgres in 5 minutes !

J'aime faire des choses inutiles ๐Ÿ˜…
ใƒป1 min read

Hello World !
Too many loves in my last post

Today i show you how to mount a fast Auto Schema GraphQL server with NodeJS and Postgres Database in 5 minutes.

The the first thing is mount Postgres database with Docker !

docker run --name mydb-postgres -e POSTGRES_PASSWORD=12345 -p 5432:5432 -d postgres  

(default user is : postgres , default db is : postgres)

You can try to connect with DBeaver it's a good Postgres UI tool


create a folder for your NodeJS project

mkdir awesome-graphql-server
cd awesome-graphql-server

Init npm packages

npm init

Install Express and Postgraphile

Postgraphile is a very good tool to auto schema your Graphql based on your Postgres structure (relations include , very awesome)

npm install express
npm install postgraphile

so this is the simple code to have to insert in your index.js

touch index.js
nano index.js

insert this inside

var express = require('express');

const {
} = require("postgraphile");

var app = express();
        process.env.DATABASE_URL || "postgres://postgres:12345@",
        "public", {
            watchPg: true,
            graphiql: true,
            enhanceGraphiql: true,
app.listen(4000, () => console.log('go to for playground graphiql http://localhost:4000/graphiql'))

after launch

node index.js

And go to http://localhost:4000/graphiql
Welcome to your Graphql Auto schema playground !

The endpoint for Graphql request is

Thanks for your feedbacks !

Discussion (6)

simerca profile image
Ayrton Author

Hi ! Don't forget to discuss with me because I love coffee, like you โ˜•๏ธ !

gevera profile image
Denis Donici • Edited

Would love to see a more in-depth tutorial with maybe authentication and roles or subscriptions

simerca profile image
Ayrton Author

Good idea ! I can work on it

Thread Thread
gevera profile image
Denis Donici • Edited

Please do, because there are no proper tutorials online that will describe how to implement subscriptions. I have tried to implement subscriptions myself with no luck so far.

sametweb profile image
Samet Mutevelli

I will take a look at this, it looks interesting. Thanks for sharing!

simerca profile image
Ayrton Author

Yes very helpful !