ra-data-hasura-graphql
ra-data-hasura-graphql copied to clipboard
Support for graphql enums
Thanks for your work on this!
I'm hoping to switch over from the JSON API data provider to this data provider but encountered an issue with the <ReferenceInput>
component on a foreign key relationship to a table that's configured in Hasura as a graphql enum.
It seems there's some sort of coupling to the idea that every entity should have a distinct id
, which is not allowed for graphql enums in Hasura.
At first, I was encountering issues because the sort
property on <ReferenceInput>
defaulted to sorting on id. I was able to override this like so:
<ReferenceInput
source="product_type"
reference="product_type"
sort={{ field: 'value', order: 'DESC' }}
>
<SelectInput
optionText="comment"
/>
</ReferenceInput>
In the above example, a model product
has a foreign key relationship on the product_type
column to a product_type
table on its primary key column value
.
However, this yielded a console error which prevented data from being populated in my <SelectInput>
:
The response to 'GET_LIST' must be like { data : [{ id: 123, ...}, ...] }, but at least one received data item do not have an 'id' key. The dataProvider is probably wrong for 'GET_LIST'
The product_type
table does not have an id
and I cannot add one because I want to use that table as a graphql enum. Does anyone know how I can get around this?
My solution: custom GraphQL field name value -> id
@hetaochen could you elaborate? Were you able to make this work in your own environment? Where did you apply that mapping?
I'm very new to react-admin and hasura here, my apologies if this should be obvious!
Ah, good idea! Thanks!
I wonder if there's another solution that could be implemented at the package level that would allow us to use a model without an id
. Going to leave this issue open for now.