useCustom filters
When I try to use useCustom to get total counts, the filter I define doesn't get applied to the query.
Here is my query for total counts:
8 Replies
Hi @chachi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
useCustom
hook in Refine is used to send custom query requests. It uses the custom
method as the query function from the dataProvider
which is passed to <Refine>
. The useCustom
hook expects the url
and method
properties, which will be passed to the custom
method from the dataProvider
as parameters. When properties are changed, the useCustom
hook will trigger a new request.
In your case, you are trying to apply a filter to the useCustom
hook. The filters
property is part of the config
object and it will be passed to the custom
method from the dataProvider
as a parameter. It can be used to send the filter query parameters of the request.
Here is an example of how to use the filters
property in the useCustom
hook:
In your case, you are trying to filter by business.id
. Make sure that the business.id
field exists in your data and that the value you are trying to filter by is correct. Also, ensure that the custom
method in your dataProvider
is correctly handling the filters
parameter.
If you are still having issues, it might be helpful to check how your dataProvider
is handling the custom
method and how it's processing the filters
parameter. You can refer to the Refine documentation on the custom
method (https://refine.dev/docs/data/data-provider#custom) for more information.
Also, note that useCustom
should not be used when creating, updating, or deleting a resource. It does not invalidate queries and therefore will not update the application state. If you need to customize the mutation request, use the useCustomMutation
hook instead.
Sources:
- useCustom Hook (https://refine.dev/docs/data/hooks/use-custom)
- custom Method (https://refine.dev/docs/data/data-provider#custom)
- useCustom filters (https://refine.dev/docs/data/hooks/use-custom#configfilters)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@95552725294518272> kapa.ai is still learning and improving, please let us know how it did by reacting below
conventional-tanOP•9mo ago
@kapa.ai Where do I apply filters in the custom method?
Let me check the knowledge base for you. One moment! :books:
----------------------
The
filters
parameter in your custom
method is not being used in the current implementation. To apply filters, you need to include them in your GraphQL query or mutation.
The exact way to do this depends on your GraphQL schema and how it handles filtering. Generally, you would include a filter
argument in your GraphQL operation that takes an input type representing your filter criteria.
Here's a simplified example of how you might include filters in a GraphQL query:
In this example, filters
is an array of filter objects, each with a field
, operator
, and value
property. This array is passed as a filter
argument to the GraphQL operation.
Please note that this is a simplified example and might not work in your specific case. The exact implementation depends on your GraphQL schema and how it handles filtering. You might need to transform the filters
array into a format that your GraphQL server can understand.
Also, remember to handle the case where filters
is undefined
, as it is an optional parameter.
Sources:
- useCustom Hook (https://refine.dev/docs/data/hooks/use-custom)
- custom Method (https://refine.dev/docs/data/data-provider#custom)
- useCustom filters (https://refine.dev/docs/data/hooks/use-custom#configfilters)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@95552725294518272> kapa.ai is still learning and improving, please let us know how it did by reacting below
conventional-tanOP•9mo ago
@kapa.ai that doesn't work
Let me check the knowledge base for you. One moment! :books:
----------------------
I'm sorry to hear that the previous suggestion didn't work. The implementation of filters in the
custom
method largely depends on how your GraphQL server handles filtering.
In your custom
method, you're using a builder
to construct your GraphQL queries and mutations. If this builder
supports filters, you would need to pass the filters to it in the appropriate format.
However, without more information about your GraphQL schema, the builder
you're using, and how they handle filters, it's difficult to provide a more specific solution.
I would recommend checking the documentation or source code of the builder
you're using to see how it handles filters. You might also want to consult your GraphQL server's documentation or schema to see how it expects filters to be formatted in queries and mutations.
If you're still having trouble, you might want to consider asking for help in a more specific context, such as a forum or community related to your builder
, GraphQL server, or the refine framework.
Sources:
- useCustom Hook (https://refine.dev/docs/data/hooks/use-custom)
- custom Method (https://refine.dev/docs/data/data-provider#custom)
- useCustom filters (https://refine.dev/docs/data/hooks/use-custom#configfilters)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@95552725294518272> kapa.ai is still learning and improving, please let us know how it did by reacting below