Registry / database / graphql-skip-limit

graphql-skip-limit

JSON →
library2.3.1jsnpmunverified

A library for constructing GraphQL servers with skip/limit pagination instead of Relay's cursor-based pagination. Version 2.3.1 is the latest stable release, with infrequent updates as it's maintained primarily for Gatsby's data layer. It is a port of graphql-relay-js, using similar APIs but with skip/limit arguments. Requires graphql ^14.1.1 as a peer dependency. Its main differentiator is simplicity for offset-based pagination, but it is deprecated in favor of cursor-based approaches.

npm install graphql-skip-limit
INSTALL
IMPORT
SIG · GRAPHQL-SKIP-LIMIT
G
graphql-skip-limit
databasejavascriptv2.3.1
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.

connectionFromArray
import { connectionFromArray } from 'graphql-skip-limit'
const { connectionFromArray } = require('graphql-skip-limit')
This package is ESM-first; CommonJS require might work with some bundlers but is not guaranteed. Use named import for this function.
connectionArgs
import { connectionArgs } from 'graphql-skip-limit'
import connectionArgs from 'graphql-skip-limit'
connectionArgs is a named export, not a default export. Always use named import syntax.
GraphQLConnectionDef
import type { GraphQLConnectionDef } from 'graphql-skip-limit'
import { GraphQLConnectionDef } from 'graphql-skip-limit'
GraphQLConnectionDef is a TypeScript type and should be imported with `import type` to avoid runtime errors. This is only available in TypeScript environments.

Create a GraphQL schema with skip/limit pagination using connectionFromArray and connectionArgs.

import { connectionArgs, connectionFromArray } from 'graphql-skip-limit'; import { GraphQLObjectType, GraphQLSchema, GraphQLList, GraphQLInt } from 'graphql'; const allFiles = [ { id: '1', name: 'file1' }, { id: '2', name: 'file2' }, { id: '3', name: 'file3' }, { id: '4', name: 'file4' }, { id: '5', name: 'file5' }, ]; const FileType = new GraphQLObjectType({ name: 'File', fields: { id: { type: GraphQLInt }, name: { type: GraphQLString }, }, }); const ConnectionType = new GraphQLObjectType({ name: 'FileConnection', fields: { edges: { type: new GraphQLList(FileEdgeType) }, totalCount: { type: GraphQLInt }, }, }); const queryType = new GraphQLObjectType({ name: 'Query', fields: { allFile: { type: ConnectionType, args: connectionArgs, resolve: (_, { skip, limit }) => connectionFromArray(allFiles, { skip, limit }), }, }, }); export const schema = new GraphQLSchema({ query: queryType });
Debug
Known issues
deprecatedThis package is deprecated. The Gatsby team recommends using cursor-based pagination with graphql-relay instead.
fix
Migrate to graphql-relay and use cursor-based connections.
affects: >=2.0.0
gotchaThe package does not support limit arguments of 0; that will throw an error.
fix
Ensure limit is a positive integer or undefined.
affects: >=1.0.0
gotchaskip and limit arguments are added to the field arguments, but they are not part of the GraphQL spec; clients must be aware of these custom arguments.
fix
Document that your schema uses skip/limit pagination.
affects: >=1.0.0
breakingIn version 2.0.0, the package switched to ES modules and dropped CommonJS support.
fix
Use import syntax instead of require(). If you need CommonJS, stick with version 1.x.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql-skip-limit'
The package is not installed or is not in node_modules.
fix
Run npm install graphql-skip-limit graphql
TypeError: connectionFromArray is not a function
Default import used instead of named import.
fix
Change import to: import { connectionFromArray } from 'graphql-skip-limit'
GraphQLError: Unknown argument "skip" on field "allFile".
The connectionArgs are not spread into the field arguments.
fix
Add ...connectionArgs to the field's args object.
Error: limit must be a positive number
Limit argument set to 0 or negative.
fix
Ensure limit is a positive integer or omit it.
Upgrade
Version history
2.3.1latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for building GraphQL types and schemas
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-skip-limit — npm install graphql-skip-limit · libregistry