๐ŸŒ
Jelani Harris
jelaniharris.com โ€บ blog โ€บ building-a-graphql-api-with-nestjs-and-prisma
Building a GraphQL API with NestJS and Prisma | Jelani Harris
June 9, 2024 - So now you know how to create a NestJS API using GraphQL with help from Prisma for accessing the database. If you want to see the source code for this example project you can look at it at https://github.com/jelaniharris/nestjs-graphql-example
Discussions

nestjs - How can I use Prisma types on a nest.js GraphQL query argument - Stack Overflow
There are packages that generate classes from prisma schema, like prisma-nestjs-graphql which i've been using recently. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Anybody using NestJS along Prisma and GraphQL? How is your experience with it? do you recommend it ?
Hey there, I work at Prisma and wanted to chime in with some resources and offer help in case you have any specific questions about how Prisma and NestJS work together (we created this page to give a high-level overview of that, this could be a good starting point). My colleague also recently gave a really comprehensive Letโ€™s build a REST API with NestJS and Prisma workshop (~90min) that covers Prisma and NestJS fundamentals, how to build a REST API and document it using Swagger as well as data validation and error handling. The same colleague is also currently publishing an article series on our blog, here's the first article . Note that other TypeORM is often used as the default ORM in NestJS, you can read a comparison about the two in our docs (where we e.g. explain how Prisma can provide much stronger type-safety guarantees compared to TypeORM). Here's also a nice article from a developer who explains why and how they migrated a large production NestJS app from TypeORM to Prisma. Let me know if you have any questions about Prisma, always happy to help! More on reddit.com
๐ŸŒ r/Nestjs_framework
1
14
August 30, 2022
Library for NestJS GraphQL and Zod
Hey u/incetarik , this library is perfect for what we want to do, which is using zod schema as the sources of truth to scaffold (with customisation) dynamodb models, gql object types and input types, compose various combinations of these with partial/omitted fields etc and export this goodness for the front-end in the monorepo as well. This is an absolute killer pattern imo. I'm having trouble with compiling under ts@4.9.5, however. Simply using any of the exports of this library throws errors on types `Mapper` and `MapKeys` being undefined. node_modules/nestjs-graphql-zod/dist/model-from-zod.d.ts:74:84 - error TS2304: Cannot find name 'Mapper'.74 export interface IModelFromZodOptionsWithMapper = Mapper> extends IModelFromZodOptions {~~~~~~node_modules/nestjs-graphql-zod/dist/model-from-zod.d.ts:74:96 - error TS2304: Cannot find name 'Mapper'.74 export interface IModelFromZodOptionsWithMapper = Mapper> extends IModelFromZodOptions {~~~~~~node_modules/nestjs-graphql-zod/dist/model-from-zod.d.ts:86:49 - error TS2304: Cannot find name 'Mapper'.86 type Options = Mapper> = IModelFromZodOptionsWithMapper & {~~~~~~node_modules/nestjs-graphql-zod/dist/model-from-zod.d.ts:86:61 - error TS2304: Cannot find name 'Mapper'.86 type Options = Mapper> = IModelFromZodOptionsWithMapper & {~~~~~~node_modules/nestjs-graphql-zod/dist/model-from-zod.d.ts:98:13 - error TS2304: Cannot find name 'MapKeys'.98 new (): MapKeys; I see they are defined in `types.d.ts`, but not imported or defined in any of the dist files. Importing anything directly from the src directory still yields the same problem. I'm reasonably new to typescript, would be awesome if you could comment, I've surely walked into similar problems before. My tsconfig: "compilerOptions": {"include": ["src/**/*.ts"],"exclude": ["node_modules/**/*"]"experimentalDecorators": true,"lib": ["ESNext", "DOM", "DOM.Iterable"],"moduleResolution": "node","noUnusedLocals": false,"noUnusedParameters": false,"removeComments": true,"sourceMap": true,"outDir": "dist","module": "commonjs","esModuleInterop": true,"declaration": true,"emitDecoratorMetadata": true,"allowSyntheticDefaultImports": true,"target": "ES2020","incremental": true,"alwaysStrict": true,"strictNullChecks": true,"resolveJsonModule": true,} More on reddit.com
๐ŸŒ r/Nestjs_framework
4
6
May 8, 2022
Nest JS with Prisma and CASL Example
Here: https://cs.github.com/?scopeName=All+repos&scope=&q=%22%40casl%2Fprisma%22+%22%40nestjs%22+path%3Apackage.json I found this two repos: https://github.com/ZenSoftware/zen https://github.com/creatorsgarten/eventkit More on reddit.com
๐ŸŒ r/Nestjs_framework
3
7
August 21, 2022
๐ŸŒ
GitHub
github.com โ€บ unlight โ€บ nestjs-graphql-prisma-realworld-example-app
GitHub - unlight/nestjs-graphql-prisma-realworld-example-app: Example real world application built with NestJS, Prisma and GraphQL ยท GitHub
Example real world application built with NestJS, Prisma and GraphQL - unlight/nestjs-graphql-prisma-realworld-example-app
Starred by 108 users
Forked by 26 users
Languages ย  TypeScript 95.6% | JavaScript 3.0% | Shell 1.2% | Dockerfile 0.2%
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ prisma-nestjs-graphql
prisma-nestjs-graphql - npm
May 30, 2026 - If imported module has internal namespace, this allow to generate named import, imported name will be equal to {namespace}, see example of usage Type: boolean Default: false ... generator nestgraphql { fields_Validator_from = "class-validator" fields_Validator_input = true } model User { id Int @id /// @Validator.MinLength(3) name String } ... import { InputType, Field } from '@nestjs/graphql'; import * as Validator from 'class-validator'; @InputType() export class UserCreateInput { @Field(() => String, { nullable: false }) @Validator.MinLength(3) name!: string; }
      ยป npm install prisma-nestjs-graphql
    
Published ย  May 11, 2025
Version ย  21.2.0
๐ŸŒ
GitHub
github.com โ€บ unlight โ€บ prisma-nestjs-graphql
GitHub - unlight/prisma-nestjs-graphql: Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module ยท GitHub
May 30, 2026 - ... import { GraphQLBigInt } from 'graphql-scalars'; export class BigIntFilter { @Field(() => GraphQLBigInt, { nullable: true }) equals?: bigint | number; } It will affect all inputs and outputs types (including models).
Starred by 572 users
Forked by 86 users
Languages ย  TypeScript
๐ŸŒ
Webscale
section.io โ€บ home โ€บ blog
Webscale Blog: Insights on AI & Commerce | Webscale
June 9, 2025 - Get the latest insights on AI, personalization, infrastructure, and digital commerce from the Webscale team and partners.
๐ŸŒ
Escape Tech
escape.tech โ€บ blog โ€บ tutorial โ€บ guide to handling relational databases with prisma, nestjs and graphql
Guide to relational databases with NestJS, Prisma & GraphQL
October 30, 2024 - A quick overview of the different tools provided by NestJS to do GraphQL APIs ยท Some guidelines and code examples to serve entities from the database, and especially to handle fields pointing to related entities. Our take on solving Prisma N+1 queries in this context.
๐ŸŒ
Amplication
amplication.com โ€บ blog โ€บ build-a-nodejs-graphql-api-with-nestjs-and-prisma
Build a Node.js GraphQL API with NestJS and Prisma - Amplication
Learn how to build a Node.js GraphQL API using NestJS and Prisma and how to generate a GraphQL API for your next application using open-source technology.
Find elsewhere
๐ŸŒ
Tomray
tomray.dev โ€บ nestjs-prisma
Ultimate Guide: How to use Prisma with NestJS - Tom Ray
November 29, 2022 - In the above code, we have defined the GraphQL object type for a Tweet, using the same fields we defined in the Tweet database table with Prisma. Note how I've also leveraged the auto-generated Prisma types too (I had to rename the import to prevent the conflict)! Now let's update the resolver to use this object type and also use our TweetsService: ... import { Query, Resolver } from '@nestjs/graphql'; import { Tweet } from 'src/modules/tweets/tweets.model'; import { TweetsService } from 'src/modules/tweets/tweets.service'; @Resolver() export class ApiResolver { constructor(private readonly tweetsService: TweetsService) {} @Query(() => [Tweet]) async getTweets() { return this.tweetsService.getTweets(); } }
๐ŸŒ
GitHub
github.com โ€บ bensiu123 โ€บ nest-prisma-graphql-example
GitHub - bensiu123/nest-prisma-graphql-example: A simple example of using Nest.js, Prisma, and GraphQL. ยท GitHub
This project is a simple example of using Nest.js, Prisma, and GraphQL. It is to investigate the possibility to use Prisma to replace Mongoose when using MongoDB as database. It is because type-safety of Mongoose is week when using TypeScript.
Author ย  bensiu123
๐ŸŒ
GitHub
github.com โ€บ notiz-dev โ€บ nestjs-prisma-starter
GitHub - notiz-dev/nestjs-prisma-starter: Starter template for NestJS ๐Ÿ˜ป includes GraphQL with Prisma Client, Passport-JWT authentication, Swagger Api and Docker
# building new NestJS docker image ... the following two commands: npx prisma generate # or in watch mode npx prisma generate --watch # or npm run prisma:generate npm run prisma:generate:watch ......
Starred by 2.5K users
Forked by 366 users
Languages ย  TypeScript 96.7% | JavaScript 1.8% | Dockerfile 1.3% | Shell 0.2%
๐ŸŒ
GitHub
github.com โ€บ gabriel-roque โ€บ nestjs-graphql-prisma
GitHub - gabriel-roque/nestjs-graphql-prisma: ๐Ÿ—๏ธ Example project with NestJS, GraphQL and Prisma (Auth, Email and Storage features)
๐Ÿ—๏ธ Example project with NestJS, GraphQL and Prisma (Auth, Email and Storage features) - gabriel-roque/nestjs-graphql-prisma
Author ย  gabriel-roque
๐ŸŒ
YouTube
youtube.com โ€บ watch
Nest JS Graphql with Prisma ORM #07 - YouTube
Nest JS with GraphqlIn this playlist, we are going to cover a lot of things related to nestjs and graphqlCode showing nestjs graphql with Postgres, mongoose ...
Published ย  April 22, 2022
๐ŸŒ
NestJS
docs.nestjs.com โ€บ recipes โ€บ prisma
Prisma | NestJS - A progressive Node.js framework
Note If you want to get a quick overview of how Prisma works, you can follow the Quickstart or read the Introduction in the documentation. There also are ready-to-run examples for REST and GraphQL in the prisma-examples repo.
๐ŸŒ
Medium
medium.com โ€บ @shkim04 โ€บ nestjs-graphql-prisma-postgresql-set-up-6cc76a624bde
NestJS GraphQL/Prisma/PostgreSQL Set Up | by Seunghyun Kim | Medium
August 2, 2023 - It will show all the tables we have defined in Prisma schema file. GraphQL is a query language for APIs. Unlike REST API, we do not have to retrieve data that we do not need. In other words, we can specify fields that we want to get as a response from an API based on our needs. Conveniently, there is the built-in @nestjs/graphql module in NestJS.
๐ŸŒ
GitHub
github.com โ€บ Qu1etboy โ€บ nestjs-prisma-graphql
GitHub - Qu1etboy/nestjs-prisma-graphql: An example of how to used Nest.js with Prisma and GraphQL
// src/prisma/prisma.module.ts import { Global, Module } from '@nestjs/common'; import { PrismaService } from './prisma.service'; @Global() @Module({ providers: [PrismaService], exports: [PrismaService], }) export class PrismaModule {} Don't forget to import PrismaModule to app.module.ts ยท Now for our main part GraphQL, install required dependencies as followed.
Author ย  Qu1etboy
๐ŸŒ
Medium
karthickragavendran.medium.com โ€บ nestjs-prisma-typescript-robust-and-powerful-graphql-apis-in-less-than-a-day-d55cf6e6e987
NestJS + Prisma + Typescript = Robust, and Powerful GraphQL APIs in less than a day. | by Karthick Ragavendran | Medium
August 14, 2023 - Next time you come across a Graphql API tutorial, notice how extensive the filtering and sorting capabilities of that. 90% of the tutorials don't go beyond implementing skip and limit arguments. Thanks for reading. Code: https://github.com/karthickthankyou/nestjs-prisma-simple-graphql-api
Top answer
1 of 1
1

There are packages that generate classes from prisma schema, like prisma-nestjs-graphql which i've been using recently.

This is an example:

// user.resolver.ts -----------------------------------

import { User, UserCreateInput } from 'src/@generated';

@Mutation(() => User, { nullable: true })
async createUser(
 @Args('data') data: UserCreateInput
) {
 return this.userService.createUser(data);
}

// user.service.ts ------------------------------------

async createUser(
 data: UserCreateInput,
): Promise<User> {
 return this.prisma.user.create({ data });
}

Setup

This is my basic setup, there're more configurations, see details

prisma.schema


generator nestgraphql {
  provider                              = "node node_modules/prisma-nestjs-graphql"
  output                                = "../src/@generated"
  fields_Validator_from                 = "class-validator"
  fields_Validator_input                = true
  requireSingleFieldsInWhereUniqueInput = true
  emitSingle                            = true
  emitCompiled                          = true
  purgeOutput                           = true
  noTypeId                              = true
}

that's it! And run npx prisma generate, which generates classes in the defined path /src/@generated/index.ts

Bonus!!!

I also parse requested graphql schema to prisma select so tha only requested fields will be queried from db and also if your query has nested relations, you will not have to define separate resolve fields, otherwise you'll need to define resolve fields for every nested relations

Example:

// user.resolver.ts -----------------------------------

import PrismaSelect from 'src/decorators/prisma-select';
import { User, UserCreateInput } from 'src/@generated';

@Mutation(() => User, { nullable: true })
async createUser(
 @Args('data') data: UserCreateInput,
 @PrismaSelect() select: Prisma.UserSelect, // <----- here is the change
) {
 return this.userService.createUser(data, select);
}

// user.service.ts ------------------------------------

async createUser(
 data: UserCreateInput,
 select: Prisma.UserSelect // <----- here is the change
): Promise<User> {
 return this.prisma.user.create({ data, select });
}

// src/decorators/prisma-select.ts

import { prismaSelect } from '@src/utils/prisma'

const PrismaSelect = createParamDecorator(
  (_data: any, ctx: ExecutionContext) => {
    const gqlCtx = GqlExecutionContext.create(ctx);
    const info = gqlCtx.getInfo();
    
    return prismaSelect(info);
  },
);

export default PrismaSelect;
// @src/utils/prisma.ts

import { GraphQLResolveInfo } from 'graphql';
import graphqlFields from 'graphql-fields';

export const prismaSelect = (
  info: GraphQLResolveInfo,
) => {
  const parsedFields = graphqlFields(info);

  const parse = (fields: any) => {
    let result: any = {};

    for (const key in fields) {
      if (key === '__typename') {
        delete fields[key];
        continue;
      }
      const value = fields[key];

      if (
        typeof value !== 'object' ||
        !Object.keys(value).length
      ) {
          result[key] = true;
      } else {
        result[key] = {
          select: parse(fields[key]),
        };
      }
    }

    return result;
  };

  return parse(parsedFields);
};

Lastly, put this prisma middleware which checks and removes nullable fields to prevent errors:

// src/middlewares/index.ts

import { Prisma } from '@prisma/client';

export function PrismaExcludeNullableFieldsMiddleware<
  T extends Prisma.BatchPayload = Prisma.BatchPayload,
>(): Prisma.Middleware {
  return async (
    params: Prisma.MiddlewareParams,
    next: (params: Prisma.MiddlewareParams) => Promise<T>,
  ): Promise<T> => {
    const args = params.args || {};

    for (const key in args) {
      const nullable = !args[key] ?? !Object.keys(args[key]).length;
      if (nullable) delete args[key];
    }

    if (args?.select && !Object.keys(args.select).length) {
      args.select.id = true;
    }

    return next(params);
  };
}

I have simplified these last codes, if that i broke something, don't mind!, you generally get the point, you can fix, if you can't and you're still interested in this bonus part, i can share the full setup.

Edit

// @src/utils/prisma.ts
import { PrismaSelect } from '@paljs/plugins';

export const prismaSelect = (
  info: GraphQLResolveInfo
) => {
  const prismaSelect = new PrismaSelect(info).value.select;
  return prismaSelect
}

i found out this @paljs/plugins library that defines prisma select query fields from graphql info, before i was doing it myself and in some scenarios i had errors, this library is doing better that my custom approach

๐ŸŒ
Amplication
amplication.com โ€บ blog โ€บ how-to-build-a-nodejs-graphql-api-with-nestjs-and-prisma
How to Build a Node.js GraphQL API With NestJS and Prisma
NestJS is a powerful framework specifically designed for building Node.js applications, while Prisma is an ORM tool that provides a type-safe API for querying databases in Node.js. This article aims to provide insights on building a Node.js GraphQL API using NestJS and Prisma while addressing some of the most frequently asked questions about these technologies.