mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 19:36:20 +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.
|
// Resolver can be a function. Be also a native resolver or a controller's action.
|
||||||
if (_.isFunction(resolver)) {
|
if (_.isFunction(resolver)) {
|
||||||
context.params = Query.convertToParams(
|
const normalizedName = _.toLower(name);
|
||||||
options.input.where || {},
|
|
||||||
(plugin ? strapi.plugins[plugin].models[name] : strapi.models[name])
|
let primaryKey;
|
||||||
.primaryKey
|
|
||||||
);
|
if (plugin) {
|
||||||
context.request.body = options.input.data || {};
|
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) {
|
if (isController) {
|
||||||
const values = await resolver.call(null, context);
|
const values = await resolver.call(null, context);
|
||||||
|
|
||||||
if (ctx.body) {
|
if (ctx.body) {
|
||||||
return {
|
return options.input
|
||||||
[pluralize.singular(name)]: ctx.body,
|
? {
|
||||||
};
|
[pluralize.singular(normalizedName)]: ctx.body,
|
||||||
|
}
|
||||||
|
: ctx.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = values && values.toJSON ? values.toJSON() : values;
|
const body = values && values.toJSON ? values.toJSON() : values;
|
||||||
|
|
||||||
return {
|
return options.input
|
||||||
[pluralize.singular(name)]: body,
|
? {
|
||||||
};
|
[pluralize.singular(normalizedName)]: body,
|
||||||
|
}
|
||||||
|
: body;
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolver.call(null, obj, options, context);
|
return resolver.call(null, obj, options, context);
|
||||||
|
|||||||
@ -205,14 +205,19 @@ const schemaBuilder = {
|
|||||||
: {};
|
: {};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'Mutation':
|
case 'Mutation': {
|
||||||
// TODO: Verify this...
|
// TODO: Verify this...
|
||||||
|
const [name, action] = acc[type][resolver].split('.');
|
||||||
|
const normalizedName = _.toLower(name);
|
||||||
|
|
||||||
acc[type][resolver] = Mutation.composeMutationResolver(
|
acc[type][resolver] = Mutation.composeMutationResolver(
|
||||||
strapi.plugins.graphql.config._schema.graphql,
|
strapi.plugins.graphql.config._schema.graphql,
|
||||||
plugin,
|
plugin,
|
||||||
resolver
|
normalizedName,
|
||||||
|
action
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'Query':
|
case 'Query':
|
||||||
default:
|
default:
|
||||||
acc[type][resolver] = Query.composeQueryResolver(
|
acc[type][resolver] = Query.composeQueryResolver(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user