import django_filters
import graphene
from graphene_django import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField
from api.models import Children, Parent
class ParentNode(DjangoObjectType):
class Meta:
model = Parent
filter_fields = ["parent_id"]
interfaces = (graphene.relay.Node,)
class ChildrenNode(DjangoObjectType):
class Meta:
model = Children
filter_fields = ["name", "parent__parent_id"]
interfaces = (graphene.relay.Node,)
class ParentFilter(django_filters.FilterSet):
parent_id = django_filters.CharFilter(lookup_expr="iexact")
class Meta:
model = Parent
fields = ["parent_id"]
order_by = django_filters.OrderingFilter(fields=(("created_at", "created_at"), ("updated_at", "updated_at"),))
class ChildrenFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr="icontains")
parent__parent_id = django_filters.CharFilter(lookup_expr="iexact")
class Meta:
model = Children
fields = ["name", "parent__parent_id"]
order_by = django_filters.OrderingFilter(fields=(("created_at", "created_at"), ("updated_at", "updated_at"),))
class Query(object):
parents = graphene.relay.Node.Field(ParentNode)
all_parents = DjangoFilterConnectionField(ParentNode, filterset_class=ParentFilter)
children = graphene.relay.Node.Field(ChildrenNode)
all_children = DjangoFilterConnectionField(ChildrenNode, filterset_class=ChildrenFilter)
Here, the Children table is having the Parent as the foreign key. When querying allChildren in the GraphQL like
query {
allChildren(orderBy: "-created_at") {
edges {
node {
name
parentsSet {
edges {
node {
parentId
}
}
}
}
}
}
}
the parentsSet NodeConnection contains before, after, first, last and parentId as the valid filter fields. Why is it missing the orderBy field and how can it be added to it?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.