fair-rose
fair-rose3mo ago

Filter nested fields

I use hasura dataprovider, and i wonder how to use nested filter in order to apply filter on nested field My goal is to make the following graphql query (specially the user_activity_aggregate) query event { event { user_activity_aggregate(where: { type: {_in: ["participate", "interested"]}}) { aggregate { count } } } }
8 Replies
kapa.ai
kapa.ai3mo ago
Hi @Nicolas Bourdin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To apply a nested filter using the Hasura data provider in Refine, you can use the dot notation for nested objects. This feature was discussed and implemented as per the Github issue #2320 (https://github.com/refinedev/refine/issues/2320). Here is an example of how you can use it:
{
field: "category.type",
operator: "eq",
value: "value"
}
{
field: "category.type",
operator: "eq",
value: "value"
}
In your case, you can use it like this:
{
field: "user_activity_aggregate.type",
operator: "in",
value: ["participate", "interested"]
}
{
field: "user_activity_aggregate.type",
operator: "in",
value: ["participate", "interested"]
}
This will allow you to filter via nested objects in your Hasura data provider. Please note that the actual implementation might vary based on your specific use case and data structure. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
fair-rose
fair-rose3mo ago
@kapa.ai I didn't explain my need very well I need to fetch nested field, and apply filter on them and not filtering my whole data query with nested field filter
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I see, you want to fetch nested fields and apply filters on them. Unfortunately, based on the information provided in the extracts, there isn't a direct example of applying filters on nested fields for a Hasura data provider in Refine. However, there's a discussion in Github issue #2127 (https://github.com/refinedev/refine/issues/2127) about introducing a new filter type NestedFilter which could potentially be used for filtering nested fields. Here's an example of how it might look:
{
operator: "nested"
value: {"category": {"type": {"_eq": "howto"}}},
}
{
operator: "nested"
value: {"category": {"type": {"_eq": "howto"}}},
}
Please note that this is a proposed solution and might not be implemented yet. I recommend checking the latest Refine documentation or reaching out to the Refine community for the most accurate information. For more complex queries, you might need to customize your data provider or use a different approach. If you need more assistance, please provide more details about your data structure and the specific filters you want to apply. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@798191015391395866> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-rose3mo ago
@kapa.ai i dont understand how to use the type NestedField in the interface QueryBuilderOptions
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @Nicolas Bourdin, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
fair-rose
fair-rose3mo ago
@kapa.ai I can get nested fields like this, but now I need to add a filter on these nestedfields
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @Nicolas Bourdin, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?