-
Notifications
You must be signed in to change notification settings - Fork 228
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
Add filters #164
Add filters #164
Conversation
1 similar comment
This should really be merged. @syrusakbary, is there a reason why it hasn't been yet? Edit: I can actually see a couple of problems with this commit. I will attempt to provide some suggestions with the new Github features. |
@ahokinson @syrusakbary |
I think my criticisms are stylistic and personal preference. There's some typos and I personally wouldn't leave TODO comments in a contribution. I also think that some of your function names as well the use of However, I don't dispute that this works. I borrowed and adapted it for my own needs and it helped me to understand how arguments are constructed. Honestly, I'm really not sure what the stance graphql-python has on contributions. If you look across their projects, there are so many ignored questions and contributions in addition to tutorials and examples that don't even work correctly. Either way, I support adding filtering to this similar to how it is done in the graphene-django implementation. Here is the relevant part of my implementation for comparison:
|
Hi, is there any progress about this filterableConnectionFiled feature in graphene-sqlalchemy. It looks is helpful. |
Hi, sorry, but I don't have time to prettify it right now. |
if operator == 'eq': | ||
query = query.filter(getattr(model, field) == value) | ||
elif operator == 'ne': | ||
query = query.filter(getattr(model, field) == value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should ==
actually be !=
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, nice catch :)
@@ -484,3 +484,36 @@ def makeNodes(nodeList): | |||
node["node"]["name"] for node in expectedNoSort[key]["edges"] | |||
) | |||
|
|||
|
|||
def test_filter(session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this won't get accepted until all of the possible ways to filter are tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the PR could benefit from docstrings and comments.
elif operator == 'lt': | ||
query = query.filter(getattr(model, field) < value) | ||
elif operator == 'gt': | ||
query = query.filter(getattr(model, field) > value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the le
and ge
operators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't have time for it.
+1 on this or a similar implementation |
In the code, you reference a series of aggregations & custom exceptions - what code are you referencing here? Thanks!
|
Hey there is a lot to like here but there's also a lot of problems that should be glaringly obvious. You have obviously never tried your implementation without required fields or you would have run into the first glaring bug in your initializer where you would run into an exception for attempting to iterate over None:
Later on you also use the required fields in a list comp that blows up if it's None Also I'm not sure why but you can't just pass this custom ConnectionField a regular SQLAlchemyObjectType that implements Node like you can with the standard SQLAlchemyConnectionField. Seems bizarre but probably stuff in your field generators does something after the normal constructor creates Edges on the object. (Honestly Graphene in general is one of the worst documented APIs I have ever used and I'm only about a week into it so I have no idea how anything really works yet) And lastly SQLAlchemy adds anonymous BindParameters to models as columns in more complex ORM use cases (or something, see https://docs.sqlalchemy.org/en/13/core/sqlelement.html) which then blows up code as it generates Fields for every column when you introspect the Model class. In these cases, there will be a filter named "'%(4539858784 anon)s" and the code will throw an Exception that something like "Field names must match (the regexp below) but the field name is "'%(4539858784 anon)s". So I had to go and change your create_filter_argument method like so:
|
My organization has been using |
@palisadoes We had the same issue at my former organization and I've always wanted this functionality included in |
Thanks I created a tracking issue that we can use. I'm on the Graphene slack channel (Peter Harrison) if you need a direct contact. @Cito would be a good point of contact to get things started. He commented on this here. |
@sabard @palisados If you could push this forward that would be highly appretiated. This will probably also involve pushing Graphene itself forward. You can try to contact @syrusakbary who is the original author of Graphene and Graphene-SQLAlchemy if you have any questions or want to become maintainer. |
@Cito I've reached out @syrusakbary without response. I took the liberty of adding both of you to our new |
I am closing all old issues&PRs related to this. The discussion will continue in #347 (WIP). A proposal for the implementation of filters is currently being worked on and will be posted there once it is ready. |
Add filters support for connections.
FilterableConnectionField will create InputFilter object with filters for every Connection's Node's property. The date type will be the same as in Node object. Currenly enums and comlex objects (not scalars) are not supported.
I've added this filter operations:
eq
,ne
,like
,lt
,gt
based onsqlalchemy.sql.operators
.Query:
Multiple filters will always work like AND.
This wil generate
select * from pets where name == "Lassie"