Using DjangoFilterConnectionField with my own Connection
See original GitHub issueHi guys,
I’ve been trying to use DjangoFilterConnectionField
with my own Connection
but it only accepts DjangoObjectType
. I saw that 15664bdc0b76d9118d41204922a41b808d5848ad attempts to implement it but it got reverted in 4cc46736bf7297d3f927115daedd1c332c7a38ef and after 48bcccdac2deaf3e9ad58eb0758ca9f255e3e38e I get an assertion error.
Is this no longer supported? Is there an alternate way?
Basically I’d like to add custom fields like count
and have filtering support. In the code below, I can’t define count
under categories
unless I change to ConnectionField
:
import graphene
from graphene import Node, Connection, ConnectionField
from graphene_django.types import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField
from cookbook.ingredients.models import Category, Ingredient
class IngredientType(DjangoObjectType):
class Meta:
model = Ingredient
filter_fields = ['name', 'notes', 'category']
interfaces = (Node,)
class IngredientConnection(Connection):
count = graphene.Int()
class Meta:
node = IngredientType
def resolve_count(self, context, **kwargs):
return self.iterable.count()
class CategoryType(DjangoObjectType):
ingredients = ConnectionField(IngredientConnection)
class Meta:
model = Category
filter_fields = ['name']
interfaces = (Node,)
@staticmethod
def resolve_ingredients(self, context, **kwargs):
return self.ingredients.all()
@staticmethod
def resolve_all(self, context, **kwargs):
return Category.objects.all()
class CategoryConnection(Connection):
count = graphene.Int()
class Meta:
node = CategoryType
def resolve_count(self, context, **kwargs):
return self.iterable.count()
class Query(graphene.ObjectType):
categories = DjangoFilterConnectionField(CategoryType)
# categories = ConnectionField(CategoryConnection, resolver=CategoryType.resolve_all)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Using DjangoFilterConnectionField with custom Connection in ...
From my understanding, User node needs to be passed UserConnection on it's meta, and UserConnection needs to be passed User on it's meta....
Read more >Using DjangoFilterConnectionField with custom Connection in ...
Coding example for the question Using DjangoFilterConnectionField with custom Connection in ... class UserConnection(Connection): extra = graphene.
Read more >django-filter - Graphene-Python
Filtering¶. Graphene-Django integrates with django-filter (2.x for Python 3 or 1.x for Python 2) to provide filtering of results. See the usage ...
Read more >Graphene-Python
There are several ways you may want to limit access to data when working ... To limit fields in a GraphQL query simply...
Read more >graphene-django-filter - PyPI
To use, simply replace all DjangoFilterConnectionField fields with AdvancedDjangoFilterConnectionField fields in your queries. Also,if you create custom ...
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
Why did you close this issue? I am in the same trouble.
@a3ammar Thanks for adding this! I solved it with something similar, but using
DjangoFilterConnectionField
, here:https://github.com/graphql-python/graphene-django/issues/636