Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在graphene中使用对象列表作为查询?_Python 3.x_Graphene Python - Fatal编程技术网

Python 3.x 如何在graphene中使用对象列表作为查询?

Python 3.x 如何在graphene中使用对象列表作为查询?,python-3.x,graphene-python,Python 3.x,Graphene Python,我有一个从第三方api获得的对象列表: heroes : [ { "id": 1, "name": "James" }, { "id": 2, "name": "Monk" } ] 这就是我想我被难倒的地方,我可以创建一个字典来加载一个数据,但是如果我有多个对象呢 def get_

我有一个从第三方api获得的对象列表:

heroes : [
    {
        "id": 1,
        "name": "James"
    },
    {
        "id": 2,
        "name": "Monk"
    }
]
这就是我想我被难倒的地方,我可以创建一个字典来加载一个数据,但是如果我有多个对象呢

def get_hero(heroes):
   hero = {}
   hero['hero_id'] = heroes[0]['id']
   hero['hero_name'] = heroes[0]['name']
   return hero
石墨烯相关:

   class Hero(ObjectType):
       hero_id = Int()
       hero_name = String()

   
   class Query(ObjectType):
       hero_search = Field(Hero, hero_id=String())

       def resolve_hero_search(self, info, **kwargs):
          return get_hero(heroes=kwargs) # this is a just a placeholder cause I think there is no issue here

graphene中的查询工作正常,但如果只包含一个数据,但我不确定是否有多个对象。

您需要从输入中获取ID/字符串列表:

hero_search = Field(Hero, hero_id=graphene.List(graphene.String))

您需要从输入中获取ID/字符串列表:

hero_search = Field(Hero, hero_id=graphene.List(graphene.String))

不清楚你到底想做什么?你能解释清楚吗?不清楚你到底想做什么?你能解释清楚吗?