Registry / devops / nestjs-graphql-connection

nestjs-graphql-connection

JSON →
library1.1.1jsnpmunverified

Relay-style pagination (Cursor-based) for NestJS GraphQL servers. Current stable version 1.1.1. Provides factory functions `createEdgeType` and `createConnectionType` to build Relay Connection/Edge types, plus a `ConnectionBuilder` class for cursor encoding/decoding and pagination logic. Supports NestJS versions 7–11 and @nestjs/graphql 7–13. Includes TypeScript definitions. Differentiates from alternatives by being NestJS-native, using decorators, and integrating with the NestJS GraphQL module's code-first approach.

npm install nestjs-graphql-connection
INSTALL
IMPORT
SIG · NESTJS-GRAPHQL-CON
N
nestjs-graphql-connection
devopsjavascriptv1.1.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.

createEdgeType
import { createEdgeType } from 'nestjs-graphql-connection'
const createEdgeType = require('nestjs-graphql-connection').createEdgeType
ESM-only; named export.
createConnectionType
import { createConnectionType } from 'nestjs-graphql-connection'
import createConnectionType from 'nestjs-graphql-connection'
No default export. Use named import.
ConnectionArgs
import { ConnectionArgs } from 'nestjs-graphql-connection'
import { ConnectionArgs as Args } from 'nestjs-graphql-connection'
Class, not a type. Use as base class with extends.
ConnectionBuilder
import { ConnectionBuilder } from 'nestjs-graphql-connection'
Generic abstract class. Must implement createConnection, createEdge, createCursor, decodeCursor.
Cursor
import { Cursor } from 'nestjs-graphql-connection'
Class to create and decode cursors. Pass parameters in constructor.

Defines a PersonEdge, PersonConnection, ConnectionArgs subclass, and a ConnectionBuilder for Relay-style pagination.

// person.edge.ts import { ObjectType } from '@nestjs/graphql'; import { createEdgeType } from 'nestjs-graphql-connection'; import { Person } from './person.entity'; @ObjectType() export class PersonEdge extends createEdgeType(Person) {} // person.connection.ts import { ObjectType } from '@nestjs/graphql'; import { createConnectionType } from 'nestjs-graphql-connection'; import { PersonEdge } from './person.edge'; @ObjectType() export class PersonConnection extends createConnectionType(PersonEdge) {} // person.args.ts import { ArgsType, Field, ID } from '@nestjs/graphql'; import { ConnectionArgs } from 'nestjs-graphql-connection'; @ArgsType() export class PersonConnectionArgs extends ConnectionArgs { @Field(type => ID, { nullable: true }) public personId?: string; } // person.builder.ts import { ConnectionBuilder, Cursor, EdgeInputWithCursor, PageInfo, } from 'nestjs-graphql-connection'; import { PersonConnection } from './person.connection'; import { PersonConnectionArgs } from './person.args'; import { PersonEdge } from './person.edge'; import { Person } from './person.entity'; export type PersonCursorParams = { id: string }; export type PersonCursor = Cursor<PersonCursorParams>; export class PersonConnectionBuilder extends ConnectionBuilder< PersonConnection, PersonConnectionArgs, PersonEdge, Person, PersonCursor > { public createConnection(fields: { edges: PersonEdge[]; pageInfo: PageInfo }): PersonConnection { return new PersonConnection(fields); } public createEdge(fields: EdgeInputWithCursor<PersonEdge>): PersonEdge { return new PersonEdge(fields); } public createCursor(node: Person): PersonCursor { return new Cursor({ id: node.id }); } public decodeCursor(encodedString: string): PersonCursor { const decoded = Buffer.from(encodedString, 'base64').toString('utf-8'); const params: PersonCursorParams = JSON.parse(decoded); return new Cursor(params); } }
Debug
Known issues
gotchaConnectionArgs does not include a default implementation for 'page' argument; you must provide your own if needed.
fix
Define a 'page' field manually in your args class if you want pagination via page numbers.
affects: >=1.0.0
gotchaCursor serialization format is not documented; default uses base64-encoded JSON, but you must override decodeCursor to handle custom formats.
fix
Override decodeCursor with your own decoding logic, e.g., using Joi to validate.
affects: >=1.0.0
deprecatedThe 'page' argument in ConnectionArgs is undocumented and may be removed.
fix
Do not rely on 'page' argument; use 'first'/'last'/'before'/'after' instead.
affects: >=1.1.0
Errors
Common errors & fixes
Cannot find module 'nestjs-graphql-connection'
Package not installed or typo in import path
fix
Run 'npm install nestjs-graphql-connection' and ensure import is from 'nestjs-graphql-connection' (no subpath).
TypeError: Class extends value undefined is not a constructor or null
createEdgeType or createConnectionType called with a class that is not a GraphQL ObjectType
fix
Ensure the argument to createEdgeType is a class decorated with @ObjectType().
Cannot read properties of undefined (reading 'prototype')
Incorrect usage: calling createEdgeType without 'new' when extending
fix
Use 'extends createEdgeType(Person)' not 'extends new createEdgeType(Person)'.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
@nestjs/commonrequiredRequired to use NestJS decorators and base classes
@nestjs/corerequiredRequired for NestJS module system
@nestjs/graphqlrequiredRequired for GraphQL integration (ObjectType, ArgsType, etc.)
reflect-metadatarequiredRequired by NestJS for decorator metadata
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
nestjs-graphql-connection — npm install nestjs-graphql-connection · libregistry