graphene-sqlalchemy icon indicating copy to clipboard operation
graphene-sqlalchemy copied to clipboard

How to exclude or specifically include fields from having filters auto created

Open adiberk opened this issue 1 year ago • 2 comments

Is there a way we can explicitly list all the fields we want filters created for? Like maybe in the Meta of the sqlalchemy object type?

adiberk avatar Dec 27 '24 14:12 adiberk

Have you got how to do that?

andmaster-one avatar Feb 13 '25 08:02 andmaster-one

@adiberk @andmaster-one if you look in the docstring for ORMField you'll see a param for enabling/disabling filter creation. Modifying an example usage from the same docstring:

            class MyModel(Base):
                id = Column(Integer(), primary_key=True)
                name = Column(String)

            class MyType(SQLAlchemyObjectType):
                class Meta:
                    model = MyModel

                id = ORMField(create_filter=False)       # disable filtering for this field
                name = ORMField(create_filter=True)  # True is default behavior, but we can make it explicit

You can also change the default behavior using the create_filter param on the Meta class

rcb4by avatar Apr 23 '25 12:04 rcb4by