Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for async connections #80

Open
clayallsopp opened this issue Apr 28, 2016 · 3 comments
Open

Better support for async connections #80

clayallsopp opened this issue Apr 28, 2016 · 3 comments

Comments

@clayallsopp
Copy link

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: clayallsopp/graphqlhub@07fec4c#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));
});
@wincent
Copy link
Contributor

wincent commented Apr 28, 2016

Can you use connectionFromPromisedArraySlice to avoid resolving the entire entire set?

@clayallsopp
Copy link
Author

Not really, it doesn't easily work out-of-the-box - I believe you have to write the logic which calculates the correct sliceStart accounting for whatever args are passed, which ends up duplicating logic from within connectionFromArraySlice

I ended up doing this, takes advantage of the fact that cursors are soley based on the offset and not whatever the array contains: https://github.com/clayallsopp/graphqlhub/pull/29/files; would be happy to open a PR to merge it into graphql-relay-js if its a thing that might be useful for others, but totally happen to just close this too

@pranaygp
Copy link

pranaygp commented Jan 7, 2018

@clayallsopp have you figured out a clean way to deal with this?

I too have a similar case where it's easier for me to fetch exactly the data I need instead of fetching all the data and having the library trim the data after the fact. I think this is rather common (in my case, request a slice of the database collection instead of the entire thing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants