Steams / ra-data-hasura-graphql

React-admin data provider for Hasura GraphQL endpoints
MIT License
211 stars 33 forks source link

How can I have custom identifiers/primary keys for my resources? #57

Open akamit21 opened 4 years ago

akamit21 commented 4 years ago

My table has a primary key other than id and react-admin enforces id to be returned in the response by the DataProvider. So can I configure different primary keys/identifiers for my resources?

caston1981 commented 4 years ago

hi Akamit21,

I am a novice (at least as a developer) myself but I hope this helps you.

In the readme for ra-data-hasura it has a section on different primary keys

best regards,

Chris

avimoondra commented 4 years ago

Have a similar question as @akamit21 !

(@affluent-bilby-classifieds that is for a different library that is not compatible with ra-data-hasura-graphql. I'm actually in the process of migrating from that library to this one.)

avimoondra commented 4 years ago

A guess would be some modification here: https://github.com/Steams/ra-data-hasura-graphql#customize-fields-variables-responseparser ?

akamit21 commented 4 years ago

Have a similar question as @akamit21 !

(@affluent-bilby-classifieds that is for a different library that is not compatible with ra-data-hasura-graphql. I'm actually in the process of migrating from that library to this one.)

Yes, I tried to implement but didn't work out.

polymeris commented 4 years ago

Having the same issue, with the added complication that I am using composite primary keys. Did any of you figure it out?

akamit21 commented 4 years ago

Nope, not yet, but to resolve my primary key problem I rename the primary key column to id when it fetches the data and generates the data-list, in that way I receive my primary-key column renamed as id.

divramod commented 3 years ago

@akamit21 can you show an example of your workaround on how you are renaming the primary key to id while fetching the data? it would be nice to have a option to configure that.

diazhector98 commented 3 years ago

@divramod agreed. @akamit21 could you show an example?

akamit21 commented 3 years ago

Well, I made the changes in getResponseParser.js file of the library. I had a employee table with primary_key name emoloyee_id. So I add only these line in code and it worked.

if (key === 'employee_id') { return { ...acc, id: dataKey }; }