feat: Unified Paginator[T] API with Fetcher pattern and functional options#16
Merged
josemarluedke merged 1 commit intomainfrom Dec 16, 2025
Merged
Conversation
…tions BREAKING CHANGES: This release unifies all three pagination strategies (offset, cursor, quotafill) around a common Paginator[T] interface with the Fetcher pattern. ## API Changes 1. **Unified Paginator[T] Interface** - All strategies implement Paginate(ctx, args, opts...) method - Consistent API across offset, cursor, and quotafill 2. **Fetcher Pattern** - All constructors take Fetcher[T] as first parameter - offset.New(fetcher) - cursor.New(fetcher, schema) - quotafill.New(fetcher, filter, schema, opts...) 3. **Functional Options for Page Size** - Page size limits moved from constructors to Paginate() options - paging.WithMaxSize(100) - cap maximum page size - paging.WithDefaultSize(25) - set default when First is nil 4. **Page[T] Result Type** - Paginate() returns *Page[T] with Nodes, PageInfo, and Metadata - Metadata includes strategy name, timing, and strategy-specific info - Offset stored in Metadata.Offset for accurate cursor generation 5. **Simplified BuildConnection** - offset.BuildConnection(page, transform) - cursor.BuildConnection(page, schema, args, transform) - quotafill.BuildConnection(page, schema, args, transform) ## Removed/Deprecated - offset: QueryMods() method removed (use Paginate() instead) - cursor: BuildFetchParams() deprecated (use Paginate() instead) - quotafill: WithPageConfig() option removed (use Paginate() options) ## Benefits - Consistent API across all three strategies - Reusable fetchers across multiple requests - Per-request page size configuration - Rich metadata for observability - Easier testing with mockable Fetcher[T] - Simpler strategy switching ## Testing - All 204 tests passing across all packages - Integration tests updated for new API - Security tests updated and passing See MIGRATION.md for detailed migration guide from v0.3.0 to v2.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR unifies all three pagination strategies (offset, cursor, quotafill) around a common
Paginator[T]interface with the Fetcher pattern and functional options. This is a major API improvement that makes the library more consistent, flexible, and easier to use.Breaking Changes
1. Unified Paginator[T] Interface
All strategies now implement the same interface:
2. Fetcher Pattern
All constructors now take
Fetcher[T]as the first parameter:offset.New(fetcher)cursor.New(fetcher, schema)quotafill.New(fetcher, filter, schema, opts...)3. Functional Options
Page size limits moved from constructors to
Paginate()options:paging.WithMaxSize(100)- cap maximum page sizepaging.WithDefaultSize(25)- set default when First is nil4. Page[T] Result Type
Paginate()returns*Page[T]with:Nodes- the actual itemsPageInfo- pagination metadataMetadata- observability data (strategy, timing, offset, etc.)5. Simplified BuildConnection
All BuildConnection functions now take the
*Page[T]result:offset.BuildConnection(page, transform)cursor.BuildConnection(page, schema, args, transform)quotafill.BuildConnection(page, schema, args, transform)Removed/Deprecated
QueryMods()method removed (usePaginate()instead)BuildFetchParams()deprecated (usePaginate()instead)WithPageConfig()option removed (usePaginate()options)Benefits
✨ Consistent API - All three strategies work the same way
✨ Reusable fetchers - Define once, use across multiple requests
✨ Per-request configuration - Page size limits via functional options
✨ Rich metadata - Observability data for monitoring and debugging
✨ Easier testing - Mockable
Fetcher[T]interface✨ Simpler strategy switching - Change 3 lines of code to switch strategies
Migration Example
Before (v0.3.0)
After (v2.0)
Testing
✅ 204 tests passing across all packages:
Documentation
Files Changed
Core API:
interfaces.go- AddedOffsetto Metadata, updated Paginator[T] interfacepage_args.go- Added PaginateOption types and functional optionsOffset Strategy:
offset/paginator.go- Implemented Paginator[T], added Fetcher patternoffset/paginator_test.go- Updated tests for new APICursor Strategy:
cursor/paginator.go- Implemented Paginator[T], added Fetcher patterncursor/paginator_test.go- Updated tests for new APIQuotafill Strategy:
quotafill/quotafill.go- Updated to use PaginateOptionTests:
connection_test.go- Updated BuildConnection teststests/offset_integration_test.go- Rewritten for new APItests/cursor_integration_test.go- Updated for new APItests/security_test.go- Updated for new APIDocumentation:
README.md- Complete rewrite with unified API examplesMIGRATION.md- Detailed v0.3.0 → v2.0 migration guideReviewers
This is a major breaking change. Please review:
See MIGRATION.md for the complete migration guide.