Pagination
The pagination plugin generates Relay-style connection types (Connection, Edge, PageInfo) for the types you list. You define the input shape; the plugin writes the SDL.
Installation
- yarn
- npm
- pnpm
- bun
yarn add @baeta/plugin-pagination -D
npm install @baeta/plugin-pagination -D
pnpm add @baeta/plugin-pagination -D
bun add @baeta/plugin-pagination -D
Configuration
In baeta.ts:
import { defineConfig } from "@baeta/cli";
import { paginationPlugin } from "@baeta/plugin-pagination";
export default defineConfig({
plugins: [
paginationPlugin({
// Customize the PageInfo type with additional fields
pageInfoFields: ["hasMorePages: Boolean!"],
// Make the node field nullable in all connections
nullableNode: true,
// Configure pagination for specific types
types: {
// Simple configuration - generate default connection types
User: true,
UserPhoto: true,
// Advanced configuration with custom fields
UserCustom: {
nodeType: "User", // Use a different type for nodes
cursorType: "UUID!", // Specify cursor type (default: ID!)
connectionFields: ["totalCount: Int!"], // Add fields to connection type
edgeFields: ["hasPhotos: Boolean!"], // Add fields to edge type
},
},
}),
],
});
For the full configuration interface, see the PaginationOptions API reference.
Usage
Declare your pagination input and reference the generated connection type:
input UserPhotoPage {
cursor: ID
limit: Int! @validInt(min: 1, max: 50)
}
extend type User {
photosConnection(page: UserPhotoPage!): UserPhotoConnection
}
For each registered type, the plugin generates:
<Type>Connection<Type>Edge- The shared
PageInfo(plus any custom fields you added) - The TypeScript types your resolvers need
tip
How you fetch the actual page depends on your data layer. The relay-pagination example shows the Prisma flavor end-to-end.