like-gold
like-gold9mo ago

GraphQL order_by precedence

I need to be able to specify the order of my order_by fields sent via the GraphQL client to Hasura. Currently, when I send two fields, the order is ignored. I reached out to Hasura and they say the query needs to be modified. I am sending:
sorters: {
initial: [
{
field: "is_archived",
order: "asc",
},
{
field: "room_tag",
order: "asc",
},
],
},
sorters: {
initial: [
{
field: "is_archived",
order: "asc",
},
{
field: "room_tag",
order: "asc",
},
],
},
which results in the query:
order_by: {is_archived: asc, room_tag: asc}
order_by: {is_archived: asc, room_tag: asc}
but what I need to send is:
order_by: [{is_archived: asc}, {room_tag: asc}]
order_by: [{is_archived: asc}, {room_tag: asc}]
how can I send this via the standard hooks?
4 Replies
kapa.ai
kapa.ai9mo ago
Hi @geoffatsource. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, the sorters prop in refine's hooks like useTable, useSelect, and useCustom allows you to specify the order of fields. However, the format used is an array of objects, each containing a field and order property, like so:
sorters: [
{
field: "title",
order: "asc",
},
]
sorters: [
{
field: "title",
order: "asc",
},
]
This is then passed to the dataProvider method and used to send sort query parameters to the API. However, the extracts do not provide information on how to modify this format to match the specific format you need for Hasura:
order_by: [{is_archived: asc}, {room_tag: asc}]
order_by: [{is_archived: asc}, {room_tag: asc}]
It seems that you might need to customize the dataProvider to transform the sorters array into the format required by Hasura. Unfortunately, the provided extracts do not contain specific information on how to achieve this. For more detailed guidance, you might want to refer to the refine documentation (https://refine.dev/docs) or seek advice from the refine community. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@1014305963219615754> kapa.ai is still learning and improving, please let us know how it did by reacting below
dependent-tan
dependent-tan9mo ago
Hello @geoffatsource it seems we have an issue on mapping filter parameters to hasura queries correctly, quick solution would be to swizzle the hasura data provider, and modify it: https://refine.dev/docs/tutorial/understanding-dataprovider/swizzle/ You can also create an issue on GitHub
like-gold
like-gold9mo ago
Thanks! Yes, we've already swizzled so we'll make the changes locally.