expose graphiql; temporary comment out postgraphile subscription setup;

update subscription setup after doc was fixed
This commit is contained in:
Taka Goto 2018-09-06 12:31:54 -05:00
parent ed5b6c8f14
commit d417b9cf3d
9 changed files with 61 additions and 30 deletions

View File

@ -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"
}
}

View File

@ -27,6 +27,7 @@ describe('buildServerConfig', () => {
.createSpyObj<PostgraphileMiddleware>(['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));
});

View File

@ -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<PostgraphileMiddleware>(['call']),
options: { simpleSubscriptions: true, webSocketMiddlewares: [] },
options: {
pluginHook: jasmine.createSpy('pluginHook'),
simpleSubscriptions: true,
graphiql: true,
webSocketMiddlewares: [] },
port: 5678
};

View File

@ -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;

View File

@ -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);

View File

@ -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) };
}

View File

@ -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
}

View File

@ -13,6 +13,6 @@ export function bootServer(
httpServer,
config.middleware,
config.options);
httpServer.listen(config.port);
}

View File

@ -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: