From cbf877074d8f8a96484ce1b7ec96980bef6e64af Mon Sep 17 00:00:00 2001 From: aissa-bouguern <6617326+aissa-bouguern@users.noreply.github.com> Date: Mon, 29 Oct 2018 22:36:39 +0000 Subject: [PATCH] GraphQL many-to-many relations symmetry Querying content types that share many-to-many relations do not return expected results. Let's say we have a product content type and a category centent type. those two models share many-to-many relation, and when we are querying categories we have the expected result, Ex : Query : { categories { Name products { Name } } } Result : { "data": { "categories": [ { "Name": "Category 1", "products": [ { "Name": "Product 1" } ] }, { "Name": "Category 2", "products": [ { "Name": "Product 1" } ] } ] } } But when we're querying products, the categories array is empty!! Query: { products { Name categories { Name } } } Result: { "data": { "products": [ { "Name": "Product 1", "categories": [ ] } ] } } categories should not be empty, it should be something like that : ... "categories": [ { "Name": "Category 1" }, { "Name": "Category 2" } ] .... I hope that was clear. --- packages/strapi-plugin-graphql/services/Resolvers.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/Resolvers.js b/packages/strapi-plugin-graphql/services/Resolvers.js index 45328cc731..7ff4d885ce 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': if (association.dominant) { const arrayOfIds = (obj[association.alias] || []).map( related => { @@ -413,8 +413,7 @@ module.exports = { [ref.primaryKey]: arrayOfIds, ...where.where, }).where; - } - break; + break; // falls through } default: