Last active
December 5, 2018 14:08
-
-
Save Fercho191/84d18f74664e8eb89b588a890d523d46 to your computer and use it in GitHub Desktop.
Graphene schema with CustomFiltersets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from graphene_django import DjangoObjectType | |
from graphene import relay, AbstractType | |
from graphene_django.filter import DjangoFilterConnectionField | |
from app.models import Leather | |
from django_filters import FilterSet, OrderingFilter | |
class LeatherFilterSet(FilterSet): | |
order_by = OrderingFilter( | |
fields=( | |
('created', 'created'), | |
) | |
) | |
class Meta: | |
model = Leather | |
fields = { | |
'name': ['exact', 'icontains', 'istartswith'] | |
} | |
class LeatherNode(DjangoObjectType): | |
class Meta: | |
model = Leather | |
interfaces = (relay.Node,) | |
class Query(AbstractType): | |
leather = relay.Node.Field(LeatherNode) | |
leathers = DjangoFilterConnectionField( | |
LeatherNode, | |
filterset_class=LeatherFilterSet | |
) |
Hi! Works like a charm! But you have a typo in
leathers
query, when you're usingPhotoNode
, instead ofLeatherNode
.
You right.. thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! Works like a charm! But you have a typo in
leathers
query, when you're usingPhotoNode
, instead ofLeatherNode
.