Graphene-django: Ordering filter in foreign key sets missing

Created on 2 Mar 2020  路  1Comment  路  Source: graphql-python/graphene-django

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?

wontfix

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanoSega picture StefanoSega  路  4Comments

khankuan picture khankuan  路  4Comments

MythicManiac picture MythicManiac  路  3Comments

artofhuman picture artofhuman  路  3Comments

amiyatulu picture amiyatulu  路  3Comments