refine
refine copied to clipboard
[FEAT] Improve DataProvider for Hasura
Is your feature request related to a problem? Please describe.
Modify code for generating the sort parameters of the GraphQL query that gets sent off to a Hasura GraphQL endpoint (might want to patch these changes to the other GraphQL data providers). This would allow for multi-sort
Describe alternatives you've considered
No response
Additional context
This is the current implementation of generating the sort parameter, https://github.com/refinedev/refine/blob/master/packages/hasura/src/utils/generateSorting.ts#L10C1-L25.
Which should generate an array of ${operation}_order_by
, but currently generates a record of ${operation}_order_by
,
https://github.com/refinedev/refine/blob/master/packages/hasura/src/dataProvider/index.ts#L112-L116.
The generation of the sort parameter should be recursive like https://github.com/refinedev/refine/blob/master/packages/hasura/src/utils/generateFilters.ts#L111-L122.
So an input like
[
{
field: 'patient_status.title',
order: 'asc'
},
{
field: 'insurance_status.title',
order: 'asc'
},
{
field: 'patient.name_and_dob',
order: 'asc'
},
{
field: 'rx_received_date',
order: 'desc'
},
]
Would produce an output like,
[
{
"patient_status": {
"title": "asc"
}
},
{
"insurance_status": {
"title": "asc"
}
},
{
"patient": {
"name_and_dob": "asc"
}
},
{
"rx_received_date": "desc"
}
]
an example implementation would be something like this
const generateNestedSorting = (sorter:any) => {
if (!sorter) {
return undefined;
}
const { field, order } = sorter;
const fieldsArray = field.split(".");
return {
...(setWith({}, fieldsArray, order, Object))
};
};
const generateSorting = (sorters:any[] | undefined) => {
if (!sorters){
return undefined
}
return sorters.map(generateNestedSorting)
}
Describe the thing to improve
Sorts of GraphQL provider
Hello @hAhl2 thanks for the issue! Would you like to create a PR for this?
Hello @hAhl2 thanks for the issue! Would you like to create a PR for this?
I'll attempt one, but if that is not so in a couple of days, this issue could be handled by someone else.
Alright, our next release cycle is in January, I've assigned this issue to the January milestone. We are open to contributions for this one.
Hello! I am new to open source. May I add a PR for this issue directly or do I need to claim for the issue first?
Fixed the issue, needed review. @BatuhanW