Registry / database / graphql-compose-pagination

graphql-compose-pagination

JSON →
library8.3.0jsnpmunverified

Plugin for graphql-compose that adds a pagination resolver to ObjectTypeComposer. Current version 8.3.0 supports graphql-compose ^7.15.0, ^8.0.0, or ^9.0.0. It provides a pre-built pagination resolver (based on page numbers/perPage) that wraps existing findMany and count resolvers. Key differentiator: integrates directly with graphql-compose's resolver system, avoiding manual wiring of pagination logic. Includes TypeScript definitions. Release cadence is moderate, with breaking changes aligning with graphql-compose major versions.

npm install graphql-compose-pagination
INSTALL
IMPORT
SIG · GRAPHQL-COMPOSE-PA
G
graphql-compose-pagination
databasejavascriptv8.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

preparePaginationResolver
import { preparePaginationResolver } from 'graphql-compose-pagination'
const preparePaginationResolver = require('graphql-compose-pagination')
Main export is a named function. CommonJS require works but matches the default export of an object with preparePaginationResolver property; prefer ESM import.
PaginationInfoType
import { PaginationInfoType } from 'graphql-compose-pagination'
import PaginationInfoType from 'graphql-compose-pagination'
PaginationInfoType is a named export, not default. Available since v8.
ResolverResolveParams
import { ResolverResolveParams } from 'graphql-compose'
import { ResolverResolveParams } from 'graphql-compose-pagination'
ResolverResolveParams is a type from graphql-compose, not from this package. Common mistake when trying to type the resolve params.
PaginationResolverOpts
import { PaginationResolverOpts } from 'graphql-compose-pagination'
const { PaginationResolverOpts } = require('graphql-compose-pagination')
TypeScript type, not a runtime value. Only import when using TypeScript.

Shows how to import and use preparePaginationResolver to add a paginated resolver (with page/perPage args) to an ObjectTypeComposer.

import { preparePaginationResolver } from 'graphql-compose-pagination'; import { schemaComposer } from 'graphql-compose'; // Assuming you have UserTC with findMany and count resolvers const UserTC = schemaComposer.createObjectTC({ name: 'User', fields: { id: 'Int!', name: 'String!', age: 'Int!' }, }); // Mock findManyResolver (returns list) and countResolver (returns count) const findManyResolver = schemaComposer.createResolver({ name: 'findMany', type: [UserTC], resolve: async () => [{ id: 1, name: 'John', age: 25 }], }); const countResolver = schemaComposer.createResolver({ name: 'count', type: 'Int', resolve: async () => 1, }); // Add pagination resolver to UserTC UserTC.addResolver( preparePaginationResolver(UserTC, { findManyResolver, countResolver, perPage: 10, name: 'paginatedUsers', }) ); const schema = schemaComposer.buildSchema(); // Now query 'paginatedUsers' with arguments: page, perPage, filter, sort
Debug
Known issues
breakingVersion 8.0.0 dropped support for graphql-compose v6. Ensure your project uses graphql-compose ^7.15.0 or later.
fix
Upgrade graphql-compose to ^7.15.0, ^8.0.0, or ^9.0.0.
affects: >=8.0.0
breakingIn v8, the return type of the pagination resolver changed: 'count' field is now non-nullable Int! instead of Int. Existing queries relying on null count may break.
fix
Update client queries to expect count as non-nullable integer.
affects: >=8.0.0
deprecatedThe previous default export (e.g., import pagination from 'graphql-compose-pagination') is deprecated in v8. Use named imports instead.
fix
Change to import { preparePaginationResolver } from 'graphql-compose-pagination'.
affects: >=8.0.0
gotchaBoth 'findManyResolver' and 'countResolver' must be provided. Missing one will cause a runtime error.
fix
Always pass both findManyResolver (returning array) and countResolver (returning integer).
affects: >=8.0.0
gotchaThe 'findManyResolver' must accept 'filter', 'sort', 'skip', 'limit' arguments. If your resolver ignores 'skip' and 'limit', pagination will not work correctly.
fix
Ensure your findManyResolver respects 'skip' and 'limit' (or converts them to your database's offset/limit).
affects: >=8.0.0
gotchaWhen using with TypeScript, ensure you import types from 'graphql-compose' for ResolverResolveParams, etc., not from this package.
fix
Import like: import { ResolverResolveParams } from 'graphql-compose'.
affects: >=8.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql-compose-pagination'
Package not installed or missing from node_modules.
fix
Run: npm install graphql-compose-pagination
TypeError: preparePaginationResolver is not a function
Using default import instead of named import (e.g., import prepPagination from 'graphql-compose-pagination').
fix
Change to: import { preparePaginationResolver } from 'graphql-compose-pagination'
GraphQLError: Field 'pagination' is not defined on type 'Query'
The pagination resolver was not added to any type in the schema.
fix
Call UserTC.addResolver() with the result of preparePaginationResolver() before building schema.
Error: Cannot read property 'resolve' of undefined
Missing findManyResolver or countResolver in options object.
fix
Ensure both 'findManyResolver' and 'countResolver' are passed to preparePaginationResolver.
Upgrade
Version history
8.3.0latest on npm
Audit
Dependencies
graphql-composerequiredPeer dependency; required to use this plugin.
Agent activity
12 hits · last 30 days
node
10
Resources
graphql-compose-pagination — npm install graphql-compose-pagination · libregistry