Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Provide $top as a synonym for $first in REST #2474

Open
JerryNixon opened this issue Nov 25, 2024 · 1 comment
Open

[Enhancement]: Provide $top as a synonym for $first in REST #2474

JerryNixon opened this issue Nov 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@JerryNixon
Copy link
Contributor

JerryNixon commented Nov 25, 2024

Proposal

Provide $top as a synonym for $first in REST with no other behavioral change.

Reasons for this minor change:

Alignment with data source syntax is only a coincidence. Intuitive use and OData alignment are the primary drivers.

Database Keyword Used Example Syntax
Cosmos DB TOP SELECT TOP 5 Id, Name FROM Users
SQL Server TOP SELECT TOP 5 Id, Name FROM Users
MySQL LIMIT SELECT Id, Name FROM Users LIMIT 5
PostgreSQL LIMIT SELECT Id, Name FROM Users LIMIT 5

Why is this proposal specific to REST?

In GraphQL, first is more common than top. first is typically used in pagination, particularly with Relay-style connections. It specifies the number of items to retrieve starting from the current cursor. top is not standard in GraphQL queries. If you encounter it, it’s likely specific to a custom schema.

query {
  users(first: 5) {
    edges {
      node {
        id
        name
      }
    }
  }
}

Current behavior

URL QUERY
https://server/api/User?
$select=Id,Name
SELECT Id, Name
FROM User
&$first=10 SELECT TOP 10 Id, Name
FROM User

Proposed behavior

URL QUERY
https://server/api/User?
$select=Id,Name
SELECT Id, Name
FROM User
&$first=10 SELECT TOP 10 Id, Name
FROM User
&$top=10 SELECT TOP 10 Id, Name
FROM User

// end

@JerryNixon JerryNixon added the enhancement New feature or request label Nov 25, 2024
@JerryNixon
Copy link
Contributor Author

Related #2344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant