Registry / database / graphql-directive-pagination

graphql-directive-pagination

JSON →
library1.0.15jsnpmunverified

A GraphQL directive that transforms fields to use SQL-style LIMIT/OFFSET pagination. Current version 1.0.15, stable maintenance. Unlike Relay's @connection, this uses limit/offset for natural integration with MySQL/PostgreSQL. Provides schema transformation, directive definition, and resolver helpers. Requires peer dependency graphql ^16.7.1. Ships TypeScript types.

npm install graphql-directive-pagination
INSTALL
IMPORT
SIG · GRAPHQL-DIRECTIVE-
G
graphql-directive-pagination
databasejavascriptv1.0.15
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.

default
import paginationDirective from 'graphql-directive-pagination'
const paginationDirective = require('graphql-directive-pagination')
Default export is a factory function. The package is ESM-only; CommonJS require will fail.
paginationResolver
const { paginationResolver } = paginationDirective('pagination', { timezone: 'utc' })
import { paginationResolver } from 'graphql-directive-pagination'
paginationResolver is not a named export from the package; it's destructured from the result of calling the default export factory function.
paginationDirectiveTransform
const { paginationDirectiveTransform } = paginationDirective('pagination', { timezone: 'utc' })
const { paginationDirectiveTransform } = require('graphql-directive-pagination')
Must call the default export with directive name and options to obtain the transform.
paginationDirectiveTypeDefs
const { paginationDirectiveTypeDefs } = paginationDirective('pagination', { timezone: 'utc' })
import { paginationDirectiveTypeDefs } from 'graphql-directive-pagination'
Type definitions are also returned from the factory, not directly exported.

Shows how to set up the @pagination directive, apply schema transform, and use the generated Pagination types.

import paginationDirective from 'graphql-directive-pagination'; import { makeExecutableSchema } from '@graphql-tools/schema'; const { paginationDirectiveTransform, paginationDirectiveTypeDefs } = paginationDirective('pagination', { timezone: 'utc' }); const typeDefs = ` directive @pagination on FIELD_DEFINITION type User { userId: Int posts: [Post!]! @pagination } type Post { postId: Int } type Query { user: User } `; const resolvers = {}; let schema = makeExecutableSchema({ typeDefs: [typeDefs, paginationDirectiveTypeDefs], resolvers, }); schema = paginationDirectiveTransform(schema, resolvers); export default schema;
Debug
Known issues
gotchaThe factory function must be called with a directive name and options object before destructuring the transform, resolver, and typeDefs. Using named imports directly from the package will result in undefined.
fix
Call default export: const { paginationResolver, paginationDirectiveTransform, paginationDirectiveTypeDefs } = paginationDirective('pagination', { timezone: 'utc' });
affects: >=1.0.0
gotchaThe @pagination directive overwrites the return type of tagged fields with the Pagination connection type. Original type annotations are ignored.
fix
Do not specify a return type for @pagination fields; the directive will replace it with Pagination<OriginalType>.
affects: >=1.0.0
gotchaThe directive requires peer dependency graphql ^16.7.1. Using older versions of graphql may cause schema transformation errors.
fix
Ensure graphql version is 16.7.1 or later in your package.json.
affects: >=1.0.0
gotchaSchema transformation must be applied after makeExecutableSchema and requires passing the resolvers object as second argument to paginationDirectiveTransform. Omitting resolvers will break pagination.
fix
Always call schema = paginationDirectiveTransform(schema, resolvers);
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql-directive-pagination'
Package not installed or ESM-only and using CommonJS require.
fix
Run `npm install graphql-directive-pagination` and ensure your project uses ES modules (e.g., `"type": "module"` in package.json or use .mjs extension).
TypeError: paginationDirective is not a function
Incorrect import: trying to use named import directly from package instead of calling default export factory.
fix
Change to: import paginationDirective from 'graphql-directive-pagination'; const { paginationTransform } = paginationDirective('pagination');
Error: Schema must contain unique root types. Type "Pagination" already exists.
Multiple schemas in the same GraphQL project using this package cause conflicting type definitions.
fix
Use unique directive names per schema, or ensure the Pagination types are only added once by reusing the same transform.
Validation Error: Field "posts" of type "Pagination" must have a selection of subfields.
Client query is not selecting nested fields of the Pagination type (e.g., items, pageInfo).
fix
Update query to include fields like `posts { items { ... } pageInfo { hasMore } }`.
Upgrade
Version history
1.0.15latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency required for GraphQL schema manipulation and type definitions.
Agent activity
4 hits · last 30 days
node
4
Resources
graphql-directive-pagination — npm install graphql-directive-pagination · libregistry