2

I have a DjangoObjectType class and its query as below.

class ExampleType(DjangoObjectType):
    class Meta:
        model = Example
        interfaces = (relay.Node,)

    order_number = String()
    group = String()

    def resolve_order_number(self, info, **kwargs):
        return "order number"

    def resolve_group(self, info, **kwargs):
        return "group"

here is the query;

class Query(ObjectType):

    all_data = DjangoFilterConnectionField(
        ExampleType,
        filterset_class=ExampleFilter,
    )

    def resolve_all_data(self, info, **kwargs):
        return Example.objects.with_annotations()

I need to add another field that is not in ExampleType to the query result. So I have created another ObjectType class as follows.

class CombineData(ObjectType):

    datas = List(ExampleType)
    error_info = String()

    def resolve_error_info(self, info, **kwargs):
        return "ERROR INFO"

And I have changed the query like below.

class Query(ObjectType):

    all_data = DjangoFilterConnectionField(
        CombineData,
        filterset_class=ExampleFilter,
    )

    def resolve_all_data(self, info, **kwargs):
        return Example.objects.with_annotations()

However, I'm getting many errors such as DjangoConnectionField only accepts DjangoObjectType types error. If I change the all_data type as Field there is no error but I also need to use my ExampleFilter in the combined class but it's an ObjectType class.

How can I fix this issue?

Aslı Kök
  • 616
  • 8
  • 19

0 Answers0