mirror of
https://github.com/strapi/strapi.git
synced 2025-11-14 17:19:01 +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 */
|
/* eslint-disable no-unused-vars */
|
||||||
|
|
||||||
module.exports = {
|
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.
|
* 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.
|
// 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(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 || {};
|
context.request.body = options.input.data || {};
|
||||||
|
|
||||||
if (isController) {
|
if (isController) {
|
||||||
|
|||||||
@ -23,8 +23,8 @@ module.exports = {
|
|||||||
return Object.keys(params).reduce((acc, current) => {
|
return Object.keys(params).reduce((acc, current) => {
|
||||||
return Object.assign(acc, {
|
return Object.assign(acc, {
|
||||||
[`${
|
[`${
|
||||||
primaryKey === current || "id" === current ? "" : "_"
|
"id" === current ? primaryKey : current
|
||||||
}${current}`]: params[current]
|
}`]: params[current]
|
||||||
});
|
});
|
||||||
}, {});
|
}, {});
|
||||||
},
|
},
|
||||||
@ -228,7 +228,7 @@ module.exports = {
|
|||||||
|
|
||||||
return async (obj, options = {}, { context }) => {
|
return async (obj, options = {}, { context }) => {
|
||||||
const _options = _.cloneDeep(options);
|
const _options = _.cloneDeep(options);
|
||||||
|
|
||||||
// Hack to be able to handle permissions for each query.
|
// Hack to be able to handle permissions for each query.
|
||||||
const ctx = Object.assign(_.clone(context), {
|
const ctx = Object.assign(_.clone(context), {
|
||||||
request: Object.assign(_.clone(context.request), {
|
request: Object.assign(_.clone(context.request), {
|
||||||
|
|||||||
@ -374,7 +374,7 @@ module.exports = {
|
|||||||
// Apply optional arguments to make more precise nested request.
|
// Apply optional arguments to make more precise nested request.
|
||||||
const convertedParams = strapi.utils.models.convertParams(
|
const convertedParams = strapi.utils.models.convertParams(
|
||||||
name,
|
name,
|
||||||
Query.convertToParams(Query.amountLimiting(options)),
|
Query.convertToParams(Query.amountLimiting(options), ref.primaryKey),
|
||||||
);
|
);
|
||||||
|
|
||||||
const where = strapi.utils.models.convertParams(
|
const where = strapi.utils.models.convertParams(
|
||||||
@ -395,7 +395,7 @@ module.exports = {
|
|||||||
return related[ref.primaryKey] || related;
|
return related[ref.primaryKey] || related;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Object.assign(queryOpts, {
|
Object.assign(queryOpts, {
|
||||||
...queryOpts,
|
...queryOpts,
|
||||||
query: {
|
query: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user