如何解决graphene.Union中的多个查询集?

问题描述

我想创建一个具有多种现有类型的 graphene.Union 类型。我能够解决它,但它不是我需要的格式。

架构

from graphene_django import DjangoObjectType

class ageType(DjangoObjectType):
    class Meta:
        model = age

class ethnicityType(DjangoObjectType):
    class Meta:
        model = ethnicity

class combinedType(graphene.Union):
    class Meta:
        types = (ageType,ethnicityType)

class Query(graphene.ObjectType):
    defaultPicker = graphene.List(combinedType)
    def resolve_defaultPicker(self,info):
        items = []
        age_q = age.objects.all()
        items.extend(age_q)
        ethnicity_q = ethnicity.objects.all()
        items.extend(ethnicity_q)
        return items

我在 graphql 管理中使用的查询

{
  defaultPicker{
    ... on ageType{
      id
      age
    }
    ... on ethnicityType{
      id
      ethnicity
    }
  }
}

我想得到这样的输出

{
  "data": {
    "defaultPicker": [
      'ageType': [{
        "id": "2","ethnicity": "American","ethnicityFr": "Test"
      }],'ethnicityType': [{
        "id": "1","familyPlans": "3 kids","familyPlansFr": "3 enfants"
      }],]
  }
}

我尝试了很多方法,但找不到解决方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)