Skip to content

Selecting items by date range in API requires sort=top or sort=user #2433

@ed-kung

Description

@ed-kung

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Trying to retrieve items from a date range using when, to, from only works if sort is equal to "top" or "user".

You can see this starting on line 394 in api/resolvers/item.js. whenClause/whenRange are only added to the query if sort is 'user' or 'top'

Screenshots

No response

Steps To Reproduce

This is the query I ran:

query GetItems($sort: String, $when: String, $from: String, $to: String, $limit: Limit) {
    items(sort: $sort, when: $when, from: $from, to: $to, limit: $limit) {
        items {
            id
            createdAt
            title
            text
            user {
                id
                name
            }
            parentId
            sats
            upvotes
            ncomments
            subName
        }
    }
}

with variables:

{'sort': '', 'when': 'custom', 'from': '1751353200000', 'to': '1754031599999', 'limit': 100}

You will retrieve items outside the date range (which in this case is 2025-07-01 to 2025-07-31).

But if you do 'sort': 'top', you'll get items in the correct date range

Expected behavior

Date filter should not depend on sort type

Logs

No response

Device information

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions