Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle query with parameter in python graphene

Tags:

python

graphql

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

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

Above are my code for query all product with no param. What is I want to query product by manufacture_id? How to do I do the resolver?

There is no document on their official site.

like image 432
Nicolas S.Xu Avatar asked Aug 16 '18 21:08

Nicolas S.Xu


1 Answers

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)

You have to add the parameter you want to query by.

like image 106
Upfrontbeats Avatar answered Nov 17 '22 01:11

Upfrontbeats