From 56ffc261ba88e93bf63ecf501333775a54a4839c Mon Sep 17 00:00:00 2001 From: Matt Black Date: Thu, 3 May 2018 11:33:51 -0400 Subject: [PATCH 1/2] added Config option for a Loader instance --- server/config.js | 1 + server/initialize.js | 6 +++++- server/schema.js | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/config.js b/server/config.js index ca4f304..cf4ef9a 100644 --- a/server/config.js +++ b/server/config.js @@ -14,6 +14,7 @@ let Config = { GRAPHQL_SCHEMA_DIRECTIVES: {}, EXPRESS_MIDDLEWARES: [], MOCKING: null, + LOADER: null, }; export default Config; diff --git a/server/initialize.js b/server/initialize.js index 2aa63a0..2a5b85c 100644 --- a/server/initialize.js +++ b/server/initialize.js @@ -15,7 +15,11 @@ export default function initialize(config = {}) { Object.freeze(Config); - const schema = getExecutableSchema(); + const schema = getExecutableSchema( + Config.LOADER && Config.LOADER.getSchema + ? Config.LOADER.getSchema.bind(Config.LOADER) + : undefined + ); if (Config.MOCKING) { addMockFunctionsToSchema({ diff --git a/server/schema.js b/server/schema.js index 470a7ee..c717197 100644 --- a/server/schema.js +++ b/server/schema.js @@ -1,12 +1,12 @@ import { makeExecutableSchema } from 'graphql-tools'; -import { load, getSchema } from 'graphql-load'; +import { load, getSchema as defaultGetSchema } from 'graphql-load'; import Config from './config'; import directives from './directives'; const EMPTY_QUERY_ERROR = 'Error: Specified query type "Query" not found in document.'; -export function getExecutableSchema() { +export function getExecutableSchema(getSchema = defaultGetSchema) { try { const { typeDefs, resolvers } = getSchema(); schema = makeExecutableSchema({ From 93532a7af5618119415a3b201d16530b84efd7d1 Mon Sep 17 00:00:00 2001 From: Matt Black Date: Thu, 3 May 2018 11:36:02 -0400 Subject: [PATCH 2/2] Initial proposition of replacing the the graphql server at runtime --- server/core/main-server.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/core/main-server.js b/server/core/main-server.js index a82f973..40bfd22 100644 --- a/server/core/main-server.js +++ b/server/core/main-server.js @@ -125,6 +125,8 @@ export const createApolloServer = (customOptions = {}, customConfig = {}) => { }) ); } + // this removes all handlers + WebApp.connectHandlers.stack = []; // this binds the specified paths to the Express server running Apollo + GraphiQL WebApp.connectHandlers.use(graphQLServer);