Merge branch 'master' into tech/middleware-load

This commit is contained in:
Alexandre BODIN 2019-06-12 18:34:35 +02:00 committed by GitHub
commit 0d480fe11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 5 deletions

View File

@ -216,6 +216,7 @@ type Query {
test(id: ID!): MypluginTest test(id: ID!): MypluginTest
tests(sort: String, limit: Int, start: Int, where: JSON): [MypluginTest] tests(sort: String, limit: Int, start: Int, where: JSON): [MypluginTest]
me: UsersPermissionsMe me: UsersPermissionsMe
userCustomRoute: String
} }
input RoleInput { input RoleInput {

View File

@ -0,0 +1,15 @@
module.exports = {
query: `
userCustomRoute: String
`,
resolver: {
Query: {
userCustomRoute: {
resolver: {
plugin: 'users-permissions',
handler: 'UsersPermissions.customRoute',
},
},
},
},
};

View File

@ -23,8 +23,11 @@ module.exports = strapi => {
strapi.config.hook.load.after.push('graphql'); strapi.config.hook.load.after.push('graphql');
// Load core utils. // Load core utils.
const configs = await loadConfigs({ appPath, installedPlugins }); const { api, plugins, extensions } = await loadConfigs({
_.merge(strapi, configs); appPath,
installedPlugins,
});
_.merge(strapi, { api, plugins });
/* /*
* Create a merge of all the GraphQL configuration. * Create a merge of all the GraphQL configuration.
@ -37,11 +40,15 @@ module.exports = strapi => {
_.get(strapi.plugins[key], 'config.schema.graphql', {}) _.get(strapi.plugins[key], 'config.schema.graphql', {})
); );
const extensionsSchemas = Object.keys(extensions || {}).map(key =>
_.get(extensions[key], 'config.schema.graphql', {})
);
// save the final schema in the plugin's config // save the final schema in the plugin's config
_.set( _.set(
strapi, strapi,
['plugins', 'graphql', 'config', '_schema', 'graphql'], ['plugins', 'graphql', 'config', '_schema', 'graphql'],
mergeSchemas([...apisSchemas, ...pluginsSchemas]) mergeSchemas([...apisSchemas, ...pluginsSchemas, ...extensionsSchemas])
); );
}, },

View File

@ -16,21 +16,26 @@ const loadPluginsGraphqlConfig = async installedPlugins => {
); );
_.set(root, ['plugins', pluginName], result); _.set(root, ['plugins', pluginName], result);
} }
return root; return root;
}; };
const loadLocalPluginsGraphqlConfig = async appPath => const loadLocalPluginsGraphqlConfig = async appPath =>
loadUtils.loadFiles(appPath, 'plugins/**/config/*.graphql?(.js)'); loadUtils.loadFiles(appPath, 'plugins/**/config/*.graphql?(.js)');
const loadExtensions = async appPath =>
loadUtils.loadFiles(appPath, 'extensions/**/config/*.graphql?(.js)');
/** /**
* Loads the graphql config files * Loads the graphql config files
*/ */
module.exports = async ({ appPath, installedPlugins }) => { module.exports = async ({ appPath, installedPlugins }) => {
const [apis, plugins, localPlugins] = await Promise.all([ const [apis, plugins, localPlugins, extensions] = await Promise.all([
loadApisGraphqlConfig(appPath), loadApisGraphqlConfig(appPath),
loadPluginsGraphqlConfig(installedPlugins), loadPluginsGraphqlConfig(installedPlugins),
loadLocalPluginsGraphqlConfig(appPath), loadLocalPluginsGraphqlConfig(appPath),
loadExtensions(appPath),
]); ]);
return _.merge({}, apis, plugins, localPlugins); return _.merge({}, apis, plugins, extensions, localPlugins);
}; };