From 51b5ea7b3f4e8c333f3f894ce20054542e0c4f32 Mon Sep 17 00:00:00 2001 From: Pierre Burgy Date: Sun, 17 Feb 2019 14:35:41 +0100 Subject: [PATCH] Fix findOne query for GraphQL --- packages/strapi-plugin-graphql/services/Query.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/Query.js b/packages/strapi-plugin-graphql/services/Query.js index e4804b7784..21a3e93471 100644 --- a/packages/strapi-plugin-graphql/services/Query.js +++ b/packages/strapi-plugin-graphql/services/Query.js @@ -19,10 +19,10 @@ module.exports = { * @return Object */ - convertToParams: params => { + convertToParams: (params, primaryKey) => { return Object.keys(params).reduce((acc, current) => { return Object.assign(acc, { - [`_${current}`]: params[current], + [`${primaryKey === current ? '' : '_'}${current}`]: params[current], }); }, {}); }, @@ -260,7 +260,7 @@ module.exports = { Object.defineProperties(ctx, { query: { value: { - ...this.convertToParams(_.omit(_options, 'where')), + ...this.convertToParams(_.omit(_options, 'where'), model.primaryKey), ..._options.where, // Avoid population. _populate: model.associations.filter(a => !a.dominant && _.isEmpty(a.model)).map(a => a.alias), @@ -269,7 +269,7 @@ module.exports = { configurable: true }, params: { - value: this.convertToParams(this.amountLimiting(_options)), + value: this.convertToParams(this.amountLimiting(_options), model.primaryKey), writable: true, configurable: true }