Skip to content

first/last, before/after support #21

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

Closed
mickhansen opened this issue Sep 22, 2015 · 8 comments
Closed

first/last, before/after support #21

mickhansen opened this issue Sep 22, 2015 · 8 comments

Comments

@mickhansen
Copy link
Owner

It would be great to support the Relay connection args out of the box for users.
first/last would simply require the user to select what field to order on.

before/after is a little more tricky, we can't simply do a comparison on ID since the order might be on something that doesn't align with the ID.

We might need to do something like [field] > (SELECT [field] FROM [table] WHERE id = [after] LIMIT 1) which might kill performance slightly.

/cc @brad-decker

@brad-decker
Copy link
Contributor

graphql/graphql-relay-js package actually supports this with their default result parsing feature. I really think that trying to add native postgres query support for this would just result in a slower operation then what is being done already. Added tests for all the mentioned arguments to show it working.

@mickhansen
Copy link
Owner Author

Haven't looked at the relay code yet, but i assume it does filtering after the values have been loaded from the database?
So in the case where you have 500 tasks, it will load all 500 and then take N of that? Then it might be good to actually filter in SQL instead.

@brad-decker
Copy link
Contributor

yeah, the filtering is done on the result level - not prior to the data being queried. We'd have to do a deeper integration which we will most definitely want to implement at some point for application speed. Before After also uses a cursor for record parsing so we'd need to really look into how that cursor is generated and apply that our code.

This will be an optimization level feature for our project so it might be a bit before we get to it.

@mickhansen
Copy link
Owner Author

I'll likely need it for my project since querying the entire range would be very expensive.
Not sure when i'll switch to Relay queries though since i'm using GraphQL with Angular atm.

@mickhansen
Copy link
Owner Author

@mickhansen
Copy link
Owner Author

So there's some talk about constructing your own cursors and storing data in them.
For example if paging by say createdAt, each cursor could hold that items createdAt value to easily filter without having to do a subquery lookup.

@mickhansen
Copy link
Owner Author

We'll probably need custom logic for all this, and won't be able to use graphql-relay's connectionFromArray like we currently do (https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js#L38).

/cc @aweary @brad-decker

@mickhansen
Copy link
Owner Author

bc9683f

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

No branches or pull requests

2 participants