I am currently using graphene-sqlalchemy-filter, which is a package built to integrate SQLAlchemy and Graphene. However, I am currently facing some issues with using it. I want to be able to retrieve the data based on the query from graphQL, and from there, before returning the fetched data, I would like to manipulate it by grouping the queryset based on a field and counting the sum or count per group. Is there any way I can achieve this?
Here is my code
class Tuition(db.Model):
__tablename__ = 'tuition'
id = db.Column(db.Integer, primary_key=True)
marks = db.Column(db.Integer)
student_name = db.Column(db.String(256))
class_name = db.Column(db.String(256))
# Filter
class TuitionFilter(FilterSet):
class Meta:
model = Tuition
fields = {
'student_name': ['eq', 'ne', 'in', 'ilike'],
'class_name': ['eq', 'ne', 'in', 'ilike'],
}
# Schema Objects
class TuitionObject(SQLAlchemyObjectType):
class Meta:
model = Tuition
interfaces = (graphene.relay.Node, )
class Query(graphene.ObjectType):
node = graphene.relay.Node.Field()
all_tuitions = FilterableConnectionField(TuitionObject, filters=TuitionFilter())
def resolve_all_tuitions(self, info):
query = TuitionObject.get_query(info) # SQLAlchemy query
return query.all()
schema = graphene.Schema(query=Query)
I am new to this, and I am not sure where I am supposed to manipulate the data, and how to manipulate it using SQLAlchemy as well, I tried googling this but to no avail, if there are any links that you guys can link me to, that would be great, or if you guys have the solution for this, that would be perfect. Thank you!