How would one implement totalCount or count on DjangoFilterConnectionField?
See original GitHub issueWith Connection
, one can implement a count
on edges
like so:
from graphene import Connection, ConnectionField, Node, Int
from graphene_django import DjangoObjectType
from ..models import Place
class Thing_Type(DjangoObjectType):
class Meta:
model = Thing
interfaces = (Node, )
class Thing_Connection(Connection):
class Meta:
node = Thing_Type
count = Int()
def resolve_count(root, info):
return len(root.edges)
class Query(object):
things = ConnectionField(Thing_Connection)
def resolve_things(root, info, **kwargs):
return Thing.objects.all()
return len(root.edges)
Given that DjangoFilterConnectionField
won’t accept a Connection
, but requires a DjangoObjectType
, how would one implement an equivalent count
?
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Send the response as count of members who have liked a ...
This is how I resolved it. import graphene from graphene import relay class CountableConnectionBase(relay.Connection): class Meta: abstract ...
Read more >DjangoFilterConnectionField query for all records-django
Are you looking for getting all of the fields within a model as follows? from graphene_django import DjangoObjectType from model.path import Model class ......
Read more >Count The Number Of Events and Venues - Django ... - YouTube
In this video I 'll show you how to add object model counts for our Event, Venue, and User models with Django and...
Read more >Get total count in pagination query - Discuss Dgraph
Given the example above, let says the total count is 150, I want to implement pagination in my website, 10 products per page....
Read more >How To Implement A Graphenedjango Pagination Feature For ...
An example GraphQL pagination API for Relay using Graphene and Django + a Next.js React UI GitHub saltycrane/graphenerelaypaginationexample: An. from django.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@phalt, never mind. Got it. I’ll add this to the wiki FAQ once editing is enabled. Turns out the trick is to subclass
Connection
and declare that as aconnection_class
on the node type.DjangoFilterConnectionField
then uses that declaredconnection_class
class seamlessly, like so:This allows, in my example here, querying:
Which returns:
Is this an official resolution to the issue? It looks like a very clever hack around the issue.