Skip to content

Instantly share code, notes, and snippets.

@unreadable
Last active December 21, 2018 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unreadable/34f43dce95835c000b9391215c3074ec to your computer and use it in GitHub Desktop.
Save unreadable/34f43dce95835c000b9391215c3074ec to your computer and use it in GitHub Desktop.
Postgraphile getting started

Start pg server

sudo brew services start postgresql

Make postgres as default user

export PGUSER=postgres

Create pg database

createdb test

Connect to database

psql test

Create users table for testing by pasting the following code in the pg console

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE users (
    id uuid PRIMARY KEY DEFAULT uuid_generate_v1(),
    createdAt TIMESTAMP DEFAULT NOW(),
    last_name TEXT,
    first_name TEXT,
    address TEXT,
    city TEXT
);

INSERT INTO users (last_name, first_name, address, city) VALUES ('alex', 'and', 'St 07', 'Focsani');
INSERT INTO users (last_name, first_name, address, city) VALUES ('well', 'dan', 'St 43', 'Bucuresti');
INSERT INTO users (last_name, first_name, address, city) VALUES ('radu', 'man', 'St 65', 'Brasov');
INSERT INTO users (last_name, first_name, address, city) VALUES ('cosmin', 'dum', 'St 03', 'Bucuresti');
INSERT INTO users (last_name, first_name, address, city) VALUES ('serban', 'coc', 'St 21', 'Roman');

Install postgraphile

sudo npm i -g postgraphile

Run the graphql server

postgraphile -c "postgres://localhost:5432/test" --watch --cors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment