Add koa-graphql && fix orm load with GraphQL server

This commit is contained in:
Aurélien Georget 2016-02-24 16:33:42 +01:00
parent f5a72e1198
commit c89bad4949
2 changed files with 15 additions and 9 deletions

View File

@ -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;
}

View File

@ -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",