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/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); 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({