From bd840d709e867f60a5276a92f194782ac33fd251 Mon Sep 17 00:00:00 2001 From: Nick Verwymeren Date: Tue, 28 Aug 2018 14:30:05 -0400 Subject: [PATCH 1/3] Change comparison operator for array of id's When there's an array of ID's present it looks like the Content Manager uses the '=' comparison which ends up returning an empty set. I think maybe the issue lies with the Content Manager plugin in that it should be using a 'IN' comparison if it detects an array. This is a workaround that seems to fix the issue. Although I'll be honest, I don't have enough knowledge of this plugin or the system to know if this will work for all edge cases. --- packages/strapi-plugin-graphql/services/GraphQL.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index eb911fae2b..33bfe38ce9 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -675,6 +675,14 @@ module.exports = { }).where; } } + + if (queryOpts.hasOwnProperty('query') && + queryOpts.query.hasOwnProperty('id') && + queryOpts.query.id.hasOwnProperty('value') && + Array.isArray(queryOpts.query.id.value) + ){ + queryOpts.query.id.symbol = 'IN'; + } const value = await (association.model ? resolvers.fetch(params, association.plugin, []): From 513558c8e9e2573afc2bcfd2ab60a0c5cd46a9d0 Mon Sep 17 00:00:00 2001 From: Nick Verwymeren Date: Thu, 25 Oct 2018 13:48:28 -0500 Subject: [PATCH 2/3] Update GraphQL.js --- packages/strapi-plugin-graphql/services/GraphQL.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index 33bfe38ce9..ef1d39e607 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -649,7 +649,6 @@ module.exports = { switch (association.nature) { case 'manyToMany': { - if (association.dominant) { const arrayOfIds = (obj[association.alias] || []).map(related => { return related[ref.primaryKey] || related; }); @@ -661,7 +660,6 @@ module.exports = { [ref.primaryKey]: arrayOfIds, ...where.where }).where; - } break; // falls through } From 08ababab426b5a11eb2a13c8a29729d9f951c17a Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Sat, 10 Nov 2018 11:37:02 +0100 Subject: [PATCH 3/3] Fix lint --- packages/strapi-plugin-graphql/services/Resolvers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/strapi-plugin-graphql/services/Resolvers.js b/packages/strapi-plugin-graphql/services/Resolvers.js index 9111b2c56d..8c117334f6 100644 --- a/packages/strapi-plugin-graphql/services/Resolvers.js +++ b/packages/strapi-plugin-graphql/services/Resolvers.js @@ -398,7 +398,7 @@ module.exports = { queryOpts.skip = convertedParams.start; switch (association.nature) { - case 'manyToMany': + case 'manyToMany': { const arrayOfIds = (obj[association.alias] || []).map( related => { return related[ref.primaryKey] || related; @@ -414,6 +414,7 @@ module.exports = { }).where; break; // falls through + } default: // Where. queryOpts.query = strapi.utils.models.convertParams(name, {