Dealing with cursors in ConnectionField resolve functions
See original GitHub issueIn the Star Wars relay example, it looks like you expect the resolve_ships
method of the Faction
class to return every ship. While this is feasible with a small dataset like that, it’s not an assumption you can make. Does the resolve function get access to the first
and after
argument? Also, how do we supply pagination info?
Looking at the code, it looks like connection_from_list
deals with the resolved data as a complete list. Is there a way to get around this? If the resolve function only gets the arguments, but no way to supply pagination info, should we just return 1 more object than was requested, so that connection_from_list
knows there’s more and can correctly create the pagination info?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Pagination - Join Monster
1. Application-layer Paging. The simplest approach is to do it on the web server. In this approach, Join Monster will handle it by...
Read more >Relay Connection - Plugins - GraphQL Nexus
connectionField method available on the object definition builder: ... main ways to use the connection field, with a nodes property, or a resolve...
Read more >GraphQL Cursor Connections Specification - Relay
This specification aims to provide an option for GraphQL clients to consistently handle pagination best practices with support for related metadata via a ......
Read more >How to resolve "AttributeError: 'function' object has no attribute ...
I am trying to connect to a MySQL database using MySQLdb library. I'm getting an error message that the function has no cursor...
Read more >Implementing pagination in GraphQL and Go using gqlgen
I've chosen to go with cursor-based pagination as it's the more ... at Apollo GraphQL made a helper function to handle the cache...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @bigblind,
connection_from_list
expect an iterable (this iterable had to implementlen
and a item getter likeiterable[20:30]
though). Could be alist
, could be a lazy list, or anything that you could iter through. However, we don’t iter through the iterable until the end (when we show the results).In the example of Starwars relay the
resolve_ships
return a complete list. But the swapi example the method returns an iterable.So, for example, when you are using django querysets, the list is only “resolved” (aka queried in the DB) when we iter though it (when we return the resolved result), and after the list is sliced.
So it will already do in the most optimal way 😃
Hi @bigblind . We’re currently going through old issues that appear to have gone stale (ie. not updated in about the last 6 months) to try and clean up the issue tracker. If this is still important to you please comment and we’ll re-open this.
Thanks!