我已经成功创建了一个响应
的所有石墨烯查询query {
person (id: "Mary") {
id
name
}
}
我现在想扩展它以便能够遍历所有人并为每个人返回类似的数据。
query {
people {
count
allPersons {
name
}
}
}
如何让resolve_allPersons
中的people
解析器为每个人拨打person
解析器?
答案 0 :(得分:2)
您所描述的第二个查询可以使用自定义类型完成,例如:
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()