Reputation: 4319
I am trying to create a GraphQL resolver using Python. I need to select only those columns from the database that the user has requested. I have the requested column names as a list of strings.
How do I query only those columns on that model using SQLAlchemy I tried the following, but that didn't work:
......
query = session.query(MyModel)
query = query.options(Load(MyModel).load_only(*requested_columns))
result = query.all()
Unfortunately this code is not working. Where am I going wrong?
Upvotes: 0
Views: 114
Reputation: 11
At first glance, I don't think you need to call Load(My Model)
because it is implied by query(MyModel)
. Have you tried simply: query.options(load_only(*requested_columns))
?
Upvotes: 1