setup engine

This commit is contained in:
Eric Burel 2018-10-03 14:19:50 +02:00
parent 29bcf74ed3
commit ad022bce9b
3 changed files with 16 additions and 70 deletions

View file

@ -32,7 +32,7 @@ import cookiesMiddleware from 'universal-cookie-express';
export let executableSchema; export let executableSchema;
import './settings'; import './settings';
import { engine, engineApiKey } from './engine'; import { engineConfig } from './engine';
import { defaultConfig, defaultOptions } from './defaults'; import { defaultConfig, defaultOptions } from './defaults';
import computeContext from './computeContext'; import computeContext from './computeContext';
@ -47,13 +47,12 @@ const createApolloServer = ({ options: givenOptions = {}, config: givenConfig =
const options = { ...defaultOptions, ...givenOptions }; const options = { ...defaultOptions, ...givenOptions };
// given options contains the schema // given options contains the schema
const apolloServer = new ApolloServer({ const apolloServer = new ApolloServer({
engine: engineConfig,
...options, ...options,
// this replace the previous syntax graphqlExpress(async req => { ... }) // this replace the previous syntax graphqlExpress(async req => { ... })
// this function takes the context, which contains the current request, // this function takes the context, which contains the current request,
// and setup the options accordingly ({req}) => { ...; return options } // and setup the options accordingly ({req}) => { ...; return options }
context: computeContext(options.context, contextFromReq) context: computeContext(options.context, contextFromReq)
// TODO: we could split options that actually need the request/result and others
// (eg schema, formatError, etc.)
}); });
// default function does nothing // default function does nothing
@ -61,10 +60,6 @@ const createApolloServer = ({ options: givenOptions = {}, config: givenConfig =
config.configServer({ apolloServer }); config.configServer({ apolloServer });
// setup middleware // setup middleware
// TODO: might not be needed anymore
//if (engineApiKey) {
// app.use(engine.expressMiddleware());
//}
//// TODO: use a graphqlish solution? //// TODO: use a graphqlish solution?
//app.use(cookiesMiddleware()); //app.use(cookiesMiddleware());
//// TODO: is it needed? //// TODO: is it needed?
@ -88,6 +83,7 @@ const createApolloServer = ({ options: givenOptions = {}, config: givenConfig =
res.end(); res.end();
} }
}); });
// TODO: previous implementation with a patch. Is it still needed?
//webAppConnectHandlersUse(Meteor.bindEnvironment(apolloServer), { //webAppConnectHandlersUse(Meteor.bindEnvironment(apolloServer), {
// name: 'graphQLServerMiddleware_bindEnvironment', // name: 'graphQLServerMiddleware_bindEnvironment',
// order: 30 // order: 30

View file

@ -1,58 +1,8 @@
import { Engine } from 'apollo-engine';
import { getSetting } from '../../modules/settings.js'; import { getSetting } from '../../modules/settings.js';
// see https://github.com/apollographql/apollo-cache-control // see https://github.com/apollographql/apollo-cache-control
const engineApiKey = getSetting('apolloEngine.apiKey'); export const engineApiKey = process.env.ENGINE_API_KEY || getSetting('apolloEngine.apiKey');
const engineLogLevel = getSetting('apolloEngine.logLevel', 'INFO'); // options now available:
const engineConfig = { // @see https://www.apollographql.com/docs/apollo-server/api/apollo-server.html#EngineReportingOptions
apiKey: engineApiKey, export const engineConfig = {
// "origins": [ apiKey: engineApiKey
// {
// "http": {
// "url": "http://localhost:3000/graphql"
// }
// }
// ],
stores: [
{
name: 'vulcanCache',
inMemory: {
cacheSize: 20000000
}
}
],
// "sessionAuth": {
// "store": "embeddedCache",
// "header": "Authorization"
// },
// "frontends": [
// {
// "host": "127.0.0.1",
// "port": 3000,
// "endpoint": "/graphql",
// "extensions": {
// "strip": []
// }
// }
// ],
queryCache: {
publicFullQueryStore: 'vulcanCache',
privateFullQueryStore: 'vulcanCache'
},
// "reporting": {
// "endpointUrl": "https://engine-report.apollographql.com",
// "debugReports": true
// },
logging: {
level: engineLogLevel
}
};
let engine;
if (engineApiKey) {
engine = new Engine({ engineConfig });
engine.start();
}
export default {
engine,
engineApiKey
}; };

View file

@ -1,9 +1,9 @@
import { registerSetting } from '../../modules/settings.js'; import { registerSetting } from '../../modules/settings.js';
// TODO: is this still necessary?
registerSetting('apolloEngine.logLevel', 'INFO', 'Log level (one of INFO, DEBUG, WARN, ERROR'); //registerSetting('apolloEngine.logLevel', 'INFO', 'Log level (one of INFO, DEBUG, WARN, ERROR');
registerSetting( //registerSetting(
'apolloTracing', // 'apolloTracing',
Meteor.isDevelopment, // Meteor.isDevelopment,
'Tracing by Apollo. Default is true on development and false on prod', // 'Tracing by Apollo. Default is true on development and false on prod',
true // true
); //);