Steams / ra-data-hasura-graphql

React-admin data provider for Hasura GraphQL endpoints
MIT License
211 stars 33 forks source link

Is it possible to filter on nested attributes? #58

Open avimoondra opened 4 years ago

avimoondra commented 4 years ago

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

narayanpromax commented 3 years ago

Any luck with this?

datakurre commented 3 years ago

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 },
       },
     },
   }
narayanpromax commented 3 years ago

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
  }
}
datakurre commented 3 years ago

I'd guess

   filter: {
     language: { 
       format: "hasura-raw-query",
       value: {
         code: { _eq: "en" },
       },
     },
   }
narayanpromax commented 3 years ago

Ok. Will it work for useQuery?

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

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.

cpursley commented 3 years ago

@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