Improve GraphQL errors when there are no collections

This commit is contained in:
Aurélien Georget 2016-03-22 15:59:03 +01:00
parent b3f4bc5b96
commit e0834065f7
2 changed files with 10 additions and 4 deletions

View File

@ -42,8 +42,14 @@ module.exports = function (strapi) {
// Define GraphQL route to GraphQL schema
if (this.defaults.graphql.enabled === true) {
require('./schema').getGraphQLSchema(_.assign({
collections: strapi.bookshelf.collections
}, strapi.config.graphql), function (schemas) {
collections: strapi.bookshelf.collections || {}
}, strapi.config.graphql), function (err, schemas) {
if (err) {
strapi.log.warn(err);
console.log();
return cb();
}
// Mount GraphQL server
strapi.app.use(strapi.middlewares.mount(self.defaults.graphql.route, strapi.middlewares.graphql((request, context) => ({

View File

@ -38,7 +38,7 @@ module.exports = {
getGraphQLSchema: function (params, cb) {
if (_.isEmpty(params.collections)) {
return 'Error: Empty object collections';
return cb('GraphQL server has not been started because there are no models', null);
}
// Set defaults properties
@ -53,7 +53,7 @@ module.exports = {
}, _.isNull));
// Return schema
cb(Schema);
cb(null, Schema);
// Build policies
this.buildPolicies();