From c37ba583bad5c1b4989a8013aac6a3115109e28f Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 10 Jun 2019 20:37:13 +0200 Subject: [PATCH 1/2] Load extensions --- .../strapi-plugin-graphql/hooks/graphql/index.js | 13 ++++++++++--- .../hooks/graphql/load-config.js | 9 +++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/strapi-plugin-graphql/hooks/graphql/index.js b/packages/strapi-plugin-graphql/hooks/graphql/index.js index 987302669b..52476d49c9 100644 --- a/packages/strapi-plugin-graphql/hooks/graphql/index.js +++ b/packages/strapi-plugin-graphql/hooks/graphql/index.js @@ -23,8 +23,11 @@ module.exports = strapi => { strapi.config.hook.load.after.push('graphql'); // Load core utils. - const configs = await loadConfigs({ appPath, installedPlugins }); - _.merge(strapi, configs); + const { api, plugins, extensions } = await loadConfigs({ + appPath, + installedPlugins, + }); + _.merge(strapi, { api, plugins }); /* * Create a merge of all the GraphQL configuration. @@ -37,11 +40,15 @@ module.exports = strapi => { _.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 _.set( strapi, ['plugins', 'graphql', 'config', '_schema', 'graphql'], - mergeSchemas([...apisSchemas, ...pluginsSchemas]) + mergeSchemas([...apisSchemas, ...pluginsSchemas, ...extensionsSchemas]) ); }, diff --git a/packages/strapi-plugin-graphql/hooks/graphql/load-config.js b/packages/strapi-plugin-graphql/hooks/graphql/load-config.js index e66da72769..691f94ebc1 100644 --- a/packages/strapi-plugin-graphql/hooks/graphql/load-config.js +++ b/packages/strapi-plugin-graphql/hooks/graphql/load-config.js @@ -16,21 +16,26 @@ const loadPluginsGraphqlConfig = async installedPlugins => { ); _.set(root, ['plugins', pluginName], result); } + return root; }; const loadLocalPluginsGraphqlConfig = async appPath => loadUtils.loadFiles(appPath, 'plugins/**/config/*.graphql?(.js)'); +const loadExtensions = async appPath => + loadUtils.loadFiles(appPath, 'extensions/**/config/*.graphql?(.js)'); + /** * Loads the graphql config files */ module.exports = async ({ appPath, installedPlugins }) => { - const [apis, plugins, localPlugins] = await Promise.all([ + const [apis, plugins, localPlugins, extensions] = await Promise.all([ loadApisGraphqlConfig(appPath), loadPluginsGraphqlConfig(installedPlugins), loadLocalPluginsGraphqlConfig(appPath), + loadExtensions(appPath), ]); - return _.merge({}, apis, plugins, localPlugins); + return _.merge({}, apis, plugins, extensions, localPlugins); }; From 50fc3a127f5f2bbf580fb7cdef6277df5ef0d43a Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Wed, 12 Jun 2019 14:34:49 +0200 Subject: [PATCH 2/2] Add example in getstarted --- .../getstarted/exports/graphql/schema.graphql | 1 + .../users-permissions/config/schema.graphql.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 examples/getstarted/extensions/users-permissions/config/schema.graphql.js diff --git a/examples/getstarted/exports/graphql/schema.graphql b/examples/getstarted/exports/graphql/schema.graphql index 935c43a9a7..f6791c920b 100644 --- a/examples/getstarted/exports/graphql/schema.graphql +++ b/examples/getstarted/exports/graphql/schema.graphql @@ -216,6 +216,7 @@ type Query { test(id: ID!): MypluginTest tests(sort: String, limit: Int, start: Int, where: JSON): [MypluginTest] me: UsersPermissionsMe + userCustomRoute: String } input RoleInput { diff --git a/examples/getstarted/extensions/users-permissions/config/schema.graphql.js b/examples/getstarted/extensions/users-permissions/config/schema.graphql.js new file mode 100644 index 0000000000..24d93760bb --- /dev/null +++ b/examples/getstarted/extensions/users-permissions/config/schema.graphql.js @@ -0,0 +1,15 @@ +module.exports = { + query: ` + userCustomRoute: String + `, + resolver: { + Query: { + userCustomRoute: { + resolver: { + plugin: 'users-permissions', + handler: 'UsersPermissions.customRoute', + }, + }, + }, + }, +};