diff --git a/lib/configuration/hooks/router/index.js b/lib/configuration/hooks/router/index.js index a46ab380b7..30f48ffc60 100644 --- a/lib/configuration/hooks/router/index.js +++ b/lib/configuration/hooks/router/index.js @@ -27,7 +27,11 @@ module.exports = function (strapi) { defaults: { prefix: '', - routes: {} + routes: {}, + graphql: { + enabled: true, + route: '/graphql' + } }, /** @@ -105,16 +109,16 @@ module.exports = function (strapi) { } }); + // Override default configuration for GraphQL + _.assign(this.defaults.graphql, strapi.config.graphql); + // 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 - })); - }); + if (this.defaults.graphql.enabled === true) { + strapi.router.get(this.defaults.graphql.route, strapi.middlewares.graphql({ + schema: strapi.schemas, + pretty: true + })); } else { global.graphql = undefined; } diff --git a/package.json b/package.json index 420fe12a35..c6c865e120 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "auth", "framework", "grant", + "graphql", "koa", "koajs", "lusca", @@ -41,6 +42,7 @@ "koa-compose": "~2.3.0", "koa-cors": "~0.0.16", "koa-favicon": "~1.2.0", + "koa-graphql": "^0.4.4", "koa-gzip": "~0.1.0", "koa-i18n": "~1.2.0", "koa-ip": "~0.1.0",