Skip to content

Commit 873e477

Browse files
committed
Do not create filter class if create_filters is False
1 parent febdc45 commit 873e477

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

graphene_sqlalchemy/tests/test_filters.py

+27
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,30 @@ async def test_additional_filters(session):
11991199
schema = graphene.Schema(query=Query)
12001200
result = await schema.execute_async(query, context_value={"session": session})
12011201
assert_and_raise_result(result, expected)
1202+
1203+
1204+
@pytest.mark.asyncio
1205+
async def test_do_not_create_filters():
1206+
class WithoutFilters(SQLAlchemyObjectType):
1207+
class Meta:
1208+
abstract = True
1209+
1210+
@classmethod
1211+
def __init_subclass_with_meta__(cls, _meta=None, **options):
1212+
super().__init_subclass_with_meta__(
1213+
_meta=_meta, create_filters=False, **options
1214+
)
1215+
1216+
class PetType(WithoutFilters):
1217+
class Meta:
1218+
model = Pet
1219+
name = "Pet"
1220+
interfaces = (relay.Node,)
1221+
connection_class = Connection
1222+
1223+
class Query(graphene.ObjectType):
1224+
pets = SQLAlchemyConnectionField(PetType.connection)
1225+
1226+
schema = graphene.Schema(query=Query)
1227+
1228+
assert "Filter" not in str(schema)

graphene_sqlalchemy/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def __init_subclass_with_meta__(
513513
_meta.fields = sqla_fields
514514

515515
# Save Generated filter class in Meta Class
516-
if not _meta.filter_class:
516+
if create_filters and not _meta.filter_class:
517517
# Map graphene fields to filters
518518
# TODO we might need to pass the ORMFields containing the SQLAlchemy models
519519
# to the scalar filters here (to generate expressions from the model)

0 commit comments

Comments
 (0)