-
-
Notifications
You must be signed in to change notification settings - Fork 119
feat(openapi): add ordering and pagination to RPC findMany endpoints #2207
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
Conversation
Add orderBy, cursor, take, and skip parameters to findMany operations in the RPC-style OpenAPI generator. This brings parity with the REST API generator and enables clients to: - Sort results using orderBy (single or multiple fields) - Paginate using take/skip (offset-based) - Use cursor-based pagination Also added runtime tests to verify the functionality works correctly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
📝 WalkthroughWalkthroughThe changes refactor the logic for determining the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RPC API
participant Database
Client->>RPC API: POST /post/findMany with { orderBy, take, skip, cursor }
RPC API->>Database: Query posts with provided pagination and ordering
Database-->>RPC API: Return paginated, ordered posts
RPC API-->>Client: Respond with posts data
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/server/tests/api/rpc.test.ts (1)
134-249
: Excellent comprehensive test coverage for pagination and ordering features.The test is well-structured with proper setup, execution, and cleanup. It comprehensively covers:
- Single field ordering (title asc, viewCount desc)
- Multiple field ordering
- Take/skip pagination
- Combined ordering and pagination
- Cursor-based pagination
The test data design with distinct titles and view counts makes verification straightforward.
Consider adding one more assertion to verify the complete ordering in the multiple orderBy test:
// Test multiple orderBy r = await handleRequest({ method: 'get', path: '/post/findMany', query: { q: JSON.stringify({ orderBy: [{ published: 'desc' }, { title: 'asc' }] }) }, prisma, }); expect(r.status).toBe(200); expect(r.data[0].title).toBe('A Post'); +expect(r.data.map(post => post.title)).toEqual(['A Post', 'B Post', 'C Post', 'D Post', 'E Post']);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (6)
packages/plugins/openapi/tests/baseline/rpc-3.0.0-omit.baseline.yaml
is excluded by!**/*.yaml
packages/plugins/openapi/tests/baseline/rpc-3.0.0.baseline.yaml
is excluded by!**/*.yaml
packages/plugins/openapi/tests/baseline/rpc-3.1.0-omit.baseline.yaml
is excluded by!**/*.yaml
packages/plugins/openapi/tests/baseline/rpc-3.1.0.baseline.yaml
is excluded by!**/*.yaml
packages/plugins/openapi/tests/baseline/rpc-type-coverage-3.0.0.baseline.yaml
is excluded by!**/*.yaml
packages/plugins/openapi/tests/baseline/rpc-type-coverage-3.1.0.baseline.yaml
is excluded by!**/*.yaml
📒 Files selected for processing (2)
packages/plugins/openapi/src/rpc-generator.ts
(2 hunks)packages/server/tests/api/rpc.test.ts
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/plugins/openapi/src/rpc-generator.ts (1)
packages/runtime/src/local-helpers/upper-case-first.ts (1)
upperCaseFirst
(1-3)
🔇 Additional comments (2)
packages/server/tests/api/rpc.test.ts (1)
283-285
: Good addition of test cleanup for better isolation.Adding cleanup at the start of the policy violation test ensures consistent test behavior regardless of execution order.
packages/plugins/openapi/src/rpc-generator.ts (1)
279-285
: Perfect implementation of pagination and ordering parameters.The addition of
orderBy
,cursor
,take
, andskip
parameters to the findMany operation correctly implements:
- Single and multiple field ordering via
oneOf
schema- Cursor-based pagination with proper
WhereUniqueInput
type- Offset-based pagination with integer
take
/skip
parameters- All parameters appropriately optional
This implementation aligns with Prisma's native API and fulfills the PR objectives.
My bad, did not catch the dev branch |
No worries. Github is missing a feature for setting a default branch for PR ... |
This PR adds support for ordering and pagination parameters to
findMany
operations in the RPC-style OpenAPI generator.Changes
orderBy
,cursor
,take
, andskip
parameters tofindMany
operation definitions inrpc-generator.ts
Features Added
orderBy
(supports single field or array of fields)take
andskip
parameterscursor
parameter for efficient paginationWhy This Change?
The RPC handler already supported these parameters at runtime (it passes them through to Prisma), but they weren't documented in the OpenAPI specification. This made it difficult for API consumers to discover these features. This change brings parity with the REST API generator.
Testing
pagination and ordering
that verifies:🤖 Generated with Claude Code