Merge pull request #2983 from strapi/fix/mutation-query-graphql

Hot fix primary key detection mutation/query GraphQL
This commit is contained in:
Jim LAURIE 2019-03-15 18:00:52 +01:00 committed by GitHub
commit 4964d80a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 20 deletions

View File

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

View File

@ -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), {

View File

@ -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: {