From aa91ca7a9627ee7abdb86e75ee4d90d03b6b991f Mon Sep 17 00:00:00 2001 From: Don Masakayan Date: Wed, 16 Oct 2019 22:23:17 +0800 Subject: [PATCH 1/5] Made ctx.params and ctx.query available to policies executed via graphql requests --- .../services/Mutation.js | 26 +++++++++---------- .../strapi-plugin-graphql/services/Query.js | 22 ++++++++-------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/Mutation.js b/packages/strapi-plugin-graphql/services/Mutation.js index 3b1f590cf0..e98d4b4af7 100644 --- a/packages/strapi-plugin-graphql/services/Mutation.js +++ b/packages/strapi-plugin-graphql/services/Mutation.js @@ -183,6 +183,18 @@ module.exports = { }), }); + if (options.input && options.input.where) { + ctx.params = Query.convertToParams(options.input.where || {}); + } else { + ctx.params = {}; + } + + if (options.input && options.input.data) { + ctx.request.body = options.input.data || {}; + } else { + ctx.request.body = options; + } + // Execute policies stack. const policy = await compose(policiesFn)(ctx); @@ -203,20 +215,8 @@ module.exports = { if (_.isFunction(resolver)) { const normalizedName = _.toLower(name); - if (options.input && options.input.where) { - context.params = Query.convertToParams(options.input.where || {}); - } else { - context.params = {}; - } - - if (options.input && options.input.data) { - context.request.body = options.input.data || {}; - } else { - context.request.body = options; - } - if (isController) { - const values = await resolver.call(null, context); + const values = await resolver.call(null, ctx); if (ctx.body) { return options.input diff --git a/packages/strapi-plugin-graphql/services/Query.js b/packages/strapi-plugin-graphql/services/Query.js index 28dff969ff..1283c4aa35 100644 --- a/packages/strapi-plugin-graphql/services/Query.js +++ b/packages/strapi-plugin-graphql/services/Query.js @@ -257,6 +257,17 @@ module.exports = { }), }); + // Note: we've to used the Object.defineProperties to reset the prototype. It seems that the cloning the context + // cause a lost of the Object prototype. + const opts = this.amountLimiting(_options); + + ctx.query = { + ...this.convertToParams(_.omit(opts, 'where')), + ...this.convertToQuery(opts.where), + }; + + ctx.params = this.convertToParams(opts); + // Execute policies stack. const policy = await compose(policiesFn)(ctx); @@ -275,17 +286,6 @@ module.exports = { // Resolver can be a function. Be also a native resolver or a controller's action. if (_.isFunction(resolver)) { - // Note: we've to used the Object.defineProperties to reset the prototype. It seems that the cloning the context - // cause a lost of the Object prototype. - const opts = this.amountLimiting(_options); - - ctx.query = { - ...this.convertToParams(_.omit(opts, 'where')), - ...this.convertToQuery(opts.where), - }; - - ctx.params = this.convertToParams(opts); - if (isController) { const values = await resolver.call(null, ctx, null); From 93319d8c477e78b21eb81117085d6f56b235e5dd Mon Sep 17 00:00:00 2001 From: Don Masakayan Date: Sat, 19 Oct 2019 19:33:06 +0800 Subject: [PATCH 2/5] Context params moved earlier --- .../services/Mutation.js | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/Mutation.js b/packages/strapi-plugin-graphql/services/Mutation.js index e98d4b4af7..ac1af5aee8 100644 --- a/packages/strapi-plugin-graphql/services/Mutation.js +++ b/packages/strapi-plugin-graphql/services/Mutation.js @@ -176,6 +176,19 @@ module.exports = { return async (obj, options, graphqlCtx) => { const { context } = graphqlCtx; + + if (options.input && options.input.where) { + context.params = Query.convertToParams(options.input.where || {}); + } else { + context.params = {}; + } + + if (options.input && options.input.data) { + context.request.body = options.input.data || {}; + } else { + context.request.body = options; + } + // Hack to be able to handle permissions for each query. const ctx = Object.assign(_.clone(context), { request: Object.assign(_.clone(context.request), { @@ -183,18 +196,6 @@ module.exports = { }), }); - if (options.input && options.input.where) { - ctx.params = Query.convertToParams(options.input.where || {}); - } else { - ctx.params = {}; - } - - if (options.input && options.input.data) { - ctx.request.body = options.input.data || {}; - } else { - ctx.request.body = options; - } - // Execute policies stack. const policy = await compose(policiesFn)(ctx); @@ -216,7 +217,7 @@ module.exports = { const normalizedName = _.toLower(name); if (isController) { - const values = await resolver.call(null, ctx); + const values = await resolver.call(null, context); if (ctx.body) { return options.input From 349b21fd6ffc98d7d3c56023f279efae6b56f1f5 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 21 Oct 2019 09:39:56 +0200 Subject: [PATCH 3/5] Check if many-many relation is populated before laoding it --- packages/strapi-plugin-graphql/services/Resolvers.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/Resolvers.js b/packages/strapi-plugin-graphql/services/Resolvers.js index 4ea9b8fbd1..b2e9af2d26 100644 --- a/packages/strapi-plugin-graphql/services/Resolvers.js +++ b/packages/strapi-plugin-graphql/services/Resolvers.js @@ -165,8 +165,9 @@ const buildAssocResolvers = (model, name, { plugin }) => { }; if ( - (association.nature === 'manyToMany' && association.dominant) || - association.nature === 'manyWay' + ((association.nature === 'manyToMany' && association.dominant) || + association.nature === 'manyWay') && + _.has(obj, association.alias) // if populated ) { _.set( queryOpts, From 8066bcd96394a30753966a2674b3361c20e4b689 Mon Sep 17 00:00:00 2001 From: Dan Dascalescu Date: Mon, 21 Oct 2019 03:41:05 -0500 Subject: [PATCH 4/5] Fix grammar --- docs/3.0.0-beta.x/plugin-development/plugin-architecture.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/3.0.0-beta.x/plugin-development/plugin-architecture.md b/docs/3.0.0-beta.x/plugin-development/plugin-architecture.md index 1c3287cdd9..62548b8216 100644 --- a/docs/3.0.0-beta.x/plugin-development/plugin-architecture.md +++ b/docs/3.0.0-beta.x/plugin-development/plugin-architecture.md @@ -1,7 +1,7 @@ # Plugin Folders and Files Architecture -The logic of a plugin is located at its root directory `./plugins/**`. The admin panel related parts of each plugin is contained in the `/admin` folder. -The folders and files structure is the following: +The logic of a plugin is located at its root directory `./plugins/**`. The admin panel related parts of each plugin are contained in the `/admin` folder. +The folders and files structure are the following: