graphql / graphql/graphql-relay-js
Better support for async connections
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 177
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
Hey, a pretty common situation is that getting the list of connected IDs is cheap (i.e. the list of the IDs of your friends), but resolving each ID is expensive.
Specifically for this kind of use case: https://github.com/clayallsopp/graphqlhub/pull/28/commits/07fec4c728cbf55b321bcdcdf3741c53944230d2#diff-6cd9d3d473d2f9b30b961ebfb3d3f048R50 - I have the entire list of IDs in memory, so if the query specifies `first: 5` or provides a cursor, it would be great to reduce the set of IDs we're resolving before we resolve them. the current `connectionFromPromisedArray` doesnt help in this regard, as you have to resolve the entire list and then it trims after-the-fact
I think something like this API would be very helpful in general - I think it's possible? (assuming you have the entire list of IDs in memory and cursors are pure functions of offset and IDs)
```
let connectionIds = item.kids;
return promisedConnectionFromIdsArray(connectionIds, args, (trimmedIds) => {
return Promise.all(trimmedIds.map(getItem));
});
```
Contributor guide
Assessment
This issue has not been assessed yet.