Comments (5)
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 :)
from graphene.
Can I just create my own field with a type of Connection
? The database I'm using, rethinkdb, allows me to do much more optimized queries with cursors than with indices based on len
. Basically, with the approach that you use, I need to know the index of every item in the database. With cursors, a rethinkdb query would look like this:
`r.db("my_db").table("users").between(cursor, r.maxval).limit(first+1).run(connection)``
If you're not interested in rethinkdb, I don't expect you to look up how this code works, but I wanted to give a use case for actually doing this.
The reason I'm fetching first+1
items, is so that I know there's a next page of results. if the query returns first
items or fewer, I know there are no more items.
from graphene.
Good catch. I will rethink better how we can handle this.
Probably moving some code from the graphql_relay
Python library to graphene
and wrapping in some class where people could manage it easily is the path to go!
Will keep this issue open until we have a good way for handling this case.
from graphene.
Similar case here working with AppEngine's NDB (would be the same for HBase or most other nosqls I guess).
I have a huge table. You can iterate it using a starting cursor value (you get the cursor value from the DB) and count of entries you want to fetch. There's an iterator that can do this in batches... but there's no len() operation...
Example fetching a page:
greets, next_curs, more = Greeting.query().fetch_page(10, start_cursor=None)
more
will be True\False on wether there's a next page and next_curs
is the start_cursor for the next query.
Is there a way to implement this logic of iterating a big list with no len() ?
from graphene.
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!
from graphene.
Related Issues (20)
- How to desirelize from graphene object to json? HOT 2
- How to use resolve in Graphene Relay Node? HOT 4
- cannot import name 'connection_from_list_slice' from 'graphql_relay.connection.arrayconnection' HOT 2
- Allow configuring schema.introspect
- Thanks for Thanks for GraphQL Python Roadmap HOT 1
- Leading white spaces in description casuing issues HOT 1
- `graphql_schema` introspection doesn't output docstrings descriptions
- InputObjectType causing encoding issues with JSONField HOT 1
- @include and @skip directives lead to irrelevant errors HOT 2
- Provide a way to configure default timezone of DateTimes HOT 3
- Turning Non-null to is_null HOT 3
- Enum conversion to Graphene Enum fails if Enum name is "type" HOT 1
- Enum equality comparison is inconsistent
- http://www.graphene-python.org Has EXPIRED HOT 3
- Upload file HOT 2
- Unexpected argument in Pycharm 2023.2.1 HOT 1
- Default_value option in Arguments inside Mutation is not working as expected HOT 2
- Exception: NonNull could not have a mounted String() as inner type. Try with NonNull(String).
- Returning non fatal errors alongside data
- Conversion to snake_case fails on nested inputs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene.