graphile-contrib/postgraphile-plugin-connection-filter

SELECT DISTINCT

PedroD opened this issue · 2 comments

Hello,

I want to be able to perform SELECT DISTINCT queries with dynamic columns using your plug-in, I am searching in your code the places where the query is built in order to achieve this but I am a bit lost.

In the end the result I want to achieve would be something like:

{
  allProductData(filter: {
    productGenderByGenderId: { name: {equalTo: "MEN" } }   // Filter all products targeting MEN
  },
    offset: 0,
    first: 10
) {
    nodes {
      category // Return the Category to which the product belongs
    }
  }
}

So what I want to do in this example is to list all my shop's Categories with products targeting men.

The problem with the query above is that it will return me repeated categories, because many men products will share the same categories... So I was looking to do something like:

{
  allProductData(
   distinctBy: ["category"],   // <---- This would equate to "SELECT DISTINCT category ..."
   filter: {
    productGenderByGenderId: { name: {equalTo: "MEN" } }   // Filter all products targeting MEN
  },
    offset: 0,
    first: 10
) {
    nodes {
      category // Return the Category to which the product belongs
    }
  }
}

And this way I will receive unique categories only.

Is this possible? If so, how?

Thanks!

Hey @PedroD , this plugin only extends the WHERE clause, so it's not capable of supporting that type of query.

However, Benjie made some recent improvements to the pg-aggregates plugin (including integrating this plugin for the filtering aspect) and I think it would support what you're after. Take a look: https://github.com/graphile/pg-aggregates#grouped-aggregates

[semi-automated message] I'm going to close this issue since it's out-of-scope for this plugin, but please feel free to continue the conversation below. 🙂