-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[On hold] Fetch more / Infinite Scroll #350
Conversation
Followup to #335 |
Can you rebase on master, as well? |
yep, let me fix a test first |
I already rebased minutes ago ... |
And ... all done! Ok, I leave you the repo as it is now, I won't be able to contribute this weekend on this part (need to send my macbook to support) but I'll be back on monday! I may write some doc on an another computer though ... |
OK @rricard are you OK if I just work on this and maybe merge it? |
Just really excited to deliver this feature to our app team and see if they can use it in Galaxy. |
No problem! I started that work so I could use the feature so that's cool if you take it from here. If you don't understand something I did, ping me here or on slack. |
Well I've got about 6 hours today to try to finish this and #336, let's see if I can get it done! Days without meetings don't come by too often :] |
So I think I'm going to remove a few things, in particular the sorting options in the directive. I think I'd rather add less stuff for now, and add more options later if it turns out the minimal approach is not convenient. |
@stubailo do you have an ETA for this? I'd rather not hack together a solution for something I need to ship if this is close! |
I'd guess merge by Tuesday. I was planning on doing it Friday but didn't get it finished. |
Let me know if you need some help! |
Ok, so I bumped apollo's max Gzipped file to 36kB. |
FYI, rebased on |
okay pulling the rebased version |
@stubailo not a fan of your directive validation simplification. The goal of that was to be able to let the user integrate custom directives later... If we use this hardcoded validation (that I implemented at first as well) this will prevent easily inserting new custom and easily validable directives later. |
OK I have one concern right now: how does polling/refetch work with this pagination model?
|
@rricard honestly I don't think it's a good idea to write a general validation system if we aren't going to use it right now. Who knows what kind of validation we will need in the future? Maybe we won't need any general validation, in which case this solution is good, or maybe we will need very complex validation with dependencies between arguments, in which case we can't predict what we will need. |
pollinterval will work like a refetch like it does right now. I don't know if we can customize that in order to do paginated polling |
@rricard I feel like it would be weird if someone set up a pollInterval, then scrolled down/loaded more data, and then the data was thrown away because the polling interval was hit. I'd be in favor of throwing an error if polling and fetchMore are used in one query, what do you think? |
for the validation system: I will soon have validation needs but fair enough, I'll do an another PR when the need will be imminent. Basically here is my thought process: if graphql-js allows to add custom directive validation, we should be able to do that (or let that happen) as well on the client. So if you don't want anything to do with validating custom directives, maybe just let unknown directives pass through (and let the server validate them) |
pollInterval+pagination won't play well together I agree. I don't think they should. When you take control with a fetchMore, you now become responsible for loading stuff (and merge it) in the order you need it. |
Personally I think it would be fine to let through unknown directives. This, combined with custom network interfaces, could be an easy way to implement Do you think directive validation via static analysis (ESLint etc) is sufficient? Or maybe it can be something that is done only in a development build? I feel like it can get pretty complicated and it seems odd to do all of that work and load all of the logic at runtime.
Cool, let's make it throw an error somehow. |
Let me know if you think this is reasonable, but my goal is to merge something that is as minimal and flexible as possible, then add additional options and built-in stuff once people have a chance to try it out. This is why I removed some of the things you had already implemented like special sorting options, prepend, etc, since I think they are covered by the |
Added a stripApolloDirectivesFromRequest used in: - QueryManager to patch mutations - batching to patch queries
Ok, @stubailo, it's done! Had to just go slower and structure things more correctly. Now the annotation is never sent to the server but is still usable from within the client (especially when writing the store. I managed to get that by transforming the query as immutably as I could. |
Now we just need to figure out what we finally want:
|
Thanks for that - I think your solution is great, basically what I was trying to do as well.
Another way we could get per-field control is if we made the
My main concern here is if someone new is reading the code, and sees "quietArguments", I think they would get pretty confused. I guess at that point you could go read the docs, but it seems like something even like "paginationArguments" or maybe even "ignoredArguments" or similar actually gives you an idea of what it's for. |
Ok, I need to leave work so I may let you do that. I agree with what you said 👍 |
Todos for me:
This is turning out to be a lot of work! But I think it will be worth it. We just need to make sure when we merge everything it's maintainable. But perhaps that can be done in a refactor for a later major version bump. |
Hey, so to be honest, I'm having a really really hard time reasoning about the possible implications of all of these changes, especially because there are a lot of things together. I think this PR kinda became too big for its own good. I think this is mostly my fault, because I didn't put in effort at the beginning to encourage splitting this into smaller chunks of work -- I'll make sure it doesn't happen again in the future. I'm going to try a different approach for this feature, which is to try to split this up into the smallest PRs possible, each with their own tests etc. For example:
For each of those, it will be a lot easier for me to reason about whether we have good test coverage, if there are weird edge cases, etc. Sorry for anyone who was relying on this feature getting merged this week - I'd rather take a step back now than merge something that I don't fully understand the implications of. |
Here's the first PR, to not throw on unknown directives: #372 |
@stubailo: we'll wait. But let me help you though, I'll try to break down that today. |
@stubailo: I think that's a pretty great decision in the long run. Even in order to get this merged, I think that's a good idea since it will make the review easier therefore faster. |
@stubailo: made a PR for stripping apollo directives |
Adds a fetchMore method able to fetch new data and concatenate it into the store, performing, that way, an infinite scroll behavior!
TODO:
concatPaths: Array<string>
topaginationParameters: Array<string>
, that way suppressing for special paths those parameters from the store ids. (ex: instead ofROOT_QUERY.allPosts({cursor: 'x', type: 'y'})
, ifpaginationParameters: {'ROOT_QUERY.allPosts': ['cursor']}
is set, it will only beROOT_QUERY.allPosts({type: 'y'})
paginationParameters
=>quietArguments
append/prepend/sort
fetchMore()
to the public API,paginationParameters
everytime there is some store access & `fetchMore everytime we're doing a query)paginationParameters
in account.graphql-tools
)Basic usage example:
Advanced usage example:
Advanced usage example with directives only!: