mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Merge pull request #2983 from strapi/fix/mutation-query-graphql
Hot fix primary key detection mutation/query GraphQL
This commit is contained in:
commit
4964d80a65
@ -13,20 +13,6 @@ const Query = require('./Query.js');
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Convert parameters to valid filters parameters.
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
|
||||
convertToParams: params => {
|
||||
return Object.keys(params).reduce((acc, current) => {
|
||||
return Object.assign(acc, {
|
||||
[`_${current}`]: params[current],
|
||||
});
|
||||
}, {});
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute policies before the specified resolver.
|
||||
*
|
||||
@ -206,7 +192,7 @@ 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 || {});
|
||||
context.params = Query.convertToParams(options.input.where || {}, (plugin ? strapi.plugins[plugin].models[name] : strapi.models[name]).primaryKey);
|
||||
context.request.body = options.input.data || {};
|
||||
|
||||
if (isController) {
|
||||
|
||||
@ -23,8 +23,8 @@ module.exports = {
|
||||
return Object.keys(params).reduce((acc, current) => {
|
||||
return Object.assign(acc, {
|
||||
[`${
|
||||
primaryKey === current || "id" === current ? "" : "_"
|
||||
}${current}`]: params[current]
|
||||
"id" === current ? primaryKey : current
|
||||
}`]: params[current]
|
||||
});
|
||||
}, {});
|
||||
},
|
||||
@ -228,7 +228,7 @@ module.exports = {
|
||||
|
||||
return async (obj, options = {}, { context }) => {
|
||||
const _options = _.cloneDeep(options);
|
||||
|
||||
|
||||
// Hack to be able to handle permissions for each query.
|
||||
const ctx = Object.assign(_.clone(context), {
|
||||
request: Object.assign(_.clone(context.request), {
|
||||
|
||||
@ -374,7 +374,7 @@ module.exports = {
|
||||
// Apply optional arguments to make more precise nested request.
|
||||
const convertedParams = strapi.utils.models.convertParams(
|
||||
name,
|
||||
Query.convertToParams(Query.amountLimiting(options)),
|
||||
Query.convertToParams(Query.amountLimiting(options), ref.primaryKey),
|
||||
);
|
||||
|
||||
const where = strapi.utils.models.convertParams(
|
||||
@ -395,7 +395,7 @@ module.exports = {
|
||||
return related[ref.primaryKey] || related;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Object.assign(queryOpts, {
|
||||
...queryOpts,
|
||||
query: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user