Skip to content

Commit

Permalink
Do not create filter class if create_filters is False
Browse files Browse the repository at this point in the history
  • Loading branch information
romeroyonatan committed Jan 28, 2025
1 parent febdc45 commit 873e477
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions graphene_sqlalchemy/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,3 +1199,30 @@ async def test_additional_filters(session):
schema = graphene.Schema(query=Query)
result = await schema.execute_async(query, context_value={"session": session})
assert_and_raise_result(result, expected)


@pytest.mark.asyncio
async def test_do_not_create_filters():
class WithoutFilters(SQLAlchemyObjectType):
class Meta:
abstract = True

@classmethod
def __init_subclass_with_meta__(cls, _meta=None, **options):
super().__init_subclass_with_meta__(
_meta=_meta, create_filters=False, **options
)

class PetType(WithoutFilters):
class Meta:
model = Pet
name = "Pet"
interfaces = (relay.Node,)
connection_class = Connection

class Query(graphene.ObjectType):
pets = SQLAlchemyConnectionField(PetType.connection)

schema = graphene.Schema(query=Query)

assert "Filter" not in str(schema)
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def __init_subclass_with_meta__(
_meta.fields = sqla_fields

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

0 comments on commit 873e477

Please sign in to comment.