fixed new syntax

This commit is contained in:
Eric Burel 2018-10-03 17:06:40 +02:00
parent d3c384f0fe
commit e474414350
3 changed files with 36 additions and 20 deletions

View file

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

View file

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

View file

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