New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to achieve filtering? #82
Comments
I've been working on filtering stuff with graphene-mongo. It's very early work (wasn't planning to put it up till later), so full disclaimers, etc. etc. but you can check it out here (python 3 only): https://github.com/riverfr0zen/graphene-mongo-extras Since there isn't much documentation yet, I also put up a repo with an example flask app that shows you how the queries might look: |
Hi Irfan,
Thank you so much for your wonderful graphene-mongo-extras. I was just playing with the code and found an issue. Would you please help me with it. I would be really thankful to you.
If I have a info of "Highscore" info=ListField(EmbeddedDocumentField(PlaythruInfo)) insted of info = EmbeddedDocumentField(PlaythruInfo) it thows "AttributeError: type object 'NoneType' has no attribute 'name'"
class HighScore(Document):
player = StringField()
score = IntField()
recorded = DateTimeField()
info = EmbeddedDocumentField(PlaythruInfo)
use
info=ListField(EmbeddedDocumentField(PlaythruInfo))
and it will throw an error.
AttributeError: type object 'MongoengineConnectionField' has no attribute 'name' OR AttributeError: type object 'NoneType' has no attribute 'name'
Please help.
Regards
Anil
www.ibizwaresolutions.com<http://www.ibizwaresolutions.com>
A Step to Hug the Universe!
"The difference between a successful person and others is not a lack of strength, not a lack of knowledge, but rather a lack in will." - Vince Lombardi
…________________________________
From: Irfan Baig <notifications@github.com>
Sent: Monday, April 29, 2019 4:38 AM
To: graphql-python/graphene-mongo
Cc: anilwarbhe; Author
Subject: Re: [graphql-python/graphene-mongo] How to achieve filtering? (#82)
I've been working on filtering stuff with graphene-mongo. It's very early work (wasn't planning to put it up till later), so full disclaimers, etc. etc. but you can check it out here (python 3 only):
https://github.com/riverfr0zen/graphene-mongo-extras
Since there isn't much documentation yet, I also put up a repo with an example flask app that shows you how the queries might look:
https://github.com/riverfr0zen/graphene-mongo-extras-examples
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#82 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ALKYDUW4B2WLYBTTCTCVMXLPSYVALANCNFSM4HHLI4WQ>.
|
@anilwarbhe I will respond to the issue you created on that repository when I get a chance. |
@anilwarbhe @riverfr0zen : Close this one and let's move the discussion on https://github.com/riverfr0zen/graphene-mongo-extras later. |
Hello, I have had the same issue and I solved it by creating a filter class like this (It even got pagination 😱): class Product(db.DynamicDocument):
name = db.StringField(required=True)
tags = db.ListField(db.StringField())
... And the schema class ProductSchema(MongoengineObjectType):
class Meta:
description = "Products"
model = models.Product
connection_class = ExtendedConnection
interfaces = (Node,)
class ProductFilter(graphene.InputObjectType):
name = graphene.String()
name__icontains = graphene.String(name="name_icontains")
tags__in = graphene.List(graphene.String, name="tags_in", description="Product has to have ONE of the provided tags")
tags__all = graphene.List(graphene.String, name="tags_all", description="Product has to have all provided tags")
class QueryProductsSchema(graphene.ObjectType):
total_count = graphene.Int()
total_pages = graphene.Int()
products = graphene.List(ProductSchema)
class Query(graphene.ObjectType):
class Meta():
description = "Root Query"
query_products = graphene.Field(QueryProductsSchema, first=graphene.Int(), offset=graphene.Int(), filters=ProductFilter())
def resolve_query_products(self, info, **kwargs):
query = models.Product.objects(**kwargs.get("filters", {}))
pagination = query.paginate(kwargs.get("offset", 1), kwargs.get("first", 20))
return QueryProductsSchema(total_count=pagination.total, total_pages=pagination.pages,
products=pagination.items) Example Query: {
queryProducts(first: 2, offset: 1, filters: {
tags_in: ["ww"],
name_icontains: "hähnchen"
}) {
totalCount
totalPages
products {
name
tags
}
}
} To define what field should be querried like what you have to name the fields in the ProductFilter class according to your needs (http://docs.mongoengine.org/guide/querying.html) |
@dscso big thank you for posting your solution! |
Hi,
It would be good if graphene mongo had support for filters. For example
query { allPersons(filter: { age_gt: 18 }) { firstName lastName } }
Is there any other way to achieve this or fire a query like thin in graphene-mongo?
The text was updated successfully, but these errors were encountered: