From 715964177936b82d1eaef5849e62961185fb7eff Mon Sep 17 00:00:00 2001 From: Andreas Hubel Date: Sun, 25 Nov 2018 17:13:40 +0100 Subject: [PATCH] c3d-graphql: switch from npx to index.js --- c3d-graphql/Dockerfile | 10 ++++------ c3d-graphql/package.json | 12 ++++++++++++ c3d-graphql/run_server.sh | 2 -- c3d-graphql/src/index.js | 25 +++++++++++++++++++++++++ docker-compose.yaml | 3 ++- 5 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 c3d-graphql/package.json delete mode 100644 c3d-graphql/run_server.sh create mode 100644 c3d-graphql/src/index.js diff --git a/c3d-graphql/Dockerfile b/c3d-graphql/Dockerfile index b77ae00..88b9705 100644 --- a/c3d-graphql/Dockerfile +++ b/c3d-graphql/Dockerfile @@ -3,12 +3,10 @@ FROM node:8.9.0 WORKDIR /app ENV NODE_ENV=production -#ADD package.json yarn.lock .npmrc /app/ -#RUN unset NODE_ENV; yarn install +ADD package.json yarn.lock /app/ +RUN unset NODE_ENV; yarn install ADD . /app/ -#RUN yarn build -#CMD npx postgraphile -c postgres:///c3data -w -h 0.0.0.0 -p 5000 - -EXPOSE 5000 +RUN yarn build +CMD yarn start diff --git a/c3d-graphql/package.json b/c3d-graphql/package.json new file mode 100644 index 0000000..ef1998a --- /dev/null +++ b/c3d-graphql/package.json @@ -0,0 +1,12 @@ +{ + "dependencies": { + "@graphile-contrib/pg-simplify-inflector": "^3.0.0", + "express": "^4.16.4", + "postgraphile": "^4.0.1", + "postgraphile-plugin-connection-filter": "^1.0.0-beta.20" + }, + "scripts": { + "start": "node src/index.js", + "start:direct": "postgraphile --plugins postgraphile-plugin-connection-filter -w -n 0.0.0.0" + } +} diff --git a/c3d-graphql/run_server.sh b/c3d-graphql/run_server.sh deleted file mode 100644 index afcee20..0000000 --- a/c3d-graphql/run_server.sh +++ /dev/null @@ -1,2 +0,0 @@ -#/bin/sh -npx postgraphile -c postgres:///c3data -w -n 0.0.0.0 diff --git a/c3d-graphql/src/index.js b/c3d-graphql/src/index.js new file mode 100644 index 0000000..c4638d3 --- /dev/null +++ b/c3d-graphql/src/index.js @@ -0,0 +1,25 @@ +const express = require("express"); +const { postgraphile } = require("postgraphile"); +const ConnectionFilterPlugin = require("postgraphile-plugin-connection-filter"); +const SimplifyInflectorPlugin = require("@graphile-contrib/pg-simplify-inflector"); + +const app = express(); + +app.use( + postgraphile(process.env.DATABASE_URL || "postgres:///c3data", "public", { + graphiql: true, + enhanceGraphiql: true, + appendPlugins: [ConnectionFilterPlugin, SimplifyInflectorPlugin], + graphileBuildOptions: { + // https://github.com/graphile-contrib/postgraphile-plugin-connection-filter#performance-and-security + connectionFilterComputedColumns: false, + connectionFilterSetofFunctions: false, + connectionFilterLists: false + }, + watchPg: true, + disableQueryLog: false, + //pgDefaultRole: "viewer" + }) +); + +app.listen(process.env.PORT || 5000); diff --git a/docker-compose.yaml b/docker-compose.yaml index 35f8f43..5c56dc7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,11 +17,12 @@ services: c3d-graphql: build: c3d-graphql depends_on: ['postgres'] - command: npx postgraphile -c "postgres://graphql:graphql@postgres/c3data" -n 0.0.0.0 --watch + command: yarn start links: ['postgres'] ports: ['5000:5000'] environment: - PORT=5000 + - DATABASE_URL=postgres://grapqhl:graphql@postgres/c3data postgres: image: postgres:10.5 environment: