From d417b9cf3df6ddf9c39eb7247a767c6bbb502038 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Thu, 6 Sep 2018 12:31:54 -0500 Subject: [PATCH] expose graphiql; temporary comment out postgraphile subscription setup; update subscription setup after doc was fixed --- postgraphile/package.json | 9 ++++- postgraphile/spec/server/config.spec.ts | 5 ++- postgraphile/spec/server/runtime.spec.ts | 7 +++- postgraphile/src/adapters/postgraphile.ts | 5 ++- postgraphile/src/index.ts | 6 ++- postgraphile/src/server/config.ts | 8 +++- postgraphile/src/server/interface.ts | 2 + postgraphile/src/server/runtime.ts | 2 +- postgraphile/yarn.lock | 47 +++++++++++++---------- 9 files changed, 61 insertions(+), 30 deletions(-) diff --git a/postgraphile/package.json b/postgraphile/package.json index 73c046f7..16339225 100644 --- a/postgraphile/package.json +++ b/postgraphile/package.json @@ -22,15 +22,17 @@ "homepage": "https://github.com/vulcanize/vulcanizedb", "dependencies": { "express-session": "1.15.6", - "graphql-subscriptions": "0.5.8", "lodash": "4.17.10", "passport": "0.4.0", "pg-native": "3.0.0", "postgraphile": "4.0.0-rc.4", + "graphql-subscriptions": "0.5.8", "subscriptions-transport-ws": "0.9.14", - "toml": "2.3.3" + "toml": "2.3.3", + "pg": "6.4.2" }, "devDependencies": { + "@types/graphql": "^0.13.4", "@types/express": "4.16.0", "@types/express-session": "1.15.10", "@types/jasmine": "2.8.8", @@ -47,5 +49,8 @@ "webpack": "4.17.1", "webpack-cli": "3.1.0", "webpack-dev-server": "3.1.6" + }, + "resolutions": { + "pg": "6.4.2" } } diff --git a/postgraphile/spec/server/config.spec.ts b/postgraphile/spec/server/config.spec.ts index c1da9316..6b68b4d3 100644 --- a/postgraphile/spec/server/config.spec.ts +++ b/postgraphile/spec/server/config.spec.ts @@ -27,6 +27,7 @@ describe('buildServerConfig', () => { .createSpyObj(['call']), serverUtilities = { + pluginHook: jasmine.createSpy('pluginHook'), enableSubscriptions: jasmine.createSpy('enableSubscriptions'), express: jasmine.createSpy('express'), expressSession: jasmine.createSpy('expressSession'), @@ -82,8 +83,8 @@ describe('buildServerConfig', () => { it('provides the database config to Postgraphile', () => { expect(serverUtilities.postgraphile).toHaveBeenCalledWith( - databaseConfig.host, - databaseConfig.database, + `${databaseConfig.host}/${databaseConfig.database}`, + ["public", "maker"], jasmine.any(Object)); }); diff --git a/postgraphile/spec/server/runtime.spec.ts b/postgraphile/spec/server/runtime.spec.ts index c7707dc5..0d3d993d 100644 --- a/postgraphile/spec/server/runtime.spec.ts +++ b/postgraphile/spec/server/runtime.spec.ts @@ -14,6 +14,7 @@ describe('bootServer', () => { beforeEach(() => { serverUtilities = { + pluginHook: jasmine.createSpy('pluginHook'), enableSubscriptions: jasmine.createSpy('enableSubscriptions'), express: jasmine.createSpy('express'), expressSession: jasmine.createSpy('expressSession'), @@ -24,7 +25,11 @@ describe('bootServer', () => { serverConfig = { middleware: jasmine.createSpyObj(['call']), - options: { simpleSubscriptions: true, webSocketMiddlewares: [] }, + options: { + pluginHook: jasmine.createSpy('pluginHook'), + simpleSubscriptions: true, + graphiql: true, + webSocketMiddlewares: [] }, port: 5678 }; diff --git a/postgraphile/src/adapters/postgraphile.ts b/postgraphile/src/adapters/postgraphile.ts index 8ba97d3b..629f344e 100644 --- a/postgraphile/src/adapters/postgraphile.ts +++ b/postgraphile/src/adapters/postgraphile.ts @@ -1,5 +1,6 @@ import { RequestHandler } from 'express'; import { Server } from 'http'; +import { PluginHookFn } from 'postgraphile/build/postgraphile/pluginHook'; // NOTE (jchristie@8thlight.com) Shape of the middleware is not // currently important to this application, but if a need arises, @@ -8,7 +9,9 @@ import { Server } from 'http'; export interface PostgraphileMiddleware extends RequestHandler {} export interface PostgraphileOptions { + pluginHook: PluginHookFn, simpleSubscriptions: boolean; + graphiql: boolean; // NOTE (jchristie@8thlight.com) Shape of the middlewares is not // currently important to this application, but if a need arises, // any needed shape can be assigned from a custom type here. @@ -17,7 +20,7 @@ export interface PostgraphileOptions { export type PostgraphileInitCallback = ( databaseUrl: string, - databaseName: string, + schemas: string[], options: PostgraphileOptions ) => PostgraphileMiddleware; diff --git a/postgraphile/src/index.ts b/postgraphile/src/index.ts index 81ead023..d14aa0d6 100644 --- a/postgraphile/src/index.ts +++ b/postgraphile/src/index.ts @@ -1,5 +1,5 @@ import { createServer } from 'http'; -import { postgraphile } from 'postgraphile'; +import { postgraphile, makePluginHook } from 'postgraphile'; import { readFileSync } from 'fs'; import express = require('express'); @@ -11,6 +11,7 @@ const { default: PostGraphileSupporter, enhanceHttpServerWithSubscriptions, } = require('@graphile/plugin-supporter'); +const pluginHook = makePluginHook([PostGraphileSupporter]); import { ServerUtilities } from './server/interface'; import { bootServer } from './server/runtime'; @@ -31,7 +32,8 @@ const serverUtilities: ServerUtilities = { expressSession: session, httpServerFactory: createServer, passport, - postgraphile + postgraphile, + pluginHook }; const databaseConfig = parseConfig(readFileSync, toml.parse, configPath); diff --git a/postgraphile/src/server/config.ts b/postgraphile/src/server/config.ts index 356d7535..05dca1f3 100644 --- a/postgraphile/src/server/config.ts +++ b/postgraphile/src/server/config.ts @@ -22,9 +22,12 @@ export function buildServerConfig( const expressSessionHandler = utilities.expressSession(); const passportInitializer = utilities.passport.initialize(); const passportSessionHandler = utilities.passport.session(); + const pluginHook = utilities.pluginHook; const options: PostgraphileOptions = { + pluginHook: pluginHook, simpleSubscriptions: true, + graphiql: true, webSocketMiddlewares: [ expressSessionHandler, passportInitializer, @@ -33,7 +36,10 @@ export function buildServerConfig( }; const middleware: PostgraphileMiddleware = utilities.postgraphile( - databaseConfig.host, databaseConfig.database, options); + `${databaseConfig.host}/${databaseConfig.database}`, + ["public", "maker"], + options + ); return { middleware, options, port: parseInt(port, 10) }; } diff --git a/postgraphile/src/server/interface.ts b/postgraphile/src/server/interface.ts index c4eec759..b1d251b7 100644 --- a/postgraphile/src/server/interface.ts +++ b/postgraphile/src/server/interface.ts @@ -12,6 +12,7 @@ import { PostgraphileMiddleware, PostgraphileOptions } from '../adapters/postgraphile'; +import { PluginHookFn } from 'postgraphile/build/postgraphile/pluginHook'; export interface DatabaseConfig { host: string; @@ -31,4 +32,5 @@ export interface ServerUtilities { httpServerFactory: CreateHttpServerCallback; passport: StaticPassportProvider; postgraphile: PostgraphileInitCallback; + pluginHook: PluginHookFn } diff --git a/postgraphile/src/server/runtime.ts b/postgraphile/src/server/runtime.ts index 0adfef2a..cf42fe6d 100644 --- a/postgraphile/src/server/runtime.ts +++ b/postgraphile/src/server/runtime.ts @@ -13,6 +13,6 @@ export function bootServer( httpServer, config.middleware, config.options); - + httpServer.listen(config.port); } diff --git a/postgraphile/yarn.lock b/postgraphile/yarn.lock index 1f3aec1b..825c7c4e 100644 --- a/postgraphile/yarn.lock +++ b/postgraphile/yarn.lock @@ -1572,6 +1572,10 @@ gauge@~2.7.3: strip-ansi "^3.0.1" wide-align "^1.1.0" +generic-pool@2.4.3: + version "2.4.3" + resolved "https://registry.yarnpkg.com/generic-pool/-/generic-pool-2.4.3.tgz#780c36f69dfad05a5a045dd37be7adca11a4f6ff" + get-caller-file@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" @@ -2123,6 +2127,10 @@ jasmine@3.2.0: glob "^7.0.6" jasmine-core "~3.2.0" +js-string-escape@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/js-string-escape/-/js-string-escape-1.0.1.tgz#e2625badbc0d67c7533e9edc1068c587ae4137ef" + js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" @@ -2689,6 +2697,10 @@ number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" +object-assign@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0" + object-assign@^4.0.1, object-assign@^4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" @@ -2958,9 +2970,12 @@ pg-native@3.0.0: pg-types "^1.12.1" readable-stream "1.0.31" -pg-pool@~2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.3.tgz#c022032c8949f312a4f91fb6409ce04076be3257" +pg-pool@1.*: + version "1.8.0" + resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-1.8.0.tgz#f7ec73824c37a03f076f51bfdf70e340147c4f37" + dependencies: + generic-pool "2.4.3" + object-assign "4.1.0" pg-sql2@2.2.1: version "2.2.1" @@ -2969,7 +2984,7 @@ pg-sql2@2.2.1: "@types/pg" "^7.4.10" debug ">=2 <3" -pg-types@^1.12.1: +pg-types@1.*, pg-types@^1.12.1: version "1.13.0" resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-1.13.0.tgz#75f490b8a8abf75f1386ef5ec4455ecf6b345c63" dependencies: @@ -2979,28 +2994,20 @@ pg-types@^1.12.1: postgres-date "~1.0.0" postgres-interval "^1.1.0" -pg-types@~1.12.1: - version "1.12.1" - resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-1.12.1.tgz#d64087e3903b58ffaad279e7595c52208a14c3d2" - dependencies: - postgres-array "~1.0.0" - postgres-bytea "~1.0.0" - postgres-date "~1.0.0" - postgres-interval "^1.1.0" - -"pg@>=6.1.0 <8": - version "7.4.3" - resolved "https://registry.yarnpkg.com/pg/-/pg-7.4.3.tgz#f7b6f93f5340ecc2596afbb94a13e3d6b609834b" +pg@6.4.2, "pg@>=6.1.0 <8": + version "6.4.2" + resolved "https://registry.yarnpkg.com/pg/-/pg-6.4.2.tgz#c364011060eac7a507a2ae063eb857ece910e27f" dependencies: buffer-writer "1.0.1" + js-string-escape "1.0.1" packet-reader "0.3.1" pg-connection-string "0.1.3" - pg-pool "~2.0.3" - pg-types "~1.12.1" - pgpass "1.x" + pg-pool "1.*" + pg-types "1.*" + pgpass "1.*" semver "4.3.2" -pgpass@1.x: +pgpass@1.*: version "1.0.2" resolved "https://registry.yarnpkg.com/pgpass/-/pgpass-1.0.2.tgz#2a7bb41b6065b67907e91da1b07c1847c877b306" dependencies: