我已经成功创建了一个响应的全石墨烯查询
query {
person (id: "Mary") {
id
name
}
}
我现在想扩展它,以便能够循环遍历所有人并为每个人返回类似的数据。
query {
people {
count
allPersons {
name
}
}
}
我如何获得resolve_allPersons
解析器在people
打电话给person
每个人的解析器?
您描述的第二个查询可以使用自定义类型完成,例如:
class AllPeopleType(graphene.ObjectType):
count = graphene.Int()
all_persons = graphene.List(YourPersonType)
def resolve_count(self, info, **kwargs):
# assumed that django used on backend
return Person.objects.count()
def resolve_all_persons(self, info, **kwargs):
return Person.objects.all()
并查询:
class YourQuery(object):
# person = ...
people = graphene.Field(AllPeopleType)
def resolve_people(self, info):
return AllPeopleType()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)