Sorting not working
See original GitHub issuedef int_timestamp():
return int(time.time())
class UserActivity(TimestampedModel, Base, DictModel):
__tablename__ = 'user_activities'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("user.id", ondelete='SET NULL'))
username = Column(String())
timestamp = Column(Integer, default=int_timestamp)
class UserActivityModel(SQLAlchemyObjectType):
class Meta:
model = UserActivity
only_fields = ()
exclude_fields = ('user_id',)
interfaces = (relay.Node,)
class Query(ObjectType):
list_user_activities = SQLAlchemyConnectionField(
type=UserActivityModel,
sort=UserActivityModel.sort_argument()
)
def resolve_list_user_activities(self, info: ResolveInfo, sort=None, first=None, after=None, **kwargs):
# Build the query
query = UserActivityModel.get_query(info)
query = query.filter_by(**kwargs)
return query.all()
graphql_app = GraphQLApp(schema=Schema(query=Query))
My query in GQL:
query {
listUserActivities(first: 3, sort: TIMESTAMP_DESC) {
edges {
node {
username
timestamp
}
}
}
}
The result:
{
"data": {
"listUserActivities": {
"edges": [
{
"node": {
"username": "adis@ulap.co",
"timestamp": 1644321703
}
},
{
"node": {
"username": "adis@ulap.co",
"timestamp": 1644334763
}
},
{
"node": {
"username": "adis@ulap.co",
"timestamp": 1644344156
}
}
]
}
}
}
What’s really strange is the first
argument appears to apply a limit to the result, but the sort argument appears to just be swallowed and unused. Switching to TIMESTAMP_ASC
produces the same result. I’m trying to find examples online to help with this. What am I doing wrong or what can i try here?
I’m using 2.3.0
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Sort not working the way its supposed to. - Microsoft Community
If it looks like the data did not sort properly, refer to the following list of possible solutions: ... Make sure no hidden...
Read more >My excel spreadsheet won't sort/alphabetize properly
The most common reason for data not sorting correctly is due to the leading space ahead of the text. Many people ...
Read more >Fixing Sort Problems | Sorting Data in Microsoft Excel 2016
Fixing Sort Problems · Make sure no hidden rows or columns exist. · Use a single row for headers. · If the headers...
Read more >Why Won't My Spreadsheet Sort? - Small Business - Chron.com
File or application corruption always can produce unexpected results even in routine software operations such as a worksheet data sort. If verifying your...
Read more >How to Sort in Excel Rows or Columns Avoid Sort Problems
Sort in a Custom Order · Select one cell in the column you want to sort. · Press Ctrl + A, to select...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Great to hear, I’m closing this issue now. If further problems occur, feel free to reply. Since I saw the attempt to apply filtering to your queries, I suggest looking into this library, before you put in too much duplicate work into providing basic custom filters: https://github.com/art1415926535/graphene-sqlalchemy-filter
It’s currently inactive but provides a lot of filtering functionality for graphene-sqlalchemy 2.0. For graphene-sqlalchemy 3, we are currently working on a custom implementation!
That worked! Thank you so much.