mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +00:00
Fix custom mutation returning null and not executing policies (#3735)
Fix custom mutation returning null and not executing policies
This commit is contained in:
parent
a2770d7c7f
commit
f0e8df63c5
@ -195,27 +195,49 @@ module.exports = {
|
||||
|
||||
// Resolver can be a function. Be also a native resolver or a controller's action.
|
||||
if (_.isFunction(resolver)) {
|
||||
context.params = Query.convertToParams(
|
||||
options.input.where || {},
|
||||
(plugin ? strapi.plugins[plugin].models[name] : strapi.models[name])
|
||||
.primaryKey
|
||||
);
|
||||
context.request.body = options.input.data || {};
|
||||
const normalizedName = _.toLower(name);
|
||||
|
||||
let primaryKey;
|
||||
|
||||
if (plugin) {
|
||||
primaryKey = strapi.plugins[plugin].models[normalizedName].primaryKey;
|
||||
} else {
|
||||
primaryKey = strapi.models[normalizedName].primaryKey;
|
||||
}
|
||||
|
||||
if (options.input && options.input.where) {
|
||||
context.params = Query.convertToParams(
|
||||
options.input.where || {},
|
||||
primaryKey
|
||||
);
|
||||
} 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);
|
||||
|
||||
if (ctx.body) {
|
||||
return {
|
||||
[pluralize.singular(name)]: ctx.body,
|
||||
};
|
||||
return options.input
|
||||
? {
|
||||
[pluralize.singular(normalizedName)]: ctx.body,
|
||||
}
|
||||
: ctx.body;
|
||||
}
|
||||
|
||||
const body = values && values.toJSON ? values.toJSON() : values;
|
||||
|
||||
return {
|
||||
[pluralize.singular(name)]: body,
|
||||
};
|
||||
return options.input
|
||||
? {
|
||||
[pluralize.singular(normalizedName)]: body,
|
||||
}
|
||||
: body;
|
||||
}
|
||||
|
||||
return resolver.call(null, obj, options, context);
|
||||
|
||||
@ -205,14 +205,19 @@ const schemaBuilder = {
|
||||
: {};
|
||||
|
||||
switch (type) {
|
||||
case 'Mutation':
|
||||
case 'Mutation': {
|
||||
// TODO: Verify this...
|
||||
const [name, action] = acc[type][resolver].split('.');
|
||||
const normalizedName = _.toLower(name);
|
||||
|
||||
acc[type][resolver] = Mutation.composeMutationResolver(
|
||||
strapi.plugins.graphql.config._schema.graphql,
|
||||
plugin,
|
||||
resolver
|
||||
normalizedName,
|
||||
action
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'Query':
|
||||
default:
|
||||
acc[type][resolver] = Query.composeQueryResolver(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user