From e0834065f738f9919d57f99b5613f03d7e2de23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Georget?= Date: Tue, 22 Mar 2016 15:59:03 +0100 Subject: [PATCH] Improve GraphQL errors when there are no collections --- .../strapi/lib/configuration/hooks/graphql/index.js | 10 ++++++++-- .../strapi/lib/configuration/hooks/graphql/schema.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/strapi/lib/configuration/hooks/graphql/index.js b/packages/strapi/lib/configuration/hooks/graphql/index.js index 9e9709ee5d..f33e76059b 100644 --- a/packages/strapi/lib/configuration/hooks/graphql/index.js +++ b/packages/strapi/lib/configuration/hooks/graphql/index.js @@ -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) => ({ diff --git a/packages/strapi/lib/configuration/hooks/graphql/schema.js b/packages/strapi/lib/configuration/hooks/graphql/schema.js index 7d049562d9..d61a380314 100644 --- a/packages/strapi/lib/configuration/hooks/graphql/schema.js +++ b/packages/strapi/lib/configuration/hooks/graphql/schema.js @@ -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();