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.

Is totalCount not implemented on Relay?

See original GitHub issue

This gives me an error in /graphql. Rest works like a charm though.

{
  "errors": [
    {
      "message": "Cannot query field \"totalCount\" on type \"ProductNodeConnection\".",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ]
    }
  ]
}
query{
  allProducts(first:2 after:"YXJyYXljb25uZWN0aW9uOjM="){
    totalCount 
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  
    edges{  
      node{
        id
        name
      }
      cursor
    }
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

45reactions
aminlandcommented, Nov 28, 2017

This is how to do it in version 2 (graphene is woefully undocumented) 😦

class CountableConnectionBase(relay.Connection):
	class Meta:
		abstract = True

	total_count = Int()
	def resolve_total_count(self, info, **kwargs):
		return self.iterable.count()


class ProductNode(DjangoObjectType):
	class Meta:
		model = MyModel
		interfaces = (relay.Node, )
		connection_class = CountableConnectionBase
10reactions
dani0805commented, Jan 24, 2018

Yep that’s what we did but would be nice to have it in a stable release as this is necessary for pagination.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is totalCount not implemented on Relay? - Bountysource
This gives me an error in /graphql. Rest works like a charm though. { "errors": [ { "message": "Cannot query field \"totalCount\" on...
Read more >
Pagination Container - Relay
If not specified, Relay will default to using all of the previous variables and using the total count for the count variable. This...
Read more >
How to pass total count to the client in pageInfo - Stack Overflow
Relay supports arbitrary fields on a connection, so you're free to name this count , totalCount , etc. Share.
Read more >
Pagination | GraphQL
To ensure a consistent implementation of this pattern, the Relay project has a formal specification you can follow for building GraphQL APIs which...
Read more >
A deep-dive into Relay, the friendly & opinionated GraphQL ...
*Although this convention is in the Relay docs, it's not enforced. input AddAlbumInput { artistId: ID! albumName: ...
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