-
Notifications
You must be signed in to change notification settings - Fork 229
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 #357
Add Filters #357
Conversation
…pLoader between queries
…re the enum will get the actula field_name
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #357 +/- ##
==========================================
- Coverage 96.46% 94.74% -1.72%
==========================================
Files 9 10 +1
Lines 933 1333 +400
==========================================
+ Hits 900 1263 +363
- Misses 33 70 +37 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Erik Wrede <[email protected]>
Signed-off-by: Erik Wrede <[email protected]>
Signed-off-by: Erik Wrede <[email protected]>
graphene_sqlalchemy/filters.py
Outdated
abstract = True | ||
|
||
@classmethod | ||
def gt_filter(cls, val: AbstractType) -> bool: |
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 this live on NumberFilter
? Technically strings are ordered as well. Maybe we can call this OrderedFilter
and numbers, strings, etc. can inherit?
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.
Great point, added!
Signed-off-by: Erik Wrede <[email protected]>
Signed-off-by: Erik Wrede <[email protected]>
Signed-off-by: Erik Wrede <[email protected]>
Signed-off-by: Erik Wrede <[email protected]>
graphene_sqlalchemy/filters.py
Outdated
return field == val | ||
|
||
@classmethod | ||
def n_eq_filter(cls, query, field, val: AbstractType) -> Union[Tuple[Query, Any], Any]: |
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.
thoughts on using ne_filter
to stay consistent with graphene-sqlalchemy-filter and sqlalchemy methods?
I'm realizing that |
Why would pagination not work if we're just attaching clauses to the SQLAlchemy query? |
Not so much "this breaks pagination" as "this doesn't provide it, and I've realized I'll need to handle it" - I had been (incorrectly) thinking of this PR as a complete replacement for |
Pagination via offset and limit has to be implemented manually at this point, it could look something like this (going off of my memory): class PaginationConnectionField(graphene_sqlalchemy.SQLAlchemyConnectionField):
def __init__(self, *args, **kwargs):
kwargs["page"] = graphene.Int()
kwargs["itemsPerPage"] = graphene.Int()
super().__init__(*args, **kwargs)
@classmethod
def get_query(cls, *args, **kwargs):
query = SQLAlchemyConnectionField.get_query(*args, **kwargs)
if (
kwargs.get("page", None) is not None
and kwargs.get("itemsPerPage", None) is not None
):
query = query.offset(kwargs["page"] * kwargs["itemsPerPage"])
query = query.limit(kwargs["itemsPerPage"])
return query We already briefly discussed implementing this (or a version of this) in the library, but there is no concrete plan yet. |
We looked into the filters a bit more in depth now and came across this issue/question regarding filtering across relationships: The new implementation uses INNERJOINs for the filters, The graphql syntax of the two filter systems is basically the same. This lead to some initial confusion on our end since we were getting different results when translating our existing queries one to one into the new filter syntax. I prepared an example to showcase the "issue", unfortunately I had no time yet to put it up somewhere but I can showcase it in a call. In the example we have Teams, which have a number of Tasks wich in turn have a number of Todos. Users are then assigned to the Todos (Teams -> Tasks -> Todos -> User). This is the filter, translated 1:1 from the
I would expect to get:
Instead we get:
The "correct" query to get the initially expected result with the "new filters" would look like this:
BUT this one also does not work because each occurence of "tasks" gets a unique alias, so we again end up with the wrong result. The resulting SQL statement:
Should look like this:
The solution here would probably be to use the same alias on each "level" of relationship. This however highlights the question: Which behavior do we want to support? INNERJOINS or EXISTS? We talked about it in my team and came to the conclusion that the grapqhl filter syntax would rather suggest the EXISTS behavior over the INNERJOIN behaviour. Let me know what you think, probably best to jump on a call and discuss it in person (I would be free this coming Monday, May 15th) |
@sabard @erikwrede When do you think you'll be able to merge the filters into the main branch? Is it just the Enum work that is outstanding? I really need to migrate off the old graphene-sqlalchemy-filter. |
@palisadoes just fixed the enum filter case. AFAIK that covers our base scope, so what's missing now is a refactor and cleanup of the code, as it still contains many special cases from previous prototypes that can be generalized to improve code quality and readability. |
thanks for figuring out the issue with enums @erikwrede! @palisadoes i've been pretty swamped this month unfortunately. hope to have more time to work on this in august |
@erikwrede Sorry about missing the meeting. Are there any more outstanding PRs for the filtering? |
Supersedes #356