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

Answer from A.Anvarbekov on Stack Overflow
🌐
npm
npmjs.com › package › prisma-nestjs-graphql
prisma-nestjs-graphql - npm
May 30, 2026 - Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module. Latest version: 21.2.0, last published: a year ago. Start using prisma-nestjs-graphql in your project by running `npm i prisma-nestjs-graphql`. There are 10 other projects in the npm registry using prisma-nestjs-graphql.
      » npm install prisma-nestjs-graphql
    
Published   May 11, 2025
Version   21.2.0
Discussions

nestjs - How can I use Prisma types on a nest.js GraphQL query argument - Stack Overflow
I'm working on a simple GraphQL query that allows me to fetch a list of users. I want to be able to sort them through my request. I'm using Prisma as an ORM. As per the documentation, my service si... 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
Integrate Prisma 2 into Nestjs applications

Loving the design of your blog!

More on reddit.com
🌐 r/Nestjs_framework
12
9
March 2, 2020
Integrating Sentry for GraphQL and Postgres Query Performance Monitoring in a React/Node.js Stack
I don't think Sentry has a direct integration with Postgres. What you could do though is wrap your backend calls to the DB in sentry and measure query performance from the APIs perspective. If you want E2E performance capturing, integrate sentry on your UI and correlate the GQL calls to the API calls. We use Apollo on our UI and use this plugin to use sentry with GQL: https://github.com/DiederikvandenB/apollo-link-sentry More on reddit.com
🌐 r/reactjs
9
2
November 21, 2023
🌐
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
This codebase was created to demonstrate a fully fledged fullstack application built with NestJS, Prisma and GraphQL including CRUD operations, authentication, routing, pagination, and more.
Starred by 108 users
Forked by 26 users
Languages   TypeScript 95.6% | JavaScript 3.0% | Shell 1.2% | Dockerfile 0.2%
🌐
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 - In our case we’ll be using the @nestjs/graphql package to provide support for our graph in NestJs · Prisma.IO is an ORM (Object Relational Mapping) tool that will help you work with databases more easily by providing an easy-to-use way to access your database by using simple commands instead of long SQL queries.
🌐
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. In this recipe, you'll learn how to get started with NestJS and Prisma ...
🌐
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 - Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module - unlight/prisma-nestjs-graphql
Starred by 572 users
Forked by 86 users
Languages   TypeScript
🌐
NestJS
docs.nestjs.com › graphql › quick-start
GraphQL + TypeScript | NestJS - A progressive Node.js ...
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP ...
Find elsewhere
🌐
Prisma
prisma.io › nestjs
Enterprise-ready database for NestJS apps | Prisma
Prisma's database tools are the perfect fit for building scalable and type-safe NestJS applications. Prisma integrates smoothly with the modular architecture of NestJS, no matter if you're building REST or GraphQL APIs.
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

🌐
Reddit
reddit.com › r/nestjs_framework › anybody using nestjs along prisma and graphql? how is your experience with it? do you recommend it ?
r/Nestjs_framework on Reddit: Anybody using NestJS along Prisma and GraphQL? How is your experience with it? do you recommend it ?
August 30, 2022 - 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! Looking for resources to learn Nest and GraphQl ·
🌐
Teeto
teeto.hashnode.dev › nestjs-prisma-graphql
NestJs, GraphQL, Prisma, Teeto, Javascript
December 29, 2022 - We can test out our queries and mutation using GraphQL Playground. Run npm start to start the Nest server. This article shows how to get started with Nest, Prisma and GraphL by building some endpoints for a makeshift blog.
🌐
Prisma
prisma.io › home › generators › generators › generators › generators
Generators (Reference) | Prisma Documentation
typegraphql-prisma-nestjs: Fork of typegraphql-prisma, which also generates CRUD resolvers for Prisma models but for NestJS · prisma-typegraphql-types-gen: Generates TypeGraphQL class types and enums from your prisma type definitions, the generated output can be edited without being overwritten by the next gen and has the ability to correct you when you mess up the types with your edits. nexus-prisma: Allows for projecting Prisma models to GraphQL via GraphQL Nexus
🌐
LinkedIn
de.linkedin.com › in › gadishimwe
Gad Ishimwe - IntegrityNext | LinkedIn
Full-stack developer with a strong front-end focus and a designer’s eye, bringing over 5… · Experience: IntegrityNext · Education: University of Rwanda · Location: Munich · 500+ connections on LinkedIn. View Gad Ishimwe’s profile on LinkedIn, a professional community of 1 billion members.
🌐
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
Full Stack like a Pro: backend with NestJS, Prisma, Graphql, NX Monorepo pt2 - YouTube
In this tutorial series you will learn how to build a full-stack web application from scratch using NextJS 13, Prisma, NestJS, GraphQL, and Nx Monorepo. This...
Published   February 7, 2023
🌐
YouTube
youtube.com › watch
Full Stack TikTok Clone: NestJS, GraphQL, Prisma, Postgres, React, Apollo Client, Zustand & Tailwind - YouTube
#graphql #reactjs #graphql *Full-Stack TikTok Clone using NestJS, GraphQL, ReactJS, Apollo Client, Zustand & TailwindCSS*Hey, coders,Here I am again with an...
Published   August 23, 2023
Views   25K
🌐
YouTube
youtube.com › watch
NestJS GraphQL Prisma - Creando API con las preguntas by Ruslan - YouTube
Ruslan Gonzalez hará la segunda parte del taller paso a paso de lo que corresponde al taller Full stack desde la extracción de datos que hicimos en la primer...
Published   May 2, 2021
Views   2K
🌐
JavaScript in Plain English
javascript.plainenglish.io › nx-nest-prisma-graphql-single-data-model-definition-e601eaa372c6
Let’s Create A Nest, Nx, GraphQL, Prisma Single Data Model Definition | by Kristan 'Krispy' Uccello | JavaScript in Plain English
December 15, 2020 - Now comes the meat of our example — setting up automatic generation of a rich GraphQL api from the Prisma schema and client. For this example I am using NestJS (though you could use another framework or simply roll your own approach — milage may vary). Remember that app we created when ...