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: { defaults: {
prefix: '', 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 // Define GraphQL route to GraphQL schema
// or disable the global variable // or disable the global variable
if (strapi.config.graphql.enabled === true) { if (this.defaults.graphql.enabled === true) {
// Wait GraphQL schemas generation strapi.router.get(this.defaults.graphql.route, strapi.middlewares.graphql({
strapi.once('orm:graphql:ready', function () { schema: strapi.schemas,
strapi.router.get(strapi.config.graphql.route, strapi.middlewares.graphql({ pretty: true
schema: strapi.schemas, }));
pretty: true
}));
});
} else { } else {
global.graphql = undefined; global.graphql = undefined;
} }

View File

@ -8,6 +8,7 @@
"auth", "auth",
"framework", "framework",
"grant", "grant",
"graphql",
"koa", "koa",
"koajs", "koajs",
"lusca", "lusca",
@ -41,6 +42,7 @@
"koa-compose": "~2.3.0", "koa-compose": "~2.3.0",
"koa-cors": "~0.0.16", "koa-cors": "~0.0.16",
"koa-favicon": "~1.2.0", "koa-favicon": "~1.2.0",
"koa-graphql": "^0.4.4",
"koa-gzip": "~0.1.0", "koa-gzip": "~0.1.0",
"koa-i18n": "~1.2.0", "koa-i18n": "~1.2.0",
"koa-ip": "~0.1.0", "koa-ip": "~0.1.0",