From fbaf818008ee7f425f80cac6fb92118972b906dc Mon Sep 17 00:00:00 2001 From: eric-burel Date: Fri, 4 Jan 2019 09:59:23 +0100 Subject: [PATCH] fix voyager regression --- .../server/apollo-server/apollo_server2.js | 2 +- .../lib/server/apollo-server/defaults.js | 2 +- .../lib/server/apollo-server/graphiql.js | 35 +++++-------------- .../lib/server/apollo-server/voyager.js | 2 +- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/packages/vulcan-lib/lib/server/apollo-server/apollo_server2.js b/packages/vulcan-lib/lib/server/apollo-server/apollo_server2.js index 1f8fec74e..c529523f7 100644 --- a/packages/vulcan-lib/lib/server/apollo-server/apollo_server2.js +++ b/packages/vulcan-lib/lib/server/apollo-server/apollo_server2.js @@ -16,7 +16,7 @@ import {WebApp} from 'meteor/webapp'; // import Cookies from 'universal-cookie'; import voyagerMiddleware from 'graphql-voyager/middleware/express'; import getVoyagerConfig from './voyager'; -import { graphiqlMiddleware, getGraphiqlConfig } from './graphiql'; +import {graphiqlMiddleware, getGraphiqlConfig} from './graphiql'; import getPlaygroundConfig from './playground'; import initGraphQL from './initGraphQL'; diff --git a/packages/vulcan-lib/lib/server/apollo-server/defaults.js b/packages/vulcan-lib/lib/server/apollo-server/defaults.js index 7fea80ba6..00d447946 100644 --- a/packages/vulcan-lib/lib/server/apollo-server/defaults.js +++ b/packages/vulcan-lib/lib/server/apollo-server/defaults.js @@ -7,7 +7,7 @@ export const defaultConfig = { maxAccountsCacheSizeInMB: 1, configServer: apolloServer => {}, voyagerPath: '/graphql-voyager', - graphiqlPath: '/graphiql' + graphiqlPath: '/graphiql', }; export const defaultOptions = { diff --git a/packages/vulcan-lib/lib/server/apollo-server/graphiql.js b/packages/vulcan-lib/lib/server/apollo-server/graphiql.js index 84a82ebf9..144b1ab0e 100644 --- a/packages/vulcan-lib/lib/server/apollo-server/graphiql.js +++ b/packages/vulcan-lib/lib/server/apollo-server/graphiql.js @@ -3,18 +3,15 @@ export const getGraphiqlConfig = currentConfig => ({ passHeader: "'Authorization': localStorage['Meteor.loginToken']", // eslint-disable-line quotes }); - // LEGACY SUPPORT FOR GRAPHIQL -// Code is taken from apollo 1.4 code and +// Code is taken from apollo 1.4 code and // @see https://github.com/eritikass/express-graphiql-middleware // This is the only way to get graphiql to work import url from 'url'; - // @seehttps://github.com/apollographql/apollo-server/blob/v1.4.0/packages/apollo-server-module-graphiql/src/resolveGraphiQLString.ts - // renderGraphiQL /* * Mostly taken straight from express-graphql, so see their licence @@ -43,7 +40,7 @@ function safeSerialize(data) { return data ? JSON.stringify(data).replace(/\//g, '\\/') : null; } -export function renderGraphiQL(data){ +export function renderGraphiQL(data) { const endpointURL = data.endpointURL; const endpointWs = endpointURL.startsWith('ws://') || endpointURL.startsWith('wss://'); @@ -240,10 +237,7 @@ function isOptionsFunction(arg) { return typeof arg === 'function'; } -async function resolveGraphiQLOptions( - options, - ...args -) { +async function resolveGraphiQLOptions(options, ...args) { if (isOptionsFunction(options)) { try { return await options(...args); @@ -264,10 +258,7 @@ function createGraphiQLParams(query) { }; } -function createGraphiQLData( - params, - options, -) { +function createGraphiQLData(params, options) { return { endpointURL: options.endpointURL, subscriptionsEndpoint: options.subscriptionsEndpoint, @@ -282,11 +273,7 @@ function createGraphiQLData( }; } -async function resolveGraphiQLString( - query, - options, - ...args -) { +async function resolveGraphiQLString(query, options, ...args) { const graphiqlParams = createGraphiQLParams(query); const graphiqlOptions = await resolveGraphiQLOptions(options, ...args); const graphiqlData = createGraphiQLData(graphiqlParams, graphiqlOptions); @@ -307,12 +294,8 @@ async function resolveGraphiQLString( * - (optional) result: the result of the query to pre-fill in the GraphiQL UI */ -export const graphiqlMiddleware = (options) => { - const graphiqlHandler = ( - req, - res, - next, - ) => { +export const graphiqlMiddleware = options => { + const graphiqlHandler = (req, res, next) => { const query = req.url && url.parse(req.url, true).query; resolveGraphiQLString(query, options, req).then( graphiqlString => { @@ -320,8 +303,8 @@ export const graphiqlMiddleware = (options) => { res.write(graphiqlString); res.end(); }, - error => next(error), + error => next(error) ); }; return graphiqlHandler; -}; \ No newline at end of file +}; diff --git a/packages/vulcan-lib/lib/server/apollo-server/voyager.js b/packages/vulcan-lib/lib/server/apollo-server/voyager.js index 576cce408..881a1d0b9 100644 --- a/packages/vulcan-lib/lib/server/apollo-server/voyager.js +++ b/packages/vulcan-lib/lib/server/apollo-server/voyager.js @@ -1,4 +1,4 @@ export const getVoyagerConfig = currentConfig => ({ - endpointUrl: currentConfig.voyagerPath, + endpointUrl: currentConfig.path, }); export default getVoyagerConfig;