Merge branch 'master' into fix/graphql-many-many-nested

This commit is contained in:
Alexandre BODIN 2019-10-22 10:09:00 +02:00 committed by GitHub
commit abe6b17392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 26 deletions

View File

@ -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:
<!-- ```
/plugin

View File

@ -1,6 +1,6 @@
'use strict';
const validateGroupInput = require('./validation/group');
const _ = require('lodash');
/**
* Groups controller
*/
@ -82,6 +82,15 @@ module.exports = {
return ctx.send({ error: 'group.notFound' }, 404);
}
// convert zero length string on default attributes to undefined
if (_.has(body, 'attributes')) {
Object.keys(body.attributes).forEach(attribute => {
if (body.attributes[attribute].default === '') {
body.attributes[attribute].default = undefined;
}
});
}
try {
await validateGroupInput(body);
} catch (error) {

View File

@ -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), {
@ -203,18 +216,6 @@ 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);

View File

@ -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);