Start GraphQL server in the router

This commit is contained in:
Aurélien Georget 2016-02-23 19:01:22 +01:00
parent 9a32907282
commit f5a72e1198

View File

@ -105,6 +105,20 @@ module.exports = function (strapi) {
}
});
// Define GraphQL route to GraphQL schema
// or disable the global variable
if (strapi.config.graphql.enabled === true) {
// Wait GraphQL schemas generation
strapi.once('orm:graphql:ready', function () {
strapi.router.get(strapi.config.graphql.route, strapi.middlewares.graphql({
schema: strapi.schemas,
pretty: true
}));
});
} else {
global.graphql = undefined;
}
// Let the router use our routes and allowed methods.
strapi.app.use(strapi.router.routes());
strapi.app.use(strapi.router.allowedMethods());