Skip to content

Initial proposal: dynamic schema stitching at runtime. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let Config = {
GRAPHQL_SCHEMA_DIRECTIVES: {},
EXPRESS_MIDDLEWARES: [],
MOCKING: null,
LOADER: null,
};

export default Config;
2 changes: 2 additions & 0 deletions server/core/main-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion server/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions server/schema.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down