Closed nicolasrouanne closed 4 years ago
Thanks for opening this issue -- that doc is out-of-date, and I haven't written a better replacement yet 😖 . In the new pagination system in 1.10+, the methods of connection objects have changed.
items
contains the "raw" collection object returned from application code (for example, a whole Array or an unpaginated ActiveRecord::Relation) nodes
contains the paginated items. This value will be nodes { ... }
(or edges { node { ... } }
) in the GraphQL result So, you code could be updated like this:
def total_count
+ object.items&.count
- object.nodes&.count
end
Does that work for you?
Let's keep this open til I fix that doc.
Using object.items&.count
works perfectly! 😃🎉
Thanks for the quick reply 🙏
I would find it very useful indeed to know more generally what are the available methods to call (be it in Types
, Connection
, Edge
, etc.). For instance, knowing that you can access object
or items
is not very easy to find, as you say.
It would be great if that could be added to the guides, which I find very useful and readable compared to the RubyDoc 🙈
total_count should be there by default
object.items.size
is not working for me anymore, I get the error:
undefined method `items' for #<GraphQL::Pro::RelationConnection::OrderedRelationConnection:0x00007efc2fd66ff0
Hey @angeloocana, could you please open a new issue (https://github.com/rmosolgo/graphql-ruby/issues/new/choose) for the problem you encountered? I'd like to understand what you were working on (or what else changed) when your code stopped working for you, but it looks like your situation is a bit different than the one described here last year.
Describe the bug
When trying to get the
total_count
of a connection, I get only the number of results filtered by the pagination, not the number of objects in the connection.Versions
graphql
: 1.10.3rails
: 6.0.2.1graphql-batch
: 0.4.2GraphQL schema
GraphQL query When querying with no pagination parameters, I get the correct amount of objects in
totalCount
, i.e. all the objectsWhen passing pagination parameters the
totalCount
doesn't reflect the entire connection, rather the current pageExpected behavior
I expected
total_count
to return the total number of items in the connection, as pointed out in that wiki articleActual behavior
It only returns the number of items in a page.