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 6df673d61..a6d2088a2 100644 --- a/packages/vulcan-lib/lib/server/apollo-server/apollo_server2.js +++ b/packages/vulcan-lib/lib/server/apollo-server/apollo_server2.js @@ -12,6 +12,7 @@ // [ ] Meteor integration? Login? import { makeExecutableSchema } from 'apollo-server'; +// we need the express version to get applyMiddleware and connect to Meteor import { ApolloServer } from 'apollo-server-express'; // now in apollo-server @@ -32,7 +33,7 @@ import './settings'; import { engineConfig } from './engine'; import { defaultConfig, defaultOptions } from './defaults'; import computeContext from './computeContext'; -import getGuiConfig from './gui'; +import getPlaygroundConfig from './playground'; // createApolloServer const createApolloServer = ({ options: givenOptions = {}, config: givenConfig = {}, contextFromReq }) => { @@ -50,7 +51,9 @@ const createApolloServer = ({ options: givenOptions = {}, config: givenConfig = // this replace the previous syntax graphqlExpress(async req => { ... }) // this function takes the context, which contains the current request, // and setup the options accordingly ({req}) => { ...; return options } - context: computeContext(options.context, contextFromReq) + context: computeContext(options.context, contextFromReq), + // graphql playground (replacement to graphiql), available on the app path + playground: getPlaygroundConfig(config) }); // default function does nothing @@ -66,9 +69,7 @@ const createApolloServer = ({ options: givenOptions = {}, config: givenConfig = // connecte apollo with the Meteor app apolloServer.applyMiddleware({ app: WebApp.connectHandlers, - path: config.path, - // graphql playground (replacement to graphiql), available on the app path - gui: getGuiConfig(config) + path: config.path }); // connect the meteor app with Express diff --git a/packages/vulcan-lib/lib/server/apollo-server/gui.js b/packages/vulcan-lib/lib/server/apollo-server/gui.js deleted file mode 100644 index 01034a697..000000000 --- a/packages/vulcan-lib/lib/server/apollo-server/gui.js +++ /dev/null @@ -1,15 +0,0 @@ -/** GraphQL Playground setup, through Apollo "gui" option */ - -export const getGuiConfig = currentConfig => { - // NOTE: this is redundant, Apollo won't show the GUI if NODE_ENV="production" - if (!Meteor.isDevelopment) return undefined; - return { - endpoint: currentConfig.path, - // allow override - ...(currentConfig.gui || {}) - //FIXME: this option does not exist yet... - // @see https://github.com/prisma/graphql-playground/issues/510 - //headers: { ["Authorization"]: 'localStorage[\'Meteor.loginToken\']' }, - }; -}; -export default getGuiConfig; diff --git a/packages/vulcan-lib/lib/server/apollo-server/playground.js b/packages/vulcan-lib/lib/server/apollo-server/playground.js new file mode 100644 index 000000000..4de903eba --- /dev/null +++ b/packages/vulcan-lib/lib/server/apollo-server/playground.js @@ -0,0 +1,30 @@ +/** GraphQL Playground setup, through Apollo "gui" option */ + +export const getPlaygroundConfig = currentConfig => { + // NOTE: this is redundant, Apollo won't show the GUI if NODE_ENV="production" + if (!Meteor.isDevelopment) return undefined; + return { + endpoint: currentConfig.path, + // allow override + //FIXME: this option does not exist yet... + // @see https://github.com/prisma/graphql-playground/issues/510 + //headers: { ["Authorization"]: 'localStorage[\'Meteor.loginToken\']' }, + // to set up headers, we are forced to create a tab, and + // setup headers reuse + tabs: [ + { + endpoint: currentConfig.path, + query: '{ currentUser { _id }}', + // TODO: does not work, we should use a cookie instead? + headers: { ['Authorization']: 'localStorage[\'Meteor.loginToken\']' } + } + ], + settings: { + 'editor.reuseHeaders': true, + // pass cookies? + 'request.credentials': 'same-origin' + }, + ...(currentConfig.gui || {}) + }; +}; +export default getPlaygroundConfig;