Open webdeb opened 3 years ago
Same here! Do you know how to fix this?
hmm, well I copied src and fixed some files locally. To fix it you basically have to cast the id to the correct type, so basically parseInt
. My code is here:
const castIdType = (params, resource) => {
const id = params.id
const target = params.target
if (!id) return
const key = target ?? "id"
const typedParam = resource.type.fields.find(f => key === f.name)
if (!typedParam) return
if (getFinalType(typedParam.type).name === "Int") {
params[key] = parseInt(params[key])
}
}
const buildVariables = introspectionResults => (
resource,
aorFetchType,
params,
queryType
) => {
// cast the id before using in the switch..
castIdType(params, resource)
Its not best code at all, but it works for me, so if it helps someone else, I am glad to help ;)
Any working code is better than "best" but buggy ;)
Thanks for your help but it is still beyond my JS skills... could you tell me some more details where to paste it and where to execute?
What do you mean by "fixed some files"? I can see only ra-data-hasura.js
@Rigel772 I've copied the whole src directory of this package into my code base, and imported it instead of "ra-data-hasura", I had to edit the buildVariables.js file in the main exported function which I called buildVariables
Makes sense, Thank you
Can we have a solution for this
https://github.com/hasura/ra-data-hasura/issues/50#issuecomment-794620383
This works. Can we add this to the default buildVariables function or into buildQueryFactory?
@webdeb hi friend can you open a PR with your changes? Would this affect people whose id type is a string? Thank you!
I've a basic entity (labels) with an id of type integer. When I go to the edit page
#/labels/1
This query is then produced:variables:
{where: {id: {_eq: "1"}}, limit: 1}
As you can see id is treated as a string.
And Hasura responds with: