refine icon indicating copy to clipboard operation
refine copied to clipboard

[FEAT] Improve DataProvider for Hasura

Open hAhl2 opened this issue 1 year ago • 5 comments

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

hAhl2 avatar Dec 05 '23 02:12 hAhl2

Hello @hAhl2 thanks for the issue! Would you like to create a PR for this?

BatuhanW avatar Dec 05 '23 11:12 BatuhanW

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.

hAhl2 avatar Dec 05 '23 13:12 hAhl2

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.

BatuhanW avatar Dec 05 '23 15:12 BatuhanW

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?

Xiayucheng1212 avatar Dec 27 '23 04:12 Xiayucheng1212

Fixed the issue, needed review. @BatuhanW

Conqxeror avatar Jan 20 '24 06:01 Conqxeror