question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dealing with cursors in ConnectionField resolve functions

See original GitHub issue

In 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:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
syrusakbarycommented, Dec 4, 2015

Hi @bigblind, connection_from_list expect an iterable (this iterable had to implement len and a item getter like iterable[20:30] though). Could be a list, 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 😃

0reactions
jkimbocommented, Feb 18, 2018

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found