ra-data-hasura-graphql icon indicating copy to clipboard operation
ra-data-hasura-graphql copied to clipboard

Is it possible to filter on nested attributes?

Open avimoondra opened this issue 4 years ago • 7 comments

Similar to sort, but for filters: https://github.com/Steams/ra-data-hasura-graphql#sorting

avimoondra avatar Jul 24 '20 01:07 avimoondra

Any luck with this?

narayanpromax avatar Sep 21 '20 20:09 narayanpromax

0.1.12 has undocumented hasura-raw-query-feature, which allows injecting "raw" hasura filters and therefore filtering using relations (nested attributes):

   filter: {
     MyRelation: { 
       format: "hasura-raw-query",
       value: {
         relation_field: { _eq: my_value },
       },
     },
   }

datakurre avatar Oct 05 '20 07:10 datakurre

What is MyRelation in here?

Can you equivalent of below?

query MyQuery {
  onboardings(order_by: {sort_order: asc}, where: {language: {code: {_eq: "en"}}}) {
    description
    image
  }
}

narayanpromax avatar Oct 05 '20 08:10 narayanpromax

I'd guess

   filter: {
     language: { 
       format: "hasura-raw-query",
       value: {
         code: { _eq: "en" },
       },
     },
   }

datakurre avatar Oct 05 '20 08:10 datakurre

Ok. Will it work for useQuery?

 const { data, loading, error } = useQuery({ 
        type: 'getList',
        resource: 'onboardings',
        payload: { filter: {format: "hasura-raw-query" , id: { '_eq' : 26}}}
});

narayanpromax avatar Oct 05 '20 19:10 narayanpromax

It seems like it would be relatively straight-forward to add a simple syntax to the filter strings e.g. passing "author.name@_ilike" as a source and then create the right nested filter structure in the generated variables. In the case of the example above: { where: { author: { name: _eq: some_value}}}

If this doesn't get implemented into the core you could create a custom variable generator that overwrite the standard filters.

tylermorganme avatar Mar 25 '21 08:03 tylermorganme

@tylermorganme ~ this repository is now depreciated. The Hasura organization has adopted and now maintains this library. Going forward, you can use this: https://github.com/hasura/ra-data-hasura

cpursley avatar Mar 29 '21 17:03 cpursley