Is your feature request related to a problem? Please describe.
When working with @connection in a relational DataStore model, I find myself having to loop through the results and manually resolve the connection fields one by one whereas with API.graphql I don't have to.
Fetching Posts with comments @connection for examples requires me to:
. Fetch all the posts
. loop through the posts and for each post fetch the comments
Given the simplicity of Datastore API, the fetching is not a big deal if you have one @connection, but once you have many it starts to feel cumbersome.
Describe the solution you'd like
It would be cool if Datastore automatically resolves the @connections the way API.graphql works.
@iartemiev 馃憖
I'm trying to understand this issue, as a developer on my team ran into something very similar today and I am working under the assumption it's an issue on our end, but this ticket makes me question that.
Are you saying that in the example Post and Comment example documented in AWS Docs that the Post.comments field isn't automatically populated when you query for a Post such as by:
const post = (await DataStore.query(Post, p => p.id("eq", postId))[0];
This wouldn't return a Post object with a populated comments array?
If that's the case why would the generated TypeScript types contain a comments array if it's not useable.
I know I must be missing something here, so apologies for that, I'm just trying to see if I can unblock my dev on this issue so diving in.
@undefobj could you please quickly clarify this to avoid us going down the wrong path? Thanks.
That's correct, comments currently does not get populated. The docs specify retrieving them separately by passing in the related postID in the predicate.
We are currently working on a solution to retrieving related child items when querying a parent, so it will be possible to do in the near future.
Thanks @iartemiev I appreciate the clarification that helps us avoid going down rabbit holes on our end, and I'm also glad to see it's something on your radar for a future enhancement.
It's great to see DataStore being actively worked on and enhanced to fill these gaps, as really does make a huge difference for our use of DataStore as it's typically death by a thousand papercuts for us, but you guys are steadily fixing them, which makes me excited.
Most helpful comment
That's correct,
commentscurrently does not get populated. The docs specify retrieving them separately by passing in the relatedpostIDin the predicate.We are currently working on a solution to retrieving related child items when querying a parent, so it will be possible to do in the near future.