setup voyager

This commit is contained in:
Eric Burel 2018-10-08 17:44:50 +02:00
parent 41da635c74
commit e57f3ecb63
5 changed files with 56 additions and 18 deletions

19
package-lock.json generated
View file

@ -5622,6 +5622,11 @@
"integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=",
"dev": true
},
"lodash.flowright": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/lodash.flowright/-/lodash.flowright-3.5.0.tgz",
"integrity": "sha1-K1//OZcW1+fcVyT+k0n2cGUYTWc="
},
"lodash.foreach": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.foreach/-/lodash.foreach-4.5.0.tgz",
@ -5647,6 +5652,11 @@
"resolved": "https://registry.npmjs.org/lodash.isempty/-/lodash.isempty-4.4.0.tgz",
"integrity": "sha1-b4bL7di+TsmHvpqvM8loTbGzHn4="
},
"lodash.isequal": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
"integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
},
"lodash.isobject": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz",
@ -7506,14 +7516,15 @@
}
},
"react-apollo": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/react-apollo/-/react-apollo-2.2.1.tgz",
"integrity": "sha512-M1UY0o66e2rc4xhAtLKXWRx183yHW/ei1XAno8vWyIUQaEAg3rP5Sgw9nzl3wvpvU1lFjlsY50sbh2Ia1NB5+w==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/react-apollo/-/react-apollo-2.2.4.tgz",
"integrity": "sha512-haS5R30Qvteb65ZLfWomUZQh47VU4ld4Kof3zlqdbLOrYPt3/DdVZC8ZFPZSxd5zPeIJtZqpUfAxD1WHVoMPIA==",
"requires": {
"fbjs": "^1.0.0",
"hoist-non-react-statics": "^3.0.0",
"invariant": "^2.2.2",
"lodash": "^4.17.10",
"lodash.flowright": "^3.5.0",
"lodash.isequal": "^4.5.0",
"prop-types": "^15.6.0"
},
"dependencies": {

View file

@ -62,7 +62,7 @@
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-addons-pure-render-mixin": "^15.4.1",
"react-apollo": "^2.2.1",
"react-apollo": "^2.2.4",
"react-bootstrap": "^0.32.0",
"react-bootstrap-datetimepicker": "0.0.22",
"react-cookie": "^2.1.4",

View file

@ -6,6 +6,7 @@
import { makeExecutableSchema } from 'apollo-server';
// Meteor WebApp use a Connect server, so we need to
// use apollo-server-express integration
//import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import { Meteor } from 'meteor/meteor';
@ -16,7 +17,7 @@ import { WebApp } from 'meteor/webapp';
import { runCallbacks } from '../../modules/callbacks.js';
// import cookiesMiddleware from 'universal-cookie-express';
// import Cookies from 'universal-cookie';
import { express as voyagerMiddleware } from 'graphql-voyager';
import voyagerMiddleware from 'graphql-voyager/middleware/express';
import getVoyagerConfig from './voyager';
export let executableSchema;
@ -71,24 +72,45 @@ const createApolloServer = ({ options: givenOptions = {}, config: givenConfig =
res.end();
}
});
// Add your own middlewares
// For the list of already set middlewares (cookies, compression...), see:
// @see https://github.com/meteor/meteor/blob/master/packages/webapp/webapp_server.js
// TODO: not sure if "config.path" is necessary
//WebApp.connectHandlers.use(config.path, /* your middleware */);
// Voyager is a schema visualizer
WebApp.connectHandlers.use(config.voyagerPath, voyagerMiddleware(getVoyagerConfig(config)));
/* Syntax for adding middlewares to /graphql
Uses Connect + Meteor + Apollo
For the list of already set middlewares (cookies, compression...), see:
@see https://github.com/meteor/meteor/blob/master/packages/webapp/webapp_server.js
It is the easiest pattern and should be used as a default
WebApp.connectHandlers.use(yourMiddleware)
*/
if (Meteor.isDevelopment) {
WebApp.connectHandlers.use(config.voyagerPath, voyagerMiddleware(getVoyagerConfig(config)));
}
/*
* Alternative syntax with Express.
* WebApp will use Connect as a default.
* Use if Express is needed in addition to connect.
*
* Alternative syntax with Express instead of Connect
* Use only if the default server created by WebApp is
* not sufficient
*
* const app = express()
* app.use(...)
*
* WebApp.connectHandlers.use(app)
* or
* WebApp.connectHandlers.use(config.path, app)
*/
/*
* Syntax for setting up an additionnal server
* eg for 3rd party tools
* Uses Apollo but NOT Meteor, it is a totally new server
*
* const app = express()
* app.use(...)
*
* apolloServer.applyMiddleware({
* app,
* path: '/your-app-path'
* })
*/
// TODO: previous implementation used a patch. Is it still needed?

View file

@ -5,7 +5,8 @@ import { formatError } from 'apollo-errors';
export const defaultConfig = {
path: '/graphql',
maxAccountsCacheSizeInMB: 1,
configServer: apolloServer => {}
configServer: apolloServer => {},
voyagerPath: '/voyager'
};
export const defaultOptions = {

View file

@ -0,0 +1,4 @@
export const getVoyagerConfig = currentConfig => ({
endpointUrl: currentConfig.path
});
export default getVoyagerConfig;