hasura / ra-data-hasura

react-admin data provider for Hasura GraphQL Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`distinct_on` support

bell-steven opened this issue · comments

I have been trying to figure out how to get the distinct_on variable working.

I played around with customBuildFields and queries, but I have been coming up short.

There is this answer on StackOverflow, which doesn't work.

Has anyone ever come across this and got it working?

Extend the default buildVariables function

    // buildGetListVariables 
    // L24 
   const { customFilters = [] } = params;
     
    // ...
    /** Setting "distinct_on" to be the `filters` object attribute to be used inside RA
     * and setting to a `distinct_on` variable
     * and removing from the filter object
     */

    const distinctOnField = "distinct_on";
    const { distinct_on = "" } = filterObj;
    filterObj = omit(filterObj, [distinctOnField]);
    
    // ... 
    
    // L150 
     if (params.sort) {
      result["order_by"] = set(
        {},
        params.sort.field,
        params.sort.order.toLowerCase()
      );
    }
    
    // Add the "distinct_on" attribute to the result object
    if (distinct_on) {
      result["distinct_on"] = distinct_on;
    }
  • Use this to pass to your buildHasuraProvider

Here's the implementation - customVariables.js and app.js

Thanks!

Would the maintainers be open to adding this to the library? I would be more than happy to open a PR.

Edit: I have a form with the changes here. Will put in a PR if anyone else seems interested these changes.

@praveenweb: Adding distinct_on support to the library

@bell-steven hey friend, could you please open a PR with your distinct_on changes? Thank you so much!

@arjunyel The repo has changed quite a bit since those changes, will have to try and find the time to rebase.

I'd like to throw in my support for this to be part of the library, as well. It's a pretty valuable addition. Let us know if you find time to include it, please!