Open SBelkaid opened 4 years ago
Not very easy but most likely possible, I think.
You need to override some parts of FilterSet
:
_generate_filter_fields
to create a GraphQL schema in a different way https://github.com/art1415926535/graphene-sqlalchemy-filter/blob/f6c2123d4f19c99e2d48c342088f9ec7f09cb667/graphene_sqlalchemy_filter/filters.py#L571_translate_filter
to implement a new method for getting the model field name and function key (FILTER_FUNCTIONS
) https://github.com/art1415926535/graphene-sqlalchemy-filter/blob/f6c2123d4f19c99e2d48c342088f9ec7f09cb667/graphene_sqlalchemy_filter/filters.py#L724This is an interesting task. It is possible that this module can have several types of GraphQL schema.
Pros:
Cons:
... filters: {username: {ne: "admin", in: ["user1", "user2"]}} ...
Example:
class UserFilter(FilterSet):
is_admin = graphene.Boolean()
class Meta:
model = User
fields = {'username': ['ne', 'in']}
@staticmethod
def is_admin_filter(info, query, value):
...
{
allUsers(filters: {username: {ne: "admin", in: ["user1", "user2"]}, is_admin: true}) {
edges { node { id } }
}
}
Is it possible to change the syntax of the filter to:
filters: {[column_name]: {[operator]: [value_name]}}
?