mirror of
https://github.com/strapi/strapi.git
synced 2026-01-04 03:03:38 +00:00
Merge pull request #33 from wistityhq/fix/graphql
Wait GraphQL schemas generation before load koa-graphql middleware
This commit is contained in:
commit
afe1c9ae86
@ -112,10 +112,13 @@ module.exports = function (strapi) {
|
||||
// Define GraphQL route with modified Waterline models to GraphQL schema
|
||||
// or disable the global variable
|
||||
if (strapi.config.graphql.enabled === true) {
|
||||
strapi.router.get(strapi.config.graphql.route, strapi.middlewares.graphql({
|
||||
schema: strapi.schemas,
|
||||
pretty: true
|
||||
}));
|
||||
// Wait GraphQL schemas generation
|
||||
strapi.once('waterline:graphql:ready', function () {
|
||||
strapi.router.get(strapi.config.graphql.route, strapi.middlewares.graphql({
|
||||
schema: strapi.schemas,
|
||||
pretty: true
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
global.graphql = undefined;
|
||||
}
|
||||
|
||||
@ -194,9 +194,13 @@ module.exports = function (strapi) {
|
||||
});
|
||||
|
||||
// Expose the GraphQL schemas at `strapi.schemas`
|
||||
strapi.schemas = WaterlineGraphQL.getGraphQLSchema({
|
||||
WaterlineGraphQL.getGraphQLSchema({
|
||||
collections: strapi.orm.collections,
|
||||
usefulFunctions: true
|
||||
}, function (schemas) {
|
||||
strapi.schemas = schemas;
|
||||
|
||||
strapi.emit('waterline:graphql:ready');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -131,9 +131,19 @@ module.exports = function (strapi) {
|
||||
loadHook('studio', cb);
|
||||
},
|
||||
|
||||
// Load the router hook.
|
||||
router: function loadRouterHook(cb) {
|
||||
if (!hooks.router) {
|
||||
return cb();
|
||||
}
|
||||
prepareHook('router');
|
||||
applyDefaults(hooks.router);
|
||||
loadHook('router', cb);
|
||||
},
|
||||
|
||||
// Prepare all other hooks.
|
||||
prepare: function prepareHooks(cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio'), function (id, cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router'), function (id, cb) {
|
||||
prepareHook(id);
|
||||
process.nextTick(cb);
|
||||
}, cb);
|
||||
@ -141,7 +151,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Apply the default config for all other hooks.
|
||||
defaults: function defaultConfigHooks(cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio'), function (id, cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router'), function (id, cb) {
|
||||
const hook = hooks[id];
|
||||
applyDefaults(hook);
|
||||
process.nextTick(cb);
|
||||
@ -150,7 +160,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Load all other hooks.
|
||||
load: function loadOtherHooks(cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio'), function (id, cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router'), function (id, cb) {
|
||||
loadHook(id, cb);
|
||||
}, cb);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user