当使用下面的模式时,我在查询产品时总是得到空值。根据我对文档的理解,它应该返回一个包含id和name的2个对象的数组。有谁能帮助我理解为什么下面的代码不起作用?在
import graphene
class Product(graphene.ObjectType):
id = graphene.Int()
name = graphene.String()
class Query(graphene.ObjectType):
products = graphene.List(Product)
def resolve_products(self, info, **kwargs):
return [{
"name": "TEST", "id": 1
}, {
"name": "TEST2", "id": 2
}]
schema = graphene.Schema(query=Query)
我不知道你现在是否明白。我遇到了和你一样的问题,谢谢你上网。下面的答案可能有帮助。在
另外,我使用
flask
来可视化web。在运行.py时,输入
^{pr2}$http://localhost:4901/graphql
进行查询。在返回列表类型。
return [Product(name="TEST", id=1), Product(name="TEST2", id= 2)]
相关问题 更多 >
编程相关推荐