如何在python graphene中使用参数处理查询

时间:2018-08-16 21:26:38

标签: python graphql

class ProductQuery(graphene.ObjectType):
    products = graphene.List(Product)

    def resolve_products(self, info):
        return get_all_products()

以上是我用于查询所有不带参数的产品的代码。我要按制造商ID查询产品什么?我该怎么办解析器?

their official site上没有文档。

1 个答案:

答案 0 :(得分:0)

class ProductQuery(graphene.ObjectType):
  products = graphene.List(Product, id=graphene.Int())

  def resolve_products(self, info, id):
    return Product.objects.filter(manufacture_id__exact=id)