ra-data-hasura-graphql icon indicating copy to clipboard operation
ra-data-hasura-graphql copied to clipboard

Hasura relationships (nested resources)

Open ceracera opened this issue 4 years ago • 3 comments

How can we query for relationships in Hasura?

I saw #30 but it would be better if we could have it out of the box. What is the benefit of this over ra-data-hasura if we can't fetch nested resources?

I saw that here https://github.com/Steams/ra-data-hasura-graphql/blob/7397a643293b9582e26795d73129fd84f032070d/src/buildGqlQuery.js#L46 OBJECT types are being dropped. Maybe we could keep them and add their fields.

Also, it would be great if we could fetch only requested fields, not whole introspection result.

Nested resources + fetch only requested fields = GraphQL win :)

ceracera avatar Apr 28 '20 00:04 ceracera

Do you have a suggestion on how to implement this? What else would you need to do besides removing object exclusion check?

jonathan-cfmp avatar May 19 '20 02:05 jonathan-cfmp

I think the key thing is getting only requested fields. If we don't have that, than we could be stuck in endless loops with nested queries.

For example, if we have author that has relationship posts and post has author, then, without specifically asking for only required fields, a query like author { posts } would be stuck in a loop.

ceracera avatar May 20 '20 12:05 ceracera

@ceracera @jonathan-cfmp I've raised PR https://github.com/Steams/ra-data-hasura-graphql/pull/68 which should allow for everything you've mentioned above - only getting requested fields, getting relationships etc. Let me know what you think - the README in my PR shows show it works, and I've built a small sample app: https://github.com/cpv123/react-admin-hasura-queries

It also doesn't introduce any breaking changes. I'm hoping that @Steams can take a look and have it merged if all ok.

cpv123 avatar Nov 29 '20 02:11 cpv123