🧬 A type builder for pagination with prisma and type-graphql.

Overview

Issues Stars License Codecov Downloads Bundlephobia Packagephobia


  

🧬 Prisma TypeGraphql Pagination


Prisma TypeGraphql Pagination builds prisma pagination types for type-graphql.


import { ... } from 'type-graphql'
import { createPaginator } from 'prisma-typegraphql-pagination';

const FriendsPagination = createPaginator(User);

@Resolver(() => User)
export class UserResolver {

 // ...
 async friends(
    @Ctx() { prisma }: GqlContext,
    @Args(() => FriendsPagination) pagination: Paginator<User>
  ): Promise<User[]> {
    return prisma.user.findMany({ where: { id }, ...pagination });
    // Or for a field resolver
    return prisma.user.findUnique({ where: { id } }).friends(pagination);
  }
}

Table of Contents


Guide

This is a pretty straightforward package, it just builds, at runtime, all graphql types required to represent the same Prisma.ENTITYFindManyArgs, like Prisma.UserFindManyArgs, which is used prisma.user.findMany(HERE).


Simple usage

You can create many pagination types for many entities, and this is how we do it:

import { createPaginator, type Paginator } from 'prisma-typegraphql-pagination';

// This UserPagination class can be used for any pagination for a User[] result.
// It is the type that type-graphql will understand
const UserPagination = createPaginator(User);

function userPagination(@Args(() => UserPagination) pag: Paginator<User>) {
  // ...
}

Configuration

This package is entirely built in mind of using TSDocs, and as the possible configuration is very simple, you can see it in the following file. src/options.ts.


Class Validator

This package provides an optional class validator integration, it is activated if the package class-validator is installed.

It automatically generates @Validation decorators for the pagination types, so you can expect a more robust and secure pagination.

Got any exceptions? You can always report them to our Issues page.


Getting a generated class at runtime.

If, for some reason, you need one of the generated classes, like the UserFieldsEnum class generated by your createPagination(User) call, you can get it in the same way as any other class from type-graphql.

After getting the array of all classes, you can do a for-of loop and get the one you need by checking its name.

const metadata = getMetadataStorage(); // from type-graphql

metadata.objectTypes; // or
metadata.inputTypes; // or
metadata.enums;

// Example:
for (const type of metadata.objectTypes) {
  if (type.name === 'UserEntityPaginator') {
    // ...
  }
}

License

Licensed under the MIT. See LICENSE for more informations.


Contact

See my contact information on my github profile or open a new issue.


You might also like...

Prisma 2+ generator to emit Zod schemas from your Prisma schema

Prisma 2+ generator to emit Zod schemas from your Prisma schema

Prisma Zod Generator Automatically generate Zod schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Dec 27, 2022

My-portfolio - Built with Namecheap, Digital Ocean, Nginx, PM2, SSL, NextJs, Tailwind 3, Graphql, NexusJS, Prisma, Postgres, Passion and Love

Current Implementation technologies Nextjs with Typescript. Static pages/ Server side rendering. Easy peasy state management (Might not need it with i

Jan 10, 2022

A basic example of a GraphQL API built with NestJS, Prisma and TypeScript

A progressive Node.js framework for building efficient and scalable server-side applications. Description Nest framework TypeScript starter repository

Dec 18, 2022

Holy Qur'an Telegram Bot with pagination and audio, in Indonesian language.

Holy Qur'an Telegram Bot with pagination and audio, in Indonesian language.

quran-telegram-bot Contributions are Welcome! Demo @fio_quran_bot Run Tested on Node.js v14.x.x with NPM v6.x.x, Windows 10 and Ubuntu 18.04.6 LTS. Cr

Oct 21, 2022

A jQuery plugin for making html tables searchable and sortable with pagination

jQuery.fancyTable A jQuery plugin for making html tables searchable and sortable with pagination. Live demo See a live demo on CodePen Installation Us

Dec 19, 2022

URL Shortener API in NodeJS supporting pagination, sort params and lot more

URL Shortener API in NodeJS supporting pagination, sort params and lot more

node-url-shortener Built with ❤️ in NodeJS A simple URL Shortner REST API that uses shortid npm package to generate short endpoints for your long URL.

Sep 22, 2022

Simple and easy-to-use pagination library for Mongoose (Node.js)

Simple and easy-to-use pagination library for Mongoose (Node.js)

node-paginator Simple and easy-to-use pagination library for Mongoose (Node.js) 📚 Why node-paginator? Every web developer should work on pagination a

Sep 21, 2022

A simple javascript library for pagination, compatible with Bootstrap.

A simple javascript library for pagination, compatible with Bootstrap.

Easy Pagination JS A simple library for pagination, compatible with Bootstrap. Check my website here. Demo Check this Demo here. Example Import the fi

Aug 5, 2022

A handler to create embedded pages with buttons for pagination.

➝ Whats that • A handler to create embedded pages with buttons for pagination. ➝ Requirements • ["Handler"] pages.js • [Example command] embed.js ➝ Us

Oct 30, 2022
Releases(v1.0.1)
Owner
Arthur Fiorette
developing for web 🌐 🪄
Arthur Fiorette
A NestJS module that allows you use Prisma, set up multiple Prisma services, and use multi-tenancy in each Prisma service.

NestJS Prisma Module Installation To use this package, first install it: npm i @sabinthedev/nestjs-prisma Basic Usage In order to use this package, yo

Sabin Adams 39 Dec 2, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022
NextJS with GraphQL using type-graphl and graphql-codegen adoptable dogs example code

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Jack Herrington 2 Mar 31, 2022
This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io)

Alternative Prisma Data Proxy This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io). In order to deploy your project to

AijiUejima 60 Dec 28, 2022
Prisma +2 generator to emit Yup schemas from your Prisma schema

Prisma Yup Generator Automatically generate Yup schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 31 Dec 24, 2022
Prisma 2+ generator to emit Joi schemas from your Prisma schema

Prisma Joi Generator Automatically generate Joi schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 26 Dec 24, 2022
Prisma +2 generator to emit a tRPC shield from your Prisma schema

Prisma tRPC Shield Generator Automatically generate a tRPC Shield from your Prisma Schema. Updates every time npx prisma generate runs. Table of Conte

Omar Dulaimi 27 Dec 24, 2022