npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

prisma-custom-relay-pagination

v3.0.0

Published

This package merges cursor, offset and relay pagination

Readme

Prisma Relay Pagination

Inspired by Prisma Korea's prisma-offset-pagination, Prisma Relay Pagination enhances pagination using Prisma cursor option.

If you want to know how Prisma supports pagination, see Prisma documentation

Installation

NPM

npm install prisma-custom-relay-pagination

Yarn

yarn add prisma-custom-relay-pagination

How to use

Add to tsconfig.json a path named @libs/prisma-custom-relay-pagination where your prisma output is generated

"@libs/prisma-custom-relay-pagination/*": [
  //Directory where your generated prisma is
  //Example: "../src/generated/prisma/*"
]

Add PrismaRelay where you need

import { PrismaRelay } from 'prisma-custom-relay-pagination';

...
const result = new PrismaRelay(PrismaClient, {
    model: 'User',
    buttons: 5,
    where:{ id: 1 }
    omit: { id: true },
    orderBy: { id: 'asc' },
    select: { id: true },
    include: { createdBy: true },
    pagination: { items: 10, cursor: 'ABCD...' }
});

Parameters

prisma: Prisma client object

args:

  • model Model name (Typescript intellisense enabled from your available Prisma's models)

  • buttons (optional) Number of available pagination pages (Default value: 5 )

  • where (optional) Same values as Prisma.${Model}WhereInput

  • omit (optional) Same values as Prisma.{Model}Omit

  • orderBy (optional) Same values as Prisma.{Model}OrderByWithRelationInput

  • select (optional) Same values as Prisma.{Model}Select

  • include (optional) Same values as Prisma.{Model}Include

  • pagination (optional) If pagination is not added, all results will be returned

    • cursor (optional) If cursor is not added, first page will be returned
    • items Number of results returned

Notes

Intellisense in fields: where, omit, orderBy, select and include are available when model parameter is added.

Return data example

{
    pageEdges: [ 
        {  cursor: 'c2FsdHl256x0MQ==', node: { id: 1 } },
        {  cursor: 'c2FsdH4gw2x0MQ==', node: { id: 2 } },
        {  cursor: 'c2FsdHldwfx0MQ==', node: { id: 3 } } 
    ],
    pageCursors: {
        previous: null,
        next: { isCurrent: false, page: 2, cursor: 'c2FsdHldwfx0MQ==' },
        first: null,
        last: { isCurrent: false, page: 15, cursor: 'c2FsdHlz45x0MjExNTY=' },
        around: [
            { isCurrent: true, page: 1, cursor: 'c2FsdHl256x0MQ==' },
            { isCurrent: false, page: 2, cursor: 'c2FsdHldwfx0MQ==' },
            { isCurrent: false, page: 3, cursor: 'c2Fs75lzYWx0Mw==' }
        ]
    },
    totalCount: 45
}

NestJS

There are some utilities for NestJS that help you to reduce boilerplate when you are using Graphql:

ResolverSelect

Using Pal.js, this decorator converts Query fields from Graphql to Prisma select fields. You can check Pal.js documentation to see how it works.

How to use

import { ResolverSelect } from 'prisma-custom-relay-pagination';

@Resolver(() => User)
export class UserResolver {
    @Query(() => User)
    getUser(@ResolverSelect() select: Prisma.UserSelect) {
        ///Your code
    }
}

Parameters

isPagination (optional) Set parameter to true if you are using PrismaRelay (Default value: false)

omit (optional) Omit fields not declared in Prisma's schema or fields with their resolver defined in Graphql.

model (optional) GraphQL model name if it does not match with the Prisma schema model name


PrismaRelayPagination

This decorator converts Graphql model to PrismaRelay pagination model

How to use

import { PrismaRelayPagination } from 'prisma-custom-relay-pagination';

@PrismaRelayPagination({ type: User })
export class UserPagination {}

Graphql result example

getUserPagination(...parameters) {
    totalCount
    pageCursors {
        first {
            cursor
            page
        }
        previous {
            cursor
            page
        }
        around {
            cursor
            page
        }
        next {
            cursor
            page
        }
        last {
            cursor
            page
        }
    }
    pageEdges {
        cursor
        node {
            ///User fields
        }
    }
}

Parameters

type The Graphql model you want to convert to a pagination


PrismaRelayPaginationArg / PrismaRelayPaginationOptionalArg

These classes help you add pagination parameters when you are using pagination queries. You can extend them with other fields like where, orderBy, etc.

If you want to force pagination, then use PrismaRelayPaginationArg, otherwise, use PrismaRelayPaginationOptionalArg

How to use

import { PrismaRelayPaginationArg } from 'prisma-custom-relay-pagination';

@ArgsType()
export class UserPaginationArgs extends PrismaRelayPaginationArg {}