1. Queries
  2. migrations
  3. UserModel
  4. User Schema
  5. cors
  6. static
  7. headers
  8. payumoney
  9. imageupload
  10. Total count

Total count

Is totalCount not implemented on Relay? #162

The solution worked for me.

Because this is scensial to paginate, I've done it as a Mixin to add it to multiple DjangoObjectType like this:

class TotalCountMixin(ObjectType):
    def get_connection(cls):
        class CountableConnection(relay.Connection):
            total_count = Int()

            class Meta:
                name = '{}Connection'.format(
                node = cls

            def resolve_total_count(root, args, context, info):
                return root.length

        return CountableConnection

Then I added it to the DjangoObjectType, in your case it would be:

class ProductNode(DjangoObjectType, TotalCountMixin):
    class Meta:
        model = Product
        filter_fields = {
            'name': ['exact''icontains''istartswith'],
        interfaces = (relay.Node, )

Test it!