-
Notifications
You must be signed in to change notification settings - Fork 227
add filters alias support #378
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import re | ||
from typing import Any, Dict, List, Tuple, Type, TypeVar, Union | ||
|
||
from graphql import Undefined | ||
from sqlalchemy import and_, not_, or_ | ||
from sqlalchemy.orm import Query, aliased # , selectinload | ||
|
||
|
@@ -35,6 +36,33 @@ def _get_functions_by_regex( | |
return matching_functions | ||
|
||
|
||
class SQLAlchemyFilterInputField(graphene.InputField): | ||
def __init__( | ||
self, | ||
type_, | ||
model_attr, | ||
name=None, | ||
default_value=Undefined, | ||
deprecation_reason=None, | ||
description=None, | ||
required=False, | ||
_creation_counter=None, | ||
**extra_args, | ||
): | ||
super(SQLAlchemyFilterInputField, self).__init__( | ||
type_, | ||
name, | ||
default_value, | ||
deprecation_reason, | ||
description, | ||
required, | ||
_creation_counter, | ||
**extra_args, | ||
) | ||
|
||
self.model_attr = model_attr | ||
|
||
|
||
class BaseTypeFilter(graphene.InputObjectType): | ||
@classmethod | ||
def __init_subclass_with_meta__( | ||
|
@@ -141,7 +169,8 @@ def execute_filters( | |
# Check with a profiler is required to determine necessity | ||
input_field = cls._meta.fields[field] | ||
if isinstance(input_field, graphene.Dynamic): | ||
field_filter_type = input_field.get_type().type | ||
input_field = input_field.get_type() | ||
field_filter_type = input_field.type | ||
else: | ||
field_filter_type = cls._meta.fields[field].type | ||
# raise Exception | ||
|
@@ -158,7 +187,9 @@ def execute_filters( | |
) | ||
clauses.extend(_clauses) | ||
else: | ||
model_field = getattr(model, field) | ||
model_field = getattr( | ||
model, input_field.model_attr | ||
) # getattr(model, field) | ||
Comment on lines
+190
to
+192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for |
||
if issubclass(field_filter_type, BaseTypeFilter): | ||
# Get the model to join on the Filter Query | ||
joined_model = field_filter_type._meta.model | ||
|
@@ -193,6 +224,10 @@ def execute_filters( | |
) | ||
clauses.extend(_clauses) | ||
elif issubclass(field_filter_type, FieldFilter): | ||
print("got", model_field) | ||
print(repr(model_field)) | ||
print(model_field == 1) | ||
print("with input", field_filters) | ||
Comment on lines
+227
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove in |
||
query, _clauses = field_filter_type.execute_filters( | ||
query, model_field, field_filters | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.