【问题标题】:How to handle query with parameter in python graphene如何在 python 石墨烯中处理带参数的查询
【发布时间】:2019-01-23 21:58:53
【问题描述】:
class ProductQuery(graphene.ObjectType):
    products = graphene.List(Product)

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

以上是我查询所有没有参数的产品的代码。我想通过manufacturer_id查询产品是什么?我该怎么做解析器?

their official site上没有文档。

【问题讨论】:

    标签: python graphql


    【解决方案1】:
    class ProductQuery(graphene.ObjectType):
      products = graphene.List(Product, id=graphene.Int())
    
      def resolve_products(self, info, id):
        return Product.objects.filter_by(manufacture_id__exact=id)
    

    您必须添加要查询的参数。

    【讨论】:

    • 请在您的代码中添加简短说明。仅代码的答案对其他人几乎没有帮助,而且往往会被删除。
    猜你喜欢
    • 2020-10-05
    • 2020-07-27
    • 2020-09-19
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    • 2021-12-22
    相关资源
    最近更新 更多