Skip to content

Instantly share code, notes, and snippets.

View pratikagashe's full-sized avatar

Pratik pratikagashe

View GitHub Profile
@pratikagashe
pratikagashe / package.json
Created February 12, 2020 12:23
postgraphile-server: package.json v1
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js",
"watch": "nodemon src/index.js"
},
"author": "Pratik Agashe",
@pratikagashe
pratikagashe / index.js
Last active February 17, 2020 10:14
Node-express server index file for postgraphile demo - version 1
require('dotenv').config()
const cors = require('cors')
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const { PORT } = process.env
app.use(cors())
app.use(bodyParser.json())
@pratikagashe
pratikagashe / .env
Last active February 17, 2020 08:04
.env sample for postgraphile demo
CLIENT=pg
PORT=8080
DATABASE=postgres-graphql
PG_USER=postgres
PASSWORD=root
HOST=127.0.0.1
PG_PORT=5432
@pratikagashe
pratikagashe / postgraphile.js
Created February 17, 2020 08:13
Postgres database connection config for postgraphile demo
const { postgraphile } = require('postgraphile')
const { DATABASE, PG_USER, PASSWORD, HOST, PG_PORT } = process.env
module.exports = postgraphile(
{
database: DATABASE,
user: PG_USER,
password: PASSWORD,
host: HOST,
@pratikagashe
pratikagashe / knexfile.js
Created February 17, 2020 11:28
Knex migration config file.
require('dotenv').config()
const { CLIENT, DATABASE, PG_USER, PASSWORD, HOST, PG_PORT } = process.env
module.exports = {
development: {
client: CLIENT,
connection: {
database: DATABASE,
user: PG_USER,
@pratikagashe
pratikagashe / knex.js
Created February 17, 2020 11:38
Knex configuration file for server : postgraphile demo
const environment = process.env.NODE_ENV || 'development'
const config = require('../knexfile')[environment]
module.exports = require('knex')(config)
@pratikagashe
pratikagashe / migration_create_table.js
Last active February 17, 2020 12:06
migration_create_table file for postgraphile demo
exports.up = function(knex) {
return knex.schema
.createTable('users', function(table) {
table.increments().primary()
table.string('name', 255).notNullable()
table.string('email', 255).notNullable()
table.string('password', 255).notNullable()
table
.boolean('account_verified')
.notNullable()
@pratikagashe
pratikagashe / 01_users.js
Created February 17, 2020 13:27
Seed file to insert data into table postgraphile demo
exports.seed = function(knex) {
// Deletes ALL existing entries
return knex('users')
.del()
.then(function() {
// Inserts seed entries
return knex('users').insert([
{
id: 1,
name: 'Pratik Agashe',
@pratikagashe
pratikagashe / 02_posts.js
Created February 17, 2020 13:28
Seed file to insert data into posts postgraphile demo
exports.seed = function(knex) {
// Deletes ALL existing entries
return knex('posts')
.del()
.then(function() {
// Inserts seed entries
return knex('posts').insert([
{
id: 1,
title: 'Sample blog',
@pratikagashe
pratikagashe / index.js
Created February 17, 2020 13:59
Node-express server index file for postgraphile demo - version 2
require('dotenv').config()
const cors = require('cors')
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const postgraphile = require('./postgraphile')
const { PORT } = process.env
app.use(cors())