graphql-python/graphene-sqlalchemy

Post processing relationship result with SQLAlchemyConnectionField

ego opened this issue · 3 comments

ego commented

Hi there!

Maybe someone asked this question, sorry.
But how to do post processing or override relationship result with SQLAlchemyConnectionField?

https://github.com/graphql-python/graphene-sqlalchemy/blob/master/examples/flask_sqlalchemy/schema.py#L36

class Query(graphene.ObjectType):
    ....
   all_departments = SQLAlchemyConnectionField(Department.connection, sort=None)

   def resolve_all_departments(root, info, *args, **kwargs):
         # Like result = super().resolve_all_departments()  ?
         # Do post processing result / add some additional filters to query.
         # return result

Hey there, for filtering in graphene-sqlalchemy<3.0, take a look at graphene-sqlalchemy-filter or look in the closed and open issues, there are plenty of suggestions, you can pick the one that fits your needs best.
One way you can get the query of an SQLAlchemyConnectionField is this:

class Query(graphene.ObjectType):

   all_departments = SQLAlchemyConnectionField(Department.connection, sort=None)

   def resolve_all_departments(parent, info, sort=None, **kwargs):
           query = SQLALchemyConnectionField.get_query(Department._meta.model, info, sort)
          #apply additional modificaitons to your query
          return query.all()
ego commented

Thanks for your time and reply.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.