【发布时间】:2020-11-24 15:29:18
【问题描述】:
我有一个从第三方 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
石墨烯中的查询工作正常,但如果只包含一个数据,但我不确定是否有多个对象。
【问题讨论】:
-
不清楚您到底想做什么?你能解释清楚吗?
标签: python-3.x graphene-python